Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

back button in react native

Is there is a way to hide back button for android devices and make it visible for iOS devices?

Following code displays Back button for both devices.

const Stack =  createStackNavigator({
  Login: {
    screen : LoginTabs,
    navigationOptions : {
      header: null  
    }
    },
  Home : {
    screen : Home,
    navigationOptions : {
      title : 'Dashboard',
      headerStyle : {
        backgroundColor : '#1565C0'
      }
    }
  }
})
like image 843
ehsan Avatar asked Apr 30 '26 07:04

ehsan


2 Answers

this is what you can do

static navigationOptions = ({ navigation }) => {
    const { state } = navigation
if(Platform.OS === 'ios'){
    return {
      title: 'title',
      headerLeft: (
          <Button />
      ),
    }
}else{
return {
      title: 'title',
      headerLeft: (
        null
      ),
    }
}
  }
like image 103
Haider Ali Avatar answered May 03 '26 11:05

Haider Ali


You can import Platform from react-native like:

import { Platform } from 'react-native'

And check in your component like:

if(Platform.OS === 'ios') {
//Render Back button
} 
like image 38
pritesh Avatar answered May 03 '26 11:05

pritesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!