From 90403154a21c654e4f0bc7258a3655ce9c1ae3c5 Mon Sep 17 00:00:00 2001 From: Fabian Eichinger Date: Mon, 8 Feb 2016 03:22:47 -0800 Subject: [PATCH] Snapshot the Set of listeners when dispatching a BackAndroid event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: …while an event is dispatched While it is guarded, a copy of the Set is created before listeners are added or removed. The event dispatch loop continues with the old Set of listeners. This PR modifies `BackAndroid` to match the proposal at the end of #5781. Closes https://github.com/facebook/react-native/pull/5783 Reviewed By: svcscm Differential Revision: D2911282 Pulled By: foghina fb-gh-sync-id: 34964ec3414af85eb9574bbcef081238fc67ffaf --- Libraries/Utilities/BackAndroid.android.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/Utilities/BackAndroid.android.js b/Libraries/Utilities/BackAndroid.android.js index 66baa59c4ea822..795380448d2f1d 100644 --- a/Libraries/Utilities/BackAndroid.android.js +++ b/Libraries/Utilities/BackAndroid.android.js @@ -23,8 +23,9 @@ type BackPressEventName = $Enum<{ var _backPressSubscriptions = new Set(); RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { + var backPressSubscriptions = new Set(_backPressSubscriptions); var invokeDefault = true; - _backPressSubscriptions.forEach((subscription) => { + backPressSubscriptions.forEach((subscription) => { if (subscription()) { invokeDefault = false; }