首页 文章

React Navigator传递NavigationOptions prop

提问于
浏览
0

我已经使用React Navigator 3.0设置了导航为了成功地从父组件传递道具,我正在调用我的TabNavigator,如下所示:

return (
        <View style={styles.container}>
          <TabNavigator screenProps={{deleteToken: this.deleteJWT }} />
        </View>
      );

我的TabNavigator组件然后呈现几个屏幕 . 我以前的方法是使用文档中的默认代码(如下所示为HomeScreen),但是现在我传递道具,我需要使用下面显示的方法用于ProfileScreen(箭头功能) .

我的问题是我不知道在使用箭头功能时将ProfileScreen的navigationOptions放在哪里 .

const TabNavigator = createBottomTabNavigator(
  {
  Profile: (props) => {
    return <ProfileScreen {...props.screenProps} />;
  },
  Home: { screen: HomeScreen,
          navigationOptions: {
            //tabBarLabel: 'Inicio',
            tabBarIcon: ({ tintColor, focused }) => (
          <Ionicons
            name={focused ? 'ios-home' : 'ios-home'}
            size={26}
            style={{ color: tintColor }}
          />
        ),
          //  tabBarIcon: () => {
          //                <Image
          //                style={{ width: 50, height: 50 }}
          //                source={{ uri: 'https://facebook.github.io/react/img/logo_og.png' }}
          //                />
        //},
        }
      },

更新:显而易见的地方是将NavigationOptions对象放在返回的屏幕中,但它被忽略:

export default class ProfileScreen extends React.Component {
  static navigationOptions = {

        tabBarLabel: 'Perfil',
        tabBarIcon: ({ tintColor, focused }) => (
      <Ionicons
        name={focused ? 'ios-person' : 'ios-person'} //TODO change to focused icon
        size={26}
        style={{ color: tintColor }}
      />
    )
  }

1 回答

  • 0

    这是正确的语法:

    const TabNavigator = createBottomTabNavigator(
      {
      Profile: {
        screen: props => <ProfileScreen {...props.screenProps} />,
        navigationOptions: {
            //tabBarLabel: 'Perfil',
            tabBarIcon: ({ tintColor, focused }) => (
          <Ionicons
            name={focused ? 'ios-person' : 'ios-person'} //TODO change to focused icon
            size={26}
            style={{ color: tintColor }}
          />
        ),
    

相关问题