ehsan
ehsan

Reputation: 522

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'
      }
    }
  }
})

Upvotes: 3

Views: 1573

Answers (2)

Haider Ali
Haider Ali

Reputation: 1285

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
      ),
    }
}
  }

Upvotes: 2

pritesh
pritesh

Reputation: 2192

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
} 

Upvotes: 1

Related Questions