Skip to content

Commit b857631

Browse files
SergeyKorochanskyFacebook Github Bot 4
authored and
Facebook Github Bot 4
committed
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 #8929 Differential Revision: D3598978 Pulled By: dmmiller fbshipit-source-id: a7b0762b36a60755a844e90fffd58887f89c9ffb
1 parent 631785f commit b857631

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Libraries/Utilities/BackAndroid.android.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ var _backPressSubscriptions = new Set();
2525
RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() {
2626
var backPressSubscriptions = new Set(_backPressSubscriptions);
2727
var invokeDefault = true;
28-
backPressSubscriptions.forEach((subscription) => {
29-
if (subscription()) {
28+
var subscriptions = [...backPressSubscriptions].reverse();
29+
for (var i = 0; i < subscriptions.length; ++i) {
30+
if (subscriptions[i]()) {
3031
invokeDefault = false;
31-
}
32-
});
32+
break;
33+
};
34+
}
35+
3336
if (invokeDefault) {
3437
BackAndroid.exitApp();
3538
}

0 commit comments

Comments
 (0)