Skip to content

Commit ee7514c

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Ensure Synchronous events are always dispatched from the UIThread (facebook#49732)
Summary: Pull Request resolved: facebook#49732 Ensure Synchronous events are always dispatched from the UIThread changelog: [internal] internal Reviewed By: lunaleaps, NickGerleman Differential Revision: D70203460 fbshipit-source-id: 04fa02ae731bce579a231052e5ed7953852f61bc
1 parent 8698eca commit ee7514c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ public class FabricUIManager
180180
private final DispatchUIFrameCallback mDispatchUIFrameCallback;
181181

182182
/** Set of events sent synchronously during the current frame render. Cleared after each frame. */
183+
@ThreadConfined(UI)
184+
@NonNull
183185
private final Set<SynchronousEvent> mSynchronousEvents = new HashSet<>();
184186

185187
/**
@@ -999,6 +1001,7 @@ public void receiveEvent(
9991001
}
10001002

10011003
if (experimentalIsSynchronous) {
1004+
UiThreadUtil.assertOnUiThread();
10021005
// add() returns true only if there are no equivalent events already in the set
10031006
boolean firstEventForFrame =
10041007
mSynchronousEvents.add(new SynchronousEvent(surfaceId, reactTag, eventName));
@@ -1389,7 +1392,7 @@ public void doFrameGuarded(long frameTimeNanos) {
13891392
} catch (Exception ex) {
13901393
FLog.e(TAG, "Exception thrown when executing UIFrameGuarded", ex);
13911394
mIsMountingEnabled = false;
1392-
throw ex;
1395+
throw new RuntimeException("Exception thrown when executing UIFrameGuarded", ex);
13931396
} finally {
13941397
schedule();
13951398
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/EventEmitterWrapper.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.annotation.SuppressLint
1111
import com.facebook.jni.HybridClassBase
1212
import com.facebook.proguard.annotations.DoNotStripAny
1313
import com.facebook.react.bridge.NativeMap
14+
import com.facebook.react.bridge.UiThreadUtil
1415
import com.facebook.react.bridge.WritableMap
1516
import com.facebook.react.fabric.FabricSoLoader.staticInit
1617
import com.facebook.react.uimanager.events.EventCategoryDef
@@ -55,6 +56,7 @@ public class EventEmitterWrapper private constructor() : HybridClassBase() {
5556
if (!isValid) {
5657
return
5758
}
59+
UiThreadUtil.assertOnUiThread()
5860
dispatchEventSynchronously(eventName, params as NativeMap?)
5961
}
6062

0 commit comments

Comments
 (0)