From 4baa9870bad31ceb15e122e6cb6de3e452adb223 Mon Sep 17 00:00:00 2001 From: Joe Mun Date: Wed, 12 Jul 2023 17:04:41 -0700 Subject: [PATCH] fix to work with fabric interop --- Video.js | 4 ++-- .../brentvatne/exoplayer/ReactExoplayerViewManager.java | 8 ++++++-- .../java/com/brentvatne/exoplayer/VideoEventEmitter.java | 2 +- .../java/com/brentvatne/react/ReactVideoViewManager.java | 2 +- examples/fabric/react-native.config.js | 9 +++++++++ ios/Video/RCTVideoManager.m | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Video.js b/Video.js index a3452ad511..77c1d1f883 100644 --- a/Video.js +++ b/Video.js @@ -279,7 +279,7 @@ export default class Video extends Component { const isAsset = !!(uri && uri.match(/^(assets-library|ipod-library|file|content|ms-appx|ms-appdata):/)); let nativeResizeMode; - const RCTVideoInstance = this.getViewManagerConfig('RCTVideo'); + const RCTVideoInstance = this.getViewManagerConfig('RNVVideo'); if (resizeMode === VideoResizeMode.stretch) { nativeResizeMode = RCTVideoInstance.Constants.ScaleToFill; @@ -510,7 +510,7 @@ Video.propTypes = { ...ViewPropTypes, }; -const RCTVideo = requireNativeComponent('RCTVideo', Video, { +const RCTVideo = requireNativeComponent('RNVVideo', Video, { nativeOnly: { src: true, seek: true, diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index eccbee7563..ee95a84b95 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -10,6 +10,7 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.common.MapBuilder; +import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.annotations.ReactProp; @@ -27,7 +28,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager { - private static final String REACT_CLASS = "RCTVideo"; + private static final String REACT_CLASS = "RNVVideo"; private static final String PROP_SRC = "src"; private static final String PROP_SRC_URI = "uri"; @@ -96,7 +97,10 @@ public void onDropViewInstance(ReactExoplayerView view) { public @Nullable Map getExportedCustomDirectEventTypeConstants() { MapBuilder.Builder builder = MapBuilder.builder(); for (String event : VideoEventEmitter.Events) { - builder.put(event, MapBuilder.of("registrationName", event)); + String eventKey = ReactFeatureFlags.enableFabricRenderer ? + "top" + event.substring(0, 1).toUpperCase() + event.substring(1) : + event; + builder.put(eventKey, MapBuilder.of("registrationName", event)); } return builder.build(); } diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java index ea0cc5ac6d..881e9361d4 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java @@ -299,6 +299,6 @@ void audioBecomingNoisy() { } private void receiveEvent(@VideoEvents String type, WritableMap event) { - eventEmitter.receiveEvent(viewId, type, event); + eventEmitter.receiveEvent(viewId, type, event != null ? event : Arguments.createMap()); } } diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java b/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java index 59efab497d..1cd5afdefc 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java @@ -16,7 +16,7 @@ public class ReactVideoViewManager extends SimpleViewManager { - public static final String REACT_CLASS = "RCTVideo"; + public static final String REACT_CLASS = "RNVVideo"; public static final String PROP_SRC = "src"; public static final String PROP_SRC_URI = "uri"; diff --git a/examples/fabric/react-native.config.js b/examples/fabric/react-native.config.js index e7f913cfb9..7808b75d9a 100644 --- a/examples/fabric/react-native.config.js +++ b/examples/fabric/react-native.config.js @@ -1,4 +1,13 @@ module.exports = { + project: { + android: { + unstable_reactLegacyComponentNames: ['RNVVideo'], + }, + ios: { + unstable_reactLegacyComponentNames: [], + }, + }, + dependencies: { 'react-native-video': { platforms: { diff --git a/ios/Video/RCTVideoManager.m b/ios/Video/RCTVideoManager.m index 000a9e83af..78e2e61348 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -6,7 +6,7 @@ @implementation RCTVideoManager -RCT_EXPORT_MODULE(); +RCT_EXPORT_MODULE(RNVVideoManager); - (UIView *)view {