From 41e9bcb1ef28c1532863186c83423814fcaf2372 Mon Sep 17 00:00:00 2001 From: Krzysztof Moch Date: Wed, 31 Jan 2024 12:36:01 +0100 Subject: [PATCH] fix(android): fix crash with interop layer (#3509) --- .../brentvatne/common/react/VideoEventEmitter.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/brentvatne/common/react/VideoEventEmitter.java b/android/src/main/java/com/brentvatne/common/react/VideoEventEmitter.java index 31cbc27f..ed194950 100644 --- a/android/src/main/java/com/brentvatne/common/react/VideoEventEmitter.java +++ b/android/src/main/java/com/brentvatne/common/react/VideoEventEmitter.java @@ -9,8 +9,11 @@ import com.brentvatne.common.api.Track; import com.brentvatne.common.api.VideoTrack; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.UIManager; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; +import com.facebook.react.uimanager.UIManagerHelper; +import com.facebook.react.uimanager.common.ViewUtil; import com.facebook.react.uimanager.events.RCTEventEmitter; import com.google.ads.interactivemedia.v3.api.AdError; @@ -23,12 +26,12 @@ import java.util.Map; public class VideoEventEmitter { - private final RCTEventEmitter eventEmitter; + private final ReactContext mReactContext; private int viewId = View.NO_ID; public VideoEventEmitter(ReactContext reactContext) { - this.eventEmitter = reactContext.getJSModule(RCTEventEmitter.class); + this.mReactContext = reactContext; } private static final String EVENT_LOAD_START = "onVideoLoadStart"; @@ -449,6 +452,10 @@ public class VideoEventEmitter { } private void receiveEvent(@VideoEvents String type, WritableMap event) { - eventEmitter.receiveEvent(viewId, type, event); + UIManager uiManager = UIManagerHelper.getUIManager(mReactContext, ViewUtil.getUIManagerType(viewId)); + + if(uiManager != null) { + uiManager.receiveEvent(UIManagerHelper.getSurfaceId(mReactContext), viewId, type, event); + } } }