Fix BackAndroid subscriptions calls
Summary: `BackAndroid` JS event subscriptions should be called in reverse order (the subscription from the latest `addEventLister` should run first). Also if listener returns true, don't call other listeners. **Motivation**: We use `BackAndroid` listeners to prevent closing screens with user's input. When we have two screens in stack (each screen with listener, which show alerts), we want to show alert only from the last screen listener, not from all. Closes https://github.com/facebook/react-native/pull/8929 Differential Revision: D3598978 Pulled By: dmmiller fbshipit-source-id: a7b0762b36a60755a844e90fffd58887f89c9ffb
This commit is contained in:
parent
631785f2ee
commit
b8576312ca
|
@ -25,11 +25,14 @@ var _backPressSubscriptions = new Set();
|
|||
RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() {
|
||||
var backPressSubscriptions = new Set(_backPressSubscriptions);
|
||||
var invokeDefault = true;
|
||||
backPressSubscriptions.forEach((subscription) => {
|
||||
if (subscription()) {
|
||||
var subscriptions = [...backPressSubscriptions].reverse();
|
||||
for (var i = 0; i < subscriptions.length; ++i) {
|
||||
if (subscriptions[i]()) {
|
||||
invokeDefault = false;
|
||||
}
|
||||
});
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
if (invokeDefault) {
|
||||
BackAndroid.exitApp();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue