react-native icon indicating copy to clipboard operation
react-native copied to clipboard

BackAndroid Functionality reg

Open lalith26 opened this issue 11 years ago • 2 comments

Hi

I have included the code snippet in MainActivity. But Here is my observation:

When the app loads and the first scene is rendered, here when i press the hardware back button, the app quits because I am returning false from my implementation of BackAndroid.

But when I move to the second scene and again when I come back to the first scene and then press the hardware back button, the app does not quit.

Is this the default expected behaviour? My implementation is as follows:

BackAndroid.addEventListener('hardwareBackPress', () => {return false;});

Another Observation is: When the app loads the third scene and when back button is pressed there, Instead of just going back one scene, It goes back to the first scene. The implementation is as follows:

BackAndroid.addEventListener('hardwareBackPress', () => {if (this.props.nav) {this.props.nav.pop(); return true;} return false;});

Thanks in Advance Lalith

lalith26 avatar Nov 18 '15 03:11 lalith26

It could be that the event is initiated multiple times by mistake, and then fires more than once. Have you tried logging to see how many times the callback is fired?

ramilushev avatar Nov 18 '15 12:11 ramilushev

Ideally you want to only register the handler on BackAndroid in one place or it will be tough to reason about, because all of those listeners will be called when the back button is pressed:

https://github.com/facebook/react-native/blob/0d17d6a8c0adee8cb3b91d735e0774e3aa381b13/Libraries/Utilities/BackAndroid.android.js#L27-L35

brentvatne avatar Nov 20 '15 06:11 brentvatne