Git Product home page Git Product logo

Comments (14)

Ehesp avatar Ehesp commented on March 29, 2024 4

Not here, however I'm integrating it with Redux so that might be the issue. Will investigate more and see if I can replicate without Redux.

from react-navigation.

satya164 avatar satya164 commented on March 29, 2024

Can you explain a bit more what you mean? Which component? What's the use case?

from react-navigation.

tlvenn avatar tlvenn commented on March 29, 2024

If I had to guess, I think the OP meant:

Android back button handling (it just works, no need to do anything)

from react-navigation.

vonovak avatar vonovak commented on March 29, 2024

Sorry for not giving more details @satya164 . I have updated the desciption.

from react-navigation.

satya164 avatar satya164 commented on March 29, 2024

@vonovak I think what you're asking could be done easily with BackAndroid directly

componentDidMount() {
  this._listener = BackAndroid.addListener('hardwareBackPress', () => {
    if (shouldDoSomething) {
      doSomething();
      return true;
    }
  });
}

componentWillUnmount() {
  this._listener.remove();
}

This is not declarative like a component, but let's the job done. And you could easily create a component for this if you need.

from react-navigation.

vonovak avatar vonovak commented on March 29, 2024

@satya164 I was assumming that the android back button "just works" out of the box - i.e. it does a pop() unless I specify otherwise. That is not the case, it seems? (I updated the description again, sorry)

from react-navigation.

satya164 avatar satya164 commented on March 29, 2024

@vonovak yes, it works out of the box, and you can override it by attaching a listener in your component and returning true from the listener.

from react-navigation.

vonovak avatar vonovak commented on March 29, 2024

ok, great! let me know where (what file of the docs) I should land a PR documenting this if you're interested.

from react-navigation.

satya164 avatar satya164 commented on March 29, 2024

@vonovak I'm not really sure. since the behaviour comes fromBackAndroid. We're not doing anything special to allow you to override it.

from react-navigation.

vonovak avatar vonovak commented on March 29, 2024

@satya164 I see, no need for special docs, then.

from react-navigation.

Ehesp avatar Ehesp commented on March 29, 2024

@satya164 Just came across this. Using StackNavigator, when traversing down the stack (child pages), BackAndroid closes the app rather than navigating back up the stack until it hits the Init route, which would then close the app.

If this is intended, like you say it's easily handled - just I read this thread thinking the default behaviour would be like what I just described. Cheers

from react-navigation.

satya164 avatar satya164 commented on March 29, 2024

@Ehesp sorry I didn't get what you mean. doesn't back button behave the same as navigation.goBack? can you open an issue with a sample if it doesn't?

from react-navigation.

lndgalante avatar lndgalante commented on March 29, 2024

@Ehesp Did you still have the same problem ? I have exactly the same issue but I fix it with what @satya164 said about BackAndroid

BackAndroid.addEventListener('hardwareBackPress', () => true);

I don't know if this is the correct solution but this doesn't closes my App and also allows me to navigate back keeping the navigators history.

from react-navigation.

lu79931748 avatar lu79931748 commented on March 29, 2024

@lndgalante you solve this problem already?

componentWillMount(){

BackHandler.addEventListener('hardwareBackPress', this._onBackAndroid)

}

_onBackAndroid = () => {
console.log(this.props.navigation.state.routeName)
if (this.lastBackPressed && this.lastBackPressed + 2000 >= Date.now()) {
return false;
}
this.lastBackPressed = Date.now();
toastShort('Press Again Exit App');
return true;
};

componentWillUnmount(){
BackHandler.removeEventListener('hardwareBackPress', this._onBackAndroid)
}

the method of _onBackAndroid does not work until back root route

from react-navigation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.