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

147
Visualizações
Not able to perform 2 actions on the same component when hardware back button is pressed in react-native,below are the code regarding the backhandler
 backAction = () => {
    if (this.props.navigation.isFocused() && !this.state.otpScreen) {
     
  this.setState({ showLoginScreen: true });
  return true;

} else if(this.state.showLoginScreen) {
  this.props.navigation.dispatch(CommonActions.reset({
    index: 0,
    routes: [
      { name: 'Login' },
    ],
  }))
  
  return false;
}

};

the code above is for action that should be done by the hardware back press, at first it should show the one screen and on the second press it should exit the app, both otp screen and login screen are on the same component, I'm just hiding based on the condition ... at the first time it is working as per the condition but for the second time it's not.

 componentDidMount() {
this.focusListener = this.props.navigation.addListener('focus', () => {
  this.setState({
    mobile: '',
    showLoginScreen: true,
  });
});
this.getDataFromStorage();
AsyncStorage.setItem('countryCode', '+91');
BackHandler.addEventListener(
  "hardwareBackPress",
  this.backAction
);


}
  componentWillUnmount() {
    clearInterval(this.interval)
    BackHandler.addEventListener('hardwareBackPress', () => { return false })
  }

can anyone pls help me how to do this,thanks in Advance

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

0

I guess your problem is that you can't access the 'current' value of a state inside a listener.

More Details here

Try to use a Reference instead of a state

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