diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackageTurboModuleManagerDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackageTurboModuleManagerDelegate.java index 9bdf41fac04883..59ed163e91a33c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackageTurboModuleManagerDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackageTurboModuleManagerDelegate.java @@ -25,14 +25,11 @@ public class CompositeReactPackageTurboModuleManagerDelegate protected native HybridData initHybrid(); - private final List mDelegates; - private CompositeReactPackageTurboModuleManagerDelegate( ReactApplicationContext context, List packages, List delegates) { super(context, packages); - mDelegates = delegates; for (TurboModuleManagerDelegate delegate : delegates) { addTurboModuleManagerDelegate(delegate); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java index 38d8c24b17f77a..874f02dc1dac15 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java @@ -103,14 +103,7 @@ private Map getViewManagersMap() { if (mViewManagers == null) { Map viewManagers = new HashMap<>(); appendMap( - viewManagers, - TraceUpdateOverlayManager.REACT_CLASS, - new Provider() { - @Override - public NativeModule get() { - return new TraceUpdateOverlayManager(); - } - }); + viewManagers, TraceUpdateOverlayManager.REACT_CLASS, TraceUpdateOverlayManager::new); mViewManagers = viewManagers; } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.java index 9ec077bc04d73d..84d4caa329d09c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.java @@ -9,7 +9,6 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE; -import androidx.annotation.NonNull; import com.facebook.react.bridge.ModuleHolder; import com.facebook.react.bridge.ModuleSpec; import com.facebook.react.bridge.NativeModule; @@ -36,18 +35,14 @@ public abstract class LazyReactPackage implements ReactPackage { @Deprecated public static ReactModuleInfoProvider getReactModuleInfoProviderViaReflection( LazyReactPackage lazyReactPackage) { - return new ReactModuleInfoProvider() { - @Override - public Map getReactModuleInfos() { - return Collections.emptyMap(); - } - }; + return Collections::emptyMap; } /** * We return an iterable * - * @param reactContext - * @return + * @param reactContext context + * @return {@link Iterable} that contains all native modules registered for the + * context */ public Iterable getNativeModuleIterator( final ReactApplicationContext reactContext) { @@ -55,11 +50,8 @@ public Iterable getNativeModuleIterator( getReactModuleInfoProvider().getReactModuleInfos(); final List nativeModules = getNativeModules(reactContext); - return new Iterable() { - @NonNull - @Override - public Iterator iterator() { - return new Iterator() { + return () -> + new Iterator() { int position = 0; @Override @@ -93,8 +85,6 @@ public void remove() { throw new UnsupportedOperationException("Cannot remove native modules from the list"); } }; - } - }; } /** diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java index abfb6c82ebdfee..ecb5203c39dff3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java @@ -71,49 +71,43 @@ public TurboModuleManager( delegate == null ? new ArrayList() : delegate.getEagerInitModuleNames(); mModuleProvider = - new ModuleProvider() { - @Nullable - public TurboModule getModule(String moduleName) { - if (delegate == null || shouldRouteTurboModulesThroughInteropLayer()) { - return null; - } + moduleName -> { + if (delegate == null || shouldRouteTurboModulesThroughInteropLayer()) { + return null; + } - TurboModule module = delegate.getModule(moduleName); - if (module == null) { - CxxModuleWrapper legacyCxxModule = delegate.getLegacyCxxModule(moduleName); - - if (legacyCxxModule != null) { - // TurboModuleManagerDelegate.getLegacyCxxModule() must always return TurboModules - Assertions.assertCondition( - legacyCxxModule instanceof TurboModule, - "CxxModuleWrapper \"" + moduleName + "\" is not a TurboModule"); - module = (TurboModule) legacyCxxModule; - } + TurboModule module = delegate.getModule(moduleName); + if (module == null) { + CxxModuleWrapper legacyCxxModule = delegate.getLegacyCxxModule(moduleName); + + if (legacyCxxModule != null) { + // TurboModuleManagerDelegate.getLegacyCxxModule() must always return TurboModules + Assertions.assertCondition( + legacyCxxModule instanceof TurboModule, + "CxxModuleWrapper \"" + moduleName + "\" is not a TurboModule"); + module = (TurboModule) legacyCxxModule; } - return module; } + return module; }; mLegacyModuleProvider = - new ModuleProvider() { - @Nullable - public NativeModule getModule(String moduleName) { - if (delegate == null || !shouldCreateLegacyModules()) { - return null; - } + moduleName -> { + if (delegate == null || !shouldCreateLegacyModules()) { + return null; + } - NativeModule nativeModule = delegate.getLegacyModule(moduleName); - if (nativeModule != null) { - if (!shouldRouteTurboModulesThroughInteropLayer()) { - // TurboModuleManagerDelegate.getLegacyModule must never return a TurboModule - Assertions.assertCondition( - !(nativeModule instanceof TurboModule), - "NativeModule \"" + moduleName + "\" is a TurboModule"); - } - return nativeModule; + NativeModule nativeModule = delegate.getLegacyModule(moduleName); + if (nativeModule != null) { + if (!shouldRouteTurboModulesThroughInteropLayer()) { + // TurboModuleManagerDelegate.getLegacyModule must never return a TurboModule + Assertions.assertCondition( + !(nativeModule instanceof TurboModule), + "NativeModule \"" + moduleName + "\" is a TurboModule"); } return nativeModule; } + return nativeModule; }; } @@ -148,6 +142,7 @@ private NativeModule getLegacyJavaModule(String moduleName) { : null; } + @SuppressWarnings("unused") @DoNotStrip @Nullable private CxxModuleWrapper getLegacyCxxModule(String moduleName) { @@ -158,6 +153,7 @@ private CxxModuleWrapper getLegacyCxxModule(String moduleName) { : null; } + @SuppressWarnings("unused") @DoNotStrip @Nullable private CxxModuleWrapper getTurboLegacyCxxModule(String moduleName) {