Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back button not working in react native navigation

I am using react native navigation and I need to update back button design which I have achieved by following code

static navigationOptions = {
    title: '',
    headerStyle: {
      backgroundColor: '#544849',
    },
    tintColor: 'transparent',
    headerLeft: <TouchableOpacity onPress={() => this.props.navigation.goBack()}><Image source={require('../../img/close.png')} style={{marginTop: 10, marginLeft:10}} /></TouchableOpacity>
  };

But this way I get error undefined is not an object(evaluating r.props.navigation)

back button does nothing without onPress.

like image 490
Adnan Ali Avatar asked Sep 07 '17 12:09

Adnan Ali


1 Answers

Acourding to docs for NavigationOptions you can change your code like below.

static navigationOptions = ({ navigation, screenProps }) => ({
        title: '',
        headerStyle: {
          backgroundColor: '#544849',
        },
        tintColor: 'transparent',
        headerLeft: <TouchableOpacity onPress={() => navigation.goBack()}><Image source={require('../../img/close.png')} style={{marginTop: 10, marginLeft:10}} /></TouchableOpacity>
});
like image 178
bennygenel Avatar answered Oct 19 '22 12:10

bennygenel