在React Native Navigation V2中添加选项卡导航

时间:2018-07-19 10:51:00

标签: javascript reactjs react-native navigation react-native-navigation

我正在尝试使导航在我的React Native App中正常工作。我已经安装了V2。以下设置未显示任何标签。

Navigation.events().registerAppLaunchedListener(()=>{
Navigation.setRoot({
root: {
  topTabs: {
    children:[{
      stack: {
        children: [
          {
            component: {
              name: 'news.MainScreen',
              text: 'tab1',
              passProps: {
                text: 'This is tab 1'
              },
              options: {
                topTab: {
                  text: "tab 1",
                  testID: 'NO_IDEA'
                }
              }

            },
          },
          {
            component: {
              name: 'news.SplashScreen',
              text: 'tab2',
              passProps: {
                text: 'This is tab 6'
              }
            },
            options: {
              topTab: {
                text: "tab 21",
                testID: 'NO_IDEA_1'
              }
            }
          },
        ]
      }
    }],
   }
 }
})

});

当我编译我的App时,结果如下:

result of the code above

欢迎提出所有建议。

2 个答案:

答案 0 :(得分:1)

您似乎只有一个孩子。尝试仅使用第一个标签(无堆叠)

Navigation.setRoot({
      root: {
                topTabs: {
                children: [
                  {
                    component: {
                      name: "screens.tab1",
                      options: {
                        topTab: {
                          title: "Tab 1"
                        }
                      }
                    }
                  },
                  {
                    component: {
                      name: "screens.tab2",
                      options: {
                        topTab: {
                          title: "Tab 2"
                        }
                      }
                    }
                  },
                  {
                    component: {
                      name: "screens.tab3",
                      options: {
                        topTab: {
                          title: "Tab 3"
                        }
                      }
                    }
                  }
                ]
              }
      }
    });

答案 1 :(得分:0)

此问题在这里报告:https://github.com/wix/react-native-navigation/issues/4485

可以从文档中进行以下操作:

Navigation.setRoot({
 root: {
  topTabs: {
   children: [{
    stack: {
      children: [{
        component: {
          name: 'example.FirstTabScreen',
          passProps: {
            text: 'This is tab 1'
          }
        }
      }],
      options: {
        topTab: {
          text: 'Tab 1',
          icon: require('../images/one.png'),
          testID: 'FIRST_TAB_BAR_BUTTON'
        }
      }
    }
  },
  {
    component: {
      name: 'navigation.playground.TextScreen',
      passProps: {
        text: 'This is tab 2'
      },
      options: {
        topTab: {
          text: 'Tab 2',
          icon: require('../images/two.png'),
          testID: 'SECOND_TAB_BAR_BUTTON'
        }
      }
    }
  }]
}
}
});

有关更多信息,请参见文档:https://wix.github.io/react-native-navigation/#/docs/top-level-api