Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pop to root when tapping on active bottom tab on Android #7239

Merged
merged 3 commits into from
Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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