0

The structure of my React Navigation is

DashboardScreen => 3 Bottom Tabs (1 out of 3, again have) => 2 Bottom Tabs

The DashboardScreen have three BottomTabs

  1. Main

  2. Profile

  3. Products, the Products have again two BottomTabs

    a. AllProducts

    b. SoldProducts

What I want to do is, when a product is sold, the product owner will receive a notification, and onNotificationOpened from DashboardScreen.js I want to navigate to SoldProducts. OneSignal onNotificationOpened is registered in DashboardScreen.js. (As far as I know, that's the screen where I should implement my OneSignal's working, I have three more cases here.)

DashboardScreen.js

useEffect(() => {
    if (isLoading) {
      loadUserDetail();
    }
    OneSignal.init(ONE_SIGNAL_APP_ID, {
      kOSSettingsKeyAutoPrompt: false,
      kOSSettingsKeyInAppLaunchURL: false,
      kOSSettingsKeyInFocusDisplayOption: 2,
    });
    OneSignal.inFocusDisplaying(2);
    OneSignal.addEventListener('received', onReceived);
    OneSignal.addEventListener('opened', onOpened);
    OneSignal.addEventListener('ids', onIds);
}, [isLoading, loadUserDetail, navigation, onOpened]);


const onOpened = useCallback((openResult) => {
    const additionalData = openResult.notification.payload.additionalData;
    if (additionalData.type === 'sold') {
        // From here I want to navigate
        console.log('DashboardScreen, Move to Product Tab, and open SOLD PRODUCT TAB, instead of All Products Tab');
    }
}, []);

return (
    <Tab.Navigator
      initialRouteName="Main"
      lazy={true}
      tabBar={(props) => (
        <CustomTabBar />
      )}>
      <Tab.Screen name="Profile" component={Profile} />
      <Tab.Screen name="Main" component={Main} />
      <Tab.Screen name="Products" component={Products} />
    </Tab.Navigator>
);

Solutions I have tried so far is

navigation.dispatch(
  NavigationActions.navigate({
    routeName: 'DashboardScreen',
    action: NavigationActions.navigate({
      routeName: 'Products',
    }),
  }),
);

But that's even not opening the Products on DashboardScreen.

Also found

TabActions.jumpTo('Tab')

but TabActions only working in TabComponenet, means inside Main, or Profile to switch between Tabs

Any help will be highly appreciated.

0 Answers0