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

Summary:
# 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 73bf406 commit 325fa5e
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
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 325fa5e

Please sign in to comment.