Skip to content

Commit

Permalink
Pop to root when tapping on active bottom tab on Android (#7239)
Browse files Browse the repository at this point in the history
* Pop to root when tapping on active bottom tab

* Add missing imports

* Add stack type checking before popping to root
  • Loading branch information
svbutko authored Sep 2, 2021
1 parent 74c09f4 commit bb2b09e
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import com.reactnativenavigation.options.BottomTabOptions;
import com.reactnativenavigation.options.Options;
import com.reactnativenavigation.react.CommandListener;
import com.reactnativenavigation.react.CommandListenerAdapter;
import com.reactnativenavigation.react.events.EventEmitter;
import com.reactnativenavigation.utils.ImageLoader;
import com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.BottomTabsAttacher;
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
import com.reactnativenavigation.viewcontrollers.parent.ParentController;
import com.reactnativenavigation.viewcontrollers.stack.StackController;
import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController;
import com.reactnativenavigation.views.bottomtabs.BottomTabs;
Expand Down Expand Up @@ -169,15 +171,22 @@ public ViewController<?> getCurrentChild() {

@Override
public boolean onTabSelected(int index, boolean wasSelected) {
BottomTabOptions options = tabs.get(index).resolveCurrentOptions().bottomTabOptions;
ViewController<?> stack = tabs.get(index);
BottomTabOptions options = stack.resolveCurrentOptions().bottomTabOptions;

eventEmitter.emitBottomTabPressed(index);

if (options.selectTabOnPress.get(true)) {
eventEmitter.emitBottomTabSelected(bottomTabs.getCurrentItem(), index);
if (wasSelected) return false;
selectTab(index);
if (!wasSelected) {
selectTab(index);
}
}

if (wasSelected && stack instanceof StackController) {
((StackController) stack).popToRoot(Options.EMPTY, new CommandListenerAdapter());
}

return false;
}

Expand Down

0 comments on commit bb2b09e

Please sign in to comment.