反応ネイティブの新しいReact-navigationを使用しています。ヘッダーのボタンから別の画面に移動します
StackNavigator:
- TabNavigatorコンテナ// HomeNavigation
- TabNavigatorコンテナ// NotificationNavigation
全コード:
const MainNavigation = StackNavigator({
Home: {
screen: HomeNavigation,
},
Notification: {
screen: NotificationNavigation,
}
});
const HomeNavigation = TabNavigator({
AllPost: {
screen: All,
},
ArticlePost: {
screen: Article,
},
BusinessPost: {
screen: Job,
},
});
HomeNavigation.navigationOptions = {
title: 'Home',
header: {
right: <SearchNotification/>
},
};
class SearchNotification extends React.Component {
goToNotification =() => {
this.props.navigate('Notification');
};
render() {
return (
<View style={styles.container}>
<TouchableOpacity>
<Icon name="md-search" style={styles.Icon}/>
</TouchableOpacity>
<TouchableOpacity style={styles.notificationWrapper} onPress={this.goToNotification}>
<Icon name="md-notifications" style={styles.Icon}/>
<Text style={styles.number}>3</Text>
</TouchableOpacity>
</View>
)
}
}
const NotificationNavigation = TabNavigator({
Comment: {
screen: NotificationComment,
},
Follow: {
screen: NotificationFollow,
}
});
HomeNavigationが持つヘッダを以下のように私は、ナビゲーションを持っています、ヘッダーはSearchNotificationの右コンポーネントを持ちます。 SearchNotificationには、私がNotificatoinNavigationに行きたいと思うアイコンがあります。
ただし、このようにHomeNavigationのヘッダーを変更すると、ヘッダーにSearchNotificationが表示されません。
HomeNavigation.navigationOptions = {
title: 'Home',
header: {
tintColor: 'white',
style: {
backgroundColor: '#2ec76e',
},
right: ({navigate}) => <SearchNotification navigate={navigate}/>
},
};
ヘッダーのボタンから別の画面に移動するにはどうすればよいですか?