Skip to content

Commit ede99ee

Browse files
astreetFacebook Github Bot 1
authored and
Facebook Github Bot 1
committed
Backed out changeset 13a4ea1d64ce
Reviewed By: ericvicenti Differential Revision: D3093064 fb-gh-sync-id: c9b68c8c5ab8ddaf77570d2cf8024e36925e5e76 fbshipit-source-id: c9b68c8c5ab8ddaf77570d2cf8024e36925e5e76
1 parent a28e59b commit ede99ee

File tree

3 files changed

+13
-85
lines changed

3 files changed

+13
-85
lines changed

Examples/UIExplorer/BackAndroidExample.js

-66
This file was deleted.

Examples/UIExplorer/UIExplorerList.android.js

-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ const APIExamples = [
102102
key: 'AppStateExample',
103103
module: require('./AppStateExample'),
104104
},
105-
{
106-
key: 'BackAndroidExample',
107-
module: require('./BackAndroidExample'),
108-
},
109105
{
110106
key: 'BorderExample',
111107
module: require('./BorderExample'),

Libraries/Utilities/BackAndroid.android.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@ type BackPressEventName = $Enum<{
2020
backPress: string;
2121
}>;
2222

23-
var _backPressSubscriptions = [];
23+
var _backPressSubscriptions = new Set();
2424

2525
RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() {
26-
var propagate = true;
27-
for (var i = _backPressSubscriptions.length - 1; i >= 0; i--) {
28-
var subscription = _backPressSubscriptions[i];
26+
var backPressSubscriptions = new Set(_backPressSubscriptions);
27+
var invokeDefault = true;
28+
backPressSubscriptions.forEach((subscription) => {
2929
if (subscription()) {
30-
propagate = false;
31-
break;
30+
invokeDefault = false;
3231
}
33-
}
34-
35-
if (propagate) {
32+
});
33+
if (invokeDefault) {
3634
BackAndroid.exitApp();
3735
}
3836
});
@@ -62,18 +60,18 @@ var BackAndroid = {
6260
addEventListener: function (
6361
eventName: BackPressEventName,
6462
handler: Function
65-
): void {
66-
_backPressSubscriptions.push(handler);
63+
): {remove: () => void} {
64+
_backPressSubscriptions.add(handler);
65+
return {
66+
remove: () => BackAndroid.removeEventListener(eventName, handler),
67+
};
6768
},
6869

6970
removeEventListener: function(
7071
eventName: BackPressEventName,
7172
handler: Function
7273
): void {
73-
var index = _backPressSubscriptions.indexOf(handler);
74-
if (index !== -1) {
75-
_backPressSubscriptions.splice(index, 1);
76-
}
74+
_backPressSubscriptions.delete(handler);
7775
},
7876

7977
};

0 commit comments

Comments
 (0)