【问题标题】:React Navigation Navigate from Firebase Push Notification来自 Firebase 推送通知的反应导航导航
【发布时间】:2019-12-19 05:43:16
【问题描述】:

我不知道如何从 firebase fcm 的推送通知中导航。我遇到了导航未定义的问题,所以我按照本指南进行操作,但它仍然没有改变屏幕。我是否缺少一些基本步骤。我试图导航到其他几个没有参数且没有导航的屏幕,但我没有收到任何错误:

https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html

这是我的导航服务:

this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
  const { data } = notificationOpen.notification;

    NavigationService.navigate("Chat", {
        chatName: `${data.channelName}`,
        chatId: `${data.channelId}`
      });

});

这是我的主要应用文件:

import SplashScreen from 'react-native-splash-screen';

const TopLevelNavigator = createStackNavigator({
  ChatApp
},
{
  headerMode: 'none',
  navigationOptions: {
      headerVisible: false,
  }
});

const AppContainer = createAppContainer(TopLevelNavigator);

class App extends Component {

  async componentDidMount() {
    SplashScreen.hide();
  }

  render() {
    return (
      <Provider store={store}>
        <AppContainer ref={navigatorRef => {
          NavigationService.setTopLevelNavigator(navigatorRef);
        }} />
      </Provider>)
  }
}

export default App;

【问题讨论】:

  • 你确定 onNotificationOpened 被触发了吗?
  • 是的。每次我点击推送通知时都会触发它。我也可以使用 alert 来查看里面的变量
  • 我没有看到您的代码有问题。您可以尝试在 NavigationService 中进行调试以查看发生了什么。
  • 不幸的是,自从升级到 >.60 反应本机以来我一直无法使用调试器,因为 firebase 不再支持我正在使用的库(用于身份验证并且我使用时出现网络错误调试器)并且不想弄乱身份验证。我已经按预期放置了一堆警报和那些火灾,所以我不确定发生了什么。我需要编辑堆栈导航器吗?
  • 你能显示你所有的导航器吗?

标签: react-native push-notification react-navigation react-native-push-notification


【解决方案1】:

问题是我需要将另一个堆栈放在同一个导航器中。一旦我添加它就开始工作了

const TopLevelNavigator = createStackNavigator({
  ChatApp: {
    screen: ChatApp,
  },
  Chat: {
    screen: ChatScreen,
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多