Skip to content

Commit c0e9230

Browse files
Gate shared C++ + Java/Kotlin legacy view manager interop behind RCT_REMOVE_LEGACY_COMPONENT_INTEROP
Summary: Changelog: [General][Added] Gate shared C++ and Android Java/Kotlin legacy view manager interop behind `RCT_REMOVE_LEGACY_COMPONENT_INTEROP` Differential Revision: D107477086
1 parent e3b782b commit c0e9230

18 files changed

Lines changed: 70 additions & 6 deletions

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,7 @@ public final class com/facebook/react/common/build/ReactBuildConfig {
16551655
public static final field IS_INTERNAL_BUILD Z
16561656
public static final field UNSTABLE_ENABLE_FUSEBOX_RELEASE Z
16571657
public static final field UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE Z
1658+
public static final field UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP Z
16581659
}
16591660

16601661
public abstract interface class com/facebook/react/common/mapbuffer/MapBuffer : java/lang/Iterable, kotlin/jvm/internal/markers/KMappedMarker {

packages/react-native/ReactAndroid/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ android {
561561
buildConfigField("boolean", "UNSTABLE_ENABLE_FUSEBOX_RELEASE", "false")
562562
buildConfigField("boolean", "ENABLE_PERFETTO", "false")
563563
buildConfigField("boolean", "UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE", "false")
564+
buildConfigField("boolean", "UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP", "false")
564565

565566
resValue("integer", "react_native_dev_server_port", reactNativeDevServerPort())
566567
resValue("string", "react_native_dev_server_ip", "localhost")

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.facebook.react.bridge.queue.MessageQueueThread;
2727
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
2828
import com.facebook.react.common.LifecycleState;
29+
import com.facebook.react.common.build.ReactBuildConfig;
2930
import com.facebook.react.interfaces.ExtraWindowEventListener;
3031
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
3132
import java.lang.ref.WeakReference;
@@ -579,6 +580,9 @@ public boolean startActivityForResult(Intent intent, int code, Bundle bundle) {
579580
*/
580581
public <T extends JavaScriptModule> void internal_registerInteropModule(
581582
Class<T> interopModuleInterface, Object interopModule) {
583+
if (ReactBuildConfig.UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP) {
584+
return;
585+
}
582586
if (mInteropModuleRegistry != null) {
583587
mInteropModuleRegistry.registerInteropModule(interopModuleInterface, interopModule);
584588
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/build/ReactBuildConfig.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ public object ReactBuildConfig {
3737
@JvmField
3838
public val UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE: Boolean =
3939
BuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE
40+
41+
@JvmField
42+
public val UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP: Boolean =
43+
BuildConfig.UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP
4044
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ public void initialize() {
447447

448448
ReactMarker.addFabricListener(mDevToolsReactPerfLogger);
449449
}
450-
if (ReactNativeNewArchitectureFeatureFlags.useFabricInterop()) {
450+
if (!ReactBuildConfig.UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP
451+
&& ReactNativeNewArchitectureFeatureFlags.useFabricInterop()) {
451452
InteropEventEmitter interopEventEmitter = new InteropEventEmitter(mReactApplicationContext);
452453
mReactApplicationContext.internal_registerInteropModule(
453454
RCTEventEmitter.class, interopEventEmitter);
@@ -514,7 +515,8 @@ public void sweepActiveTouchForTag(int surfaceId, int reactTag) {
514515
* [addUiBlock] and [prependUiBlock] on UIManagerModule.
515516
*/
516517
public void addUIBlock(UIBlock block) {
517-
if (ReactNativeNewArchitectureFeatureFlags.useFabricInterop()) {
518+
if (!ReactBuildConfig.UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP
519+
&& ReactNativeNewArchitectureFeatureFlags.useFabricInterop()) {
518520
InteropUIBlockListener listener = getInteropUIBlockListener();
519521
listener.addUIBlock(block);
520522
}
@@ -525,7 +527,8 @@ public void addUIBlock(UIBlock block) {
525527
* [addUiBlock] and [prependUiBlock] on UIManagerModule.
526528
*/
527529
public void prependUIBlock(UIBlock block) {
528-
if (ReactNativeNewArchitectureFeatureFlags.useFabricInterop()) {
530+
if (!ReactBuildConfig.UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP
531+
&& ReactNativeNewArchitectureFeatureFlags.useFabricInterop()) {
529532
InteropUIBlockListener listener = getInteropUIBlockListener();
530533
listener.prependUIBlock(block);
531534
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ internal class BridgelessReactContext(context: Context, private val reactHost: R
5656
get() = reactHost.defaultBackButtonHandler
5757

5858
init {
59-
if (ReactNativeNewArchitectureFeatureFlags.useFabricInterop()) {
59+
if (
60+
!ReactBuildConfig.UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP &&
61+
ReactNativeNewArchitectureFeatureFlags.useFabricInterop()
62+
) {
6063
initializeInteropModules()
6164
}
6265
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ internal object UIManagerModuleConstantsHelper {
143143
var viewManagerBubblingEvents: MutableMap<String, Any>? =
144144
viewManager.exportedCustomBubblingEventTypeConstants
145145
if (viewManagerBubblingEvents != null) {
146-
if (useFabricInterop()) {
146+
if (!ReactBuildConfig.UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP && useFabricInterop()) {
147147
// For Fabric, events needs to be fired with a "top" prefix.
148148
// For the sake of Fabric Interop, here we normalize events adding "top" in their
149149
// name if the user hasn't provided it.
@@ -160,7 +160,7 @@ internal object UIManagerModuleConstantsHelper {
160160
viewManager.exportedCustomDirectEventTypeConstants
161161
validateDirectEventNames(viewManager.getName(), viewManagerDirectEvents)
162162
if (viewManagerDirectEvents != null) {
163-
if (useFabricInterop()) {
163+
if (!ReactBuildConfig.UNSTABLE_REMOVE_LEGACY_COMPONENT_INTEROP && useFabricInterop()) {
164164
// For Fabric, events needs to be fired with a "top" prefix.
165165
// For the sake of Fabric Interop, here we normalize events adding "top" in their
166166
// name if the user hasn't provided it.

packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#include <react/debug/react_native_assert.h>
1313
#include <react/featureflags/ReactNativeFeatureFlags.h>
1414
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
15+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
1516
#include <react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerAutomaticComponentDescriptor.h>
1617
#include <react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerAutomaticShadowNode.h>
18+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP
1719
#include <react/renderer/core/PropsParserContext.h>
1820
#include <react/renderer/core/ShadowNodeFragment.h>
1921
#include <utility>
@@ -84,6 +86,7 @@ const ComponentDescriptor& ComponentDescriptorRegistry::at(
8486
}
8587

8688
if (it == _registryByName.end()) {
89+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
8790
if (ReactNativeFeatureFlags::useFabricInterop()) {
8891
// When interop is enabled, if the component is not found we rely on
8992
// UnstableLegacyViewManagerAutomaticComponentDescriptor to support legacy
@@ -94,6 +97,7 @@ const ComponentDescriptor& ComponentDescriptorRegistry::at(
9497
registerComponentDescriptor(componentDescriptor);
9598
return *_registryByName.find(unifiedComponentName)->second;
9699
} else {
100+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP
97101
// When interop is disabled, if the component is not found we rely on
98102
// fallbackComponentDescriptor (default:
99103
// UnimplementedNativeViewComponentDescriptor).
@@ -107,7 +111,9 @@ const ComponentDescriptor& ComponentDescriptorRegistry::at(
107111
} else {
108112
return *_fallbackComponentDescriptor.get();
109113
}
114+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
110115
}
116+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP
111117
}
112118

113119
return *it->second;

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropShadowNode.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
9+
810
namespace facebook::react {
911

1012
extern const char LegacyViewManagerInteropComponentName[] =
1113
"LegacyViewManagerInterop";
1214

1315
} // namespace facebook::react
16+
17+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropShadowNode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
11+
1012
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropState.h>
1113
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h>
1214
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
@@ -22,3 +24,5 @@ using LegacyViewManagerInteropShadowNode = ConcreteViewShadowNode<
2224
LegacyViewManagerInteropState>;
2325

2426
} // namespace facebook::react
27+
28+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

0 commit comments

Comments
 (0)