Navigate to different screen from a button in a header

后端 未结 2 1854
故里飘歌
故里飘歌 2021-01-17 07:36

I am using the new React-navigation from react-native. I have the navigation as follows:

StackNavigator:

  1. TabNavigator // HomeNavigation
  2. TabNav
2条回答
  •  甜味超标
    2021-01-17 08:34

    So the problem was (I think), inside the navigationOptions instead of using navigations I had to use navigate, and pass it as a props to the child (i.e. the SearchNotification).

    So the final code looks like this:

    HomeNavigation.navigationOptions = {
        title: 'Home',
        header: ({navigate}) => ({
            right: (
                
            ),
        }),
    };
    

    And within the SearchNotification component:

    export default class SearchNotification extends React.Component {
        goToNotification = () => {
            this.props.navigate('Notification');
        };
    
        render() {
            return (
                
                    
                        
                    
                     this.props.navigate('Notification')}>
                        
                        3
                    
                
            )
        }
    }
    

提交回复
热议问题