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

181
Visualizações
¿Cómo puedo agregar una alerta en StackScreen?

Tengo una pregunta sobre este código, quiero agregar una alerta si presiona el botón Atrás pero solo en 2 pantallas de navegación (MARKETPLACE y SHOP) La alerta es para confirmar si desea retroceder o cancelar si no ¿Cómo puedo hacer eso? Mi BackButton es la primera Stack.Screen Este es el código:

 <Stack.Navigator> <Stack.Screen name='Root' component={DrawerNavigator} options={{ headerShown: false, title: '', headerBackTitle: 'BackButton }}/> <Stack.Screen options={{ title: 'MARKETPLACE' }} name='Marketplace' component={Marketplace} /> <Stack.Screen options={{ title: 'SHOP' }} name='Shop' component={Shopping} /> <Stack.Screen options={{ title: 'CHECKOUT' }} name='Checkout' component={Checkout} /> <Stack.Screen options={{ title: 'CHECK' }} name='Check' component={CheckSuccess} /> </Stack.Navigator>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A partir de @react-navigation/native versión 5.7+ , puede agregar beforeRemove listener al objeto de navegación para evitar volver atrás.

EJEMPLO

 function Marketplace({ navigation }) { const [text, setText] = React.useState(''); const hasUnsavedChanges = Boolean(text); React.useEffect( () => navigation.addListener('beforeRemove', (e) => { if (!hasUnsavedChanges) { // If we don't have unsaved changes, then we don't need to do anything return; } // Prevent default behavior of leaving the screen e.preventDefault(); // Prompt the user before leaving the screen Alert.alert( 'Discard changes?', 'You have unsaved changes. Are you sure to discard them and leave the screen?', [ { text: "Don't leave", style: 'cancel', onPress: () => {} }, { text: 'Discard', style: 'destructive', // If the user confirmed, then we dispatch the action we blocked earlier // This will continue the action that had triggered the removal of the screen onPress: () => navigation.dispatch(e.data.action), }, ] ); }), [navigation, hasUnsavedChanges] ); return ( <TextInput value={text} placeholder="Type something…" onChangeText={setText} /> ); }

Ver más Detalles

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