Skip to content

Commit

Permalink
fix[android]: fix bridgeless configuration to include DebuggingOverla…
Browse files Browse the repository at this point in the history
…y in react packages (#43661)

Summary:
Pull Request resolved: #43661

# Changelog: [Internal]

1. Move `BridgelessDebugReactPackage.java` to core, this was added in D43407534.
2. `ReactInstanceJava` to add `BridgelessDebugReactPackage`, so `DebuggingOverlay` view manager will be included in the bridgeless build.
3. Fix `RNTesterApplication.kt` to NOT create `MyLegacyViewManager` for every possible viewManagerName, apart from `"RNTMyNativeView"`, return null instead.

Differential Revision: D55375350
  • Loading branch information
hoxyq authored and facebook-github-bot committed Mar 26, 2024
1 parent bb02049 commit 786d004
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
14 changes: 14 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -3629,6 +3629,20 @@ public final class com/facebook/react/runtime/BridgelessCatalystInstance : com/f
public fun setTurboModuleRegistry (Lcom/facebook/react/internal/turbomodule/core/interfaces/TurboModuleRegistry;)V
}

public class com/facebook/react/runtime/BridgelessDebugReactPackage : com/facebook/react/TurboReactPackage, com/facebook/react/ViewManagerOnDemandReactPackage {
public fun <init> ()V
public fun createViewManager (Lcom/facebook/react/bridge/ReactApplicationContext;Ljava/lang/String;)Lcom/facebook/react/uimanager/ViewManager;
public fun getModule (Ljava/lang/String;Lcom/facebook/react/bridge/ReactApplicationContext;)Lcom/facebook/react/bridge/NativeModule;
public fun getReactModuleInfoProvider ()Lcom/facebook/react/module/model/ReactModuleInfoProvider;
public fun getViewManagerNames (Lcom/facebook/react/bridge/ReactApplicationContext;)Ljava/util/Collection;
public fun getViewManagers (Lcom/facebook/react/bridge/ReactApplicationContext;)Ljava/util/List;
}

public class com/facebook/react/runtime/BridgelessDebugReactPackage$$ReactModuleInfoProvider : com/facebook/react/module/model/ReactModuleInfoProvider {
public fun <init> ()V
public fun getReactModuleInfos ()Ljava/util/Map;
}

public class com/facebook/react/runtime/CoreReactPackage$$ReactModuleInfoProvider : com/facebook/react/module/model/ReactModuleInfoProvider {
public fun <init> ()V
public fun getReactModuleInfos ()Ljava/util/Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.runtime;

import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.TurboReactPackage;
import com.facebook.react.ViewManagerOnDemandReactPackage;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModuleList;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.debuggingoverlay.DebuggingOverlayManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Provider;

@Nullsafe(Nullsafe.Mode.LOCAL)
@ReactModuleList(nativeModules = {})
public class BridgelessDebugReactPackage extends TurboReactPackage
implements ViewManagerOnDemandReactPackage {
private @Nullable Map<String, ModuleSpec> mViewManagers;

public BridgelessDebugReactPackage() {}

@Override
public @Nullable NativeModule getModule(String name, ReactApplicationContext reactContext) {
return null;
}

@Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return new BridgelessDebugReactPackage$$ReactModuleInfoProvider();
}

private static void appendMap(
Map<String, ModuleSpec> map, String name, Provider<? extends NativeModule> provider) {
map.put(name, ModuleSpec.viewManagerSpec(provider));
}

/**
* @return a map of view managers that should be registered with {@link UIManagerModule}
*/
private Map<String, ModuleSpec> getViewManagersMap() {
if (mViewManagers == null) {
Map<String, ModuleSpec> viewManagers = new HashMap<>();
appendMap(viewManagers, DebuggingOverlayManager.REACT_CLASS, DebuggingOverlayManager::new);

mViewManagers = viewManagers;
}
return mViewManagers;
}

@Override
public List<ModuleSpec> getViewManagers(ReactApplicationContext reactContext) {
return new ArrayList<>(getViewManagersMap().values());
}

@Override
public Collection<String> getViewManagerNames(ReactApplicationContext reactContext) {
return getViewManagersMap().keySet();
}

@Override
public @Nullable ViewManager createViewManager(
ReactApplicationContext reactContext, String viewManagerName) {
ModuleSpec spec = getViewManagersMap().get(viewManagerName);
return spec != null ? (ViewManager) spec.getProvider().get() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ final class ReactInstance {
new CoreReactPackage(
bridgelessReactContext.getDevSupportManager(),
bridgelessReactContext.getDefaultHardwareBackBtnHandler()));
if (useDevSupport) {
mReactPackages.add(new BridgelessDebugReactPackage());
}
mReactPackages.addAll(mDelegate.getReactPackages());

TurboModuleManagerDelegate turboModuleManagerDelegate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ class RNTesterApplication : Application(), ReactApplication {
override fun createViewManager(
reactContext: ReactApplicationContext,
viewManagerName: String
): ViewManager<*, out ReactShadowNode<*>> =
): ViewManager<*, out ReactShadowNode<*>>? =
if (viewManagerName == "RNTMyNativeView") {
MyNativeViewManager()
} else {
} else if (viewManagerName == "RNTMyLegacyNativeView") {
MyLegacyViewManager(reactContext)
} else {
null
}
})
}
Expand Down

0 comments on commit 786d004

Please sign in to comment.