Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
React Native: How to navigate from inside the NavigationContainer?

I have a component in my Navigation.tsx which controls the routes within my application. The component sits inside one of my Stack.Screen's under headerRight . Im trying to navigate to a different screen when the component is clicked. However, im unable to get that working for this particular component. Routing outside my Navigation file works perfectly fine, but not within.

Im unable to figure out what i am missing or what needs to be changed.

Code below: headerRight under ItemDetails

export default function Navigation( { navigation }) {
const Stack = createStackNavigator();

const MyTheme = {
    ...DefaultTheme,
    colors: {
      ...DefaultTheme.colors,
      background: '#FFF',
    }
}

return (
    <NavigationContainer theme={MyTheme}>
        <Stack.Navigator initialRouteName="Home">

            <Stack.Screen name="Home" component={Home} options={({route}) => ({
                headerShown: false,
            })}/>
            <Stack.Screen name='CartDetails' component={CartDetails}/>
            <Stack.Screen name="ItemDetails" component={ItemDetails} options={({route}) => ({
                title: false,
                headerTitle: false,
                headerBackTitleVisible: false,
                headerTransparent: true,
                headerShadowVisible: false,
                headerRight: () => (
                    <TouchableOpacity onPress={() => { navigation.navigate('CartDetails')}}>
                        <CartIcon />
                    </TouchableOpacity>
                ),
                headerBackImage: () => (
                    
                        <View style={{backgroundColor: '#ffffff', borderRadius: '50%', marginLeft: 15, marginBottom: 5}}>
                            <Entypo name="chevron-small-left" size={30} color="#37BD6B"/>
                        </View>
                )
            })} />

        </Stack.Navigator>
    </NavigationContainer>
)

}

Thanks in advance

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I managed to solve the problem.

Rather than passing headerRight an argument, passing it to 'option' gives you the correct result.

 options={({route, navigation}) => ({ 
                title: false,
                headerTitle: false,
                headerBackTitleVisible: false,
                headerTransparent: true,
                headerShadowVisible: false,
                headerRight: () => (
                    <TouchableOpacity onPress={() => navigation.navigate('CartDetails')}>
                        <CartIcon />
                    </TouchableOpacity>
                ),
                headerBackImage: () => (
                    
                        <View style={{backgroundColor: '#ffffff', borderRadius: '50%', marginLeft: 15, marginBottom: 5}}>
                            <Entypo name="chevron-small-left" size={30} color="#37BD6B"/>
                        </View>
                )
            })}  />
about 4 years ago · Juan Pablo Isaza Relatório

0

React Navigation provides the navigation object as an argument to the header callbacks. You can take it from there.

  headerRight: ({ navigation }) => (
    <TouchableOpacity onPress={() => { navigation.navigate('CartDetails')}}>
      <CartIcon />
    </TouchableOpacity>
  ),
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda