Как перемещаться по слушателю React-Native? - PullRequest
1 голос
/ 29 мая 2020

Когда я получаю уведомление pu sh, приложение должно перейти к определенному экрану c в реакции-навигации 5. Как я могу это сделать? В настоящее время прослушиватель уведомлений pu sh настроен на маршрутизацию следующим образом:

const Routing = () => {
  useEffect(() => {
    OneSignal.init(...);
    OneSignal.inFocusDisplaying(2);
    OneSignal.promptForPushNotificationsWithUserResponse();
    OneSignal.addEventListener('received', onReceived);
    OneSignal.addEventListener('opened', onOpened);
  }, []);

  const onReceived = (notification) => {
    console.log("Notification received: ", notification);
  };

  const onOpened = (openResult) => {
    if (_.get(openResult, 'notification.payload.additionalData.profile_id', null)) {
      // Here, the app should navigate to the screen of MainStack.
    }
  };
  return (
    <RootStack.Navigator>
      <RootStack.Screen name="Auth" component={AuthStack} />
      <RootStack.Screen name="Main" component={MainStack} />
    </RootStack.Navigator>
  );
};
...