diff --git a/ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackage.java b/ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackage.java index d5ad85657c716e..3cae5492de17ec 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackage.java @@ -14,6 +14,7 @@ import com.facebook.react.module.model.ReactModuleInfoProvider; import com.facebook.react.uimanager.ViewManager; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -89,18 +90,18 @@ public List createViewManagers(ReactApplicationContext reactContext /** {@inheritDoc} */ @Override - public List getViewManagerNames(ReactApplicationContext reactContext) { + public Collection getViewManagerNames(ReactApplicationContext reactContext) { Set uniqueNames = new HashSet<>(); for (ReactPackage reactPackage : mChildReactPackages) { if (reactPackage instanceof ViewManagerOnDemandReactPackage) { - List names = + Collection names = ((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(reactContext); if (names != null) { uniqueNames.addAll(names); } } } - return new ArrayList<>(uniqueNames); + return uniqueNames; } /** {@inheritDoc} */ diff --git a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java index e882247d145af1..700577ae451282 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java @@ -37,8 +37,8 @@ import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManagerResolver; import com.facebook.systrace.Systrace; +import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -184,7 +184,7 @@ private UIManagerModule createUIManager(final ReactApplicationContext reactConte } @Override - public List getViewManagerNames() { + public Collection getViewManagerNames() { return mReactInstanceManager.getViewManagerNames(); } }; diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index e046f6b5bc370f..feed1ca6d0bd4e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -159,7 +159,7 @@ public interface ReactInstanceEventListener private final JavaScriptExecutorFactory mJavaScriptExecutorFactory; // See {@code ReactInstanceManagerBuilder} for description of all flags here. - private @Nullable List mViewManagerNames = null; + private @Nullable Collection mViewManagerNames = null; private final @Nullable JSBundleLoader mBundleLoader; private final @Nullable String mJSMainModulePath; /* path to JS bundle root on Metro */ private final List mPackages; @@ -962,9 +962,9 @@ public List getOrCreateViewManagers( return null; } - public @Nullable List getViewManagerNames() { + public Collection getViewManagerNames() { Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstanceManager.getViewManagerNames"); - List viewManagerNames = mViewManagerNames; + Collection viewManagerNames = mViewManagerNames; if (viewManagerNames != null) { return viewManagerNames; } @@ -972,7 +972,7 @@ public List getOrCreateViewManagers( synchronized (mReactContextLock) { context = (ReactApplicationContext) getCurrentReactContext(); if (context == null || !context.hasActiveReactInstance()) { - return null; + return Collections.emptyList(); } } @@ -985,7 +985,7 @@ public List getOrCreateViewManagers( .arg("Package", reactPackage.getClass().getSimpleName()) .flush(); if (reactPackage instanceof ViewManagerOnDemandReactPackage) { - List names = + Collection names = ((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(context); if (names != null) { uniqueNames.addAll(names); @@ -994,7 +994,7 @@ public List getOrCreateViewManagers( SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush(); } Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); - mViewManagerNames = new ArrayList<>(uniqueNames); + mViewManagerNames = uniqueNames; } return mViewManagerNames; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/ViewManagerOnDemandReactPackage.java b/ReactAndroid/src/main/java/com/facebook/react/ViewManagerOnDemandReactPackage.java index 7f3c192740f139..3644716614bd1e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ViewManagerOnDemandReactPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ViewManagerOnDemandReactPackage.java @@ -10,15 +10,14 @@ import androidx.annotation.Nullable; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; -import java.util.List; +import java.util.Collection; public interface ViewManagerOnDemandReactPackage { /** * Provides a list of names of ViewManagers with which these modules can be accessed from JS. * Typically, this is ViewManager.getName(). */ - @Nullable - List getViewManagerNames(ReactApplicationContext reactContext); + Collection getViewManagerNames(ReactApplicationContext reactContext); /** * Creates and returns a ViewManager with a specific name {@param viewManagerName}. It's up to an * implementing package how to interpret the name. diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java index 93fe6baaea737e..a4d8facc08d9ec 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java @@ -12,6 +12,7 @@ import androidx.annotation.Nullable; import com.facebook.react.common.MapBuilder; import com.facebook.systrace.SystraceMessage; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -33,7 +34,7 @@ */ /* package */ static Map createConstants(ViewManagerResolver resolver) { Map constants = UIManagerModuleConstants.getConstants(); - constants.put("ViewManagerNames", resolver.getViewManagerNames()); + constants.put("ViewManagerNames", new ArrayList<>(resolver.getViewManagerNames())); constants.put("LazyViewManagersEnabled", true); return constants; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagerResolver.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagerResolver.java index 05c75eb1bac666..8c69d6f0d5af90 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagerResolver.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagerResolver.java @@ -7,7 +7,7 @@ package com.facebook.react.uimanager; -import java.util.List; +import java.util.Collection; import javax.annotation.Nullable; /** Enables lazy discovery of a specific {@link ViewManager} by its name. */ @@ -22,5 +22,5 @@ public interface ViewManagerResolver { /** * Provides a list of view manager names to register in JS as {@code UIManager.ViewManagerName} */ - List getViewManagerNames(); + Collection getViewManagerNames(); }