Skip to content

Bottom Navigation - Not able to prevent User action or when user press any tab then registerBottomTabPressedListener this is envoked after tab moved #8036

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

Open
1 task done
manojmehra-spraxa opened this issue Jun 2, 2025 · 0 comments

Comments

@manojmehra-spraxa
Copy link

What happened?

Problem:

When using Bottom Tabs in React Native Navigation, the registerBottomTabPressedListener is triggered after the tab is already selected.
This means:
The screen transition already occurs before we can react.
We cannot prevent the tab from opening based on logic (e.g., user not allowed, show popup, etc.).

What We Need:

Intercept the tab press before navigation happens.
Prevent navigation to a specific tab under certain conditions (e.g., user not logged in).
Instead of navigating, we want to show a popup or alert explaining why the tab is blocked.

What was the expected behaviour?

When a user taps on a bottom tab, you want:

To intercept the tab press before navigation happens.
Prevent the navigation to certain tabs under specific conditions (e.g., user not logged in, permission not granted).
Instead of navigating, show a custom popup/message/alert explaining why access to that tab is restricted.

Was it tested on latest react-native-navigation?

  • I have tested this issue on the latest react-native-navigation release and it still reproduces.

Help us reproduce this issue!


async setupNavigationForLoggedIn() {
        const icons = await this.getTabIcons();
        Navigation.setRoot({
            root: {
                bottomTabs: {
                    id: 'BottomTabsId',
                    options: {
                        bottomTabs: {
                            backgroundColor: 'whitesmoke',
                            fontSize: 12,
                            selectedFontSize: 14,
                            titleDisplayMode: 'alwaysShow',
                            animateTabSelection: true,
                            elevation: 30,
                            tabsAttachMode: "afterInitialTab"
                        },
                    },
                    children: utils.getNavigationStack().map(tabConfig => {
                        const [inactiveIdx, activeIdx] = tabConfig.iconIndexes;
                        return {
                            stack: {
                                id: tabConfig.id,
                                children: [
                                    {
                                        component: {
                                            name: tabConfig.component,
                                            passProps: tabConfig.passProps || {},
                                            options: {
                                                bottomTab: {
                                                    ...this.commonTabOptions(tabConfig.label, icons[inactiveIdx], icons[activeIdx]),
                                                    titleDisplayMode: 'alwaysShow',
                                                },
                                            },
                                        },
                                    },
                                ],
                            },
                        };
                    }),
                },
            },
        });
        // This is not required if we don't need to show anything conditionality 
        this.registerBottomTabPressedListener();
    }
Navigation.events().registerBottomTabPressedListener(({ tabIndex }) => {
            debugger;
            Navigation.mergeOptions('BottomTabsId', {
                bottomTabs: { currentTabIndex: tabIndex },
            });
        });

In what environment did this happen?

React Native Navigation version: "8.0.0",
React Native version: "0.76.0"
Has Fabric (React Native's new rendering system) enabled: (yes/no) yes
Node version: 20.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant