-1

How can I change the image of the back button in React Native?

enter image description here

I want to change the back arrow to a chevron.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
George542
  • 41
  • 1
  • 6

2 Answers2

0

In your StackNavigator, provide the screenOptions prop with headerBackImageSource set to the back arrow icon or image you want.

    <Stack.Navigator
      initialRouteName="Home"
      screenOptions={{
        headerBackImageSource: `...image source...`
      }}
    >
Andrew
  • 432
  • 2
  • 14
0

The way I handle the default header of stack navigator is by creating a custom one. Every component in the main stack exports a back method so you can use it to create a event listener for your custom arrow like in the example below.

MAIN COMPONENT:

function Home({ navigation }) {

  return(
    <>
       <CustomHeader
         title="Home Page"
         handleBack={() => {
           navigation.goBack()
         }}
       />  
    </>
  )
}

export default Home

CUSTOM HEADER COMPONENT:

function CustomHeader(props) {
  const title = props.title

  const handleBack = () => {
    props.handleBack()
  }

  return(
    <View>
      <Pressable
        onPress={handleBack}
      >
        <Image
          source={backArrowIcon}
          resizeMode="contain"
        />
      </Pressable>
      <Text>
        {title}
      </Text>
    </View>
  )
}

export default CustomHeader

You just need to style that and import all the components like View, Text, CustomHeader etc.

iamalinski
  • 265
  • 1
  • 4
  • 15