【发布时间】:2019-05-08 04:06:39
【问题描述】:
我已经使用 React Navigator 3.0 设置了 Navigation 为了成功地从父组件传递道具,我这样调用我的 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 }}
/>
)
}
【问题讨论】:
标签: react-native react-navigation