mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Simplify ViewManagerOnDemandReactPackage.getViewManagerNames to return Collection
Summary: This way we can avoid unnecessary ArrayList copies. Changelog: [Android][Changed] Generalized the return type of ViewManagerOnDemandReactPackage.getViewManagerNames Reviewed By: nlutsenko Differential Revision: D36131516 fbshipit-source-id: 6a42c76cadbcce4c3720875d80062e1ee237bc2f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d7921f0504
commit
51e029ec3c
@@ -14,6 +14,7 @@ import com.facebook.react.module.model.ReactModuleInfo;
|
||||
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 class CompositeReactPackage implements ViewManagerOnDemandReactPackage, R
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public List<String> getViewManagerNames(ReactApplicationContext reactContext) {
|
||||
public Collection<String> getViewManagerNames(ReactApplicationContext reactContext) {
|
||||
Set<String> uniqueNames = new HashSet<>();
|
||||
for (ReactPackage reactPackage : mChildReactPackages) {
|
||||
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
|
||||
List<String> names =
|
||||
Collection<String> names =
|
||||
((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(reactContext);
|
||||
if (names != null) {
|
||||
uniqueNames.addAll(names);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(uniqueNames);
|
||||
return uniqueNames;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
||||
@@ -37,8 +37,8 @@ import com.facebook.react.uimanager.UIManagerModule;
|
||||
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 @@ public class CoreModulesPackage extends TurboReactPackage implements ReactPackag
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getViewManagerNames() {
|
||||
public Collection<String> getViewManagerNames() {
|
||||
return mReactInstanceManager.getViewManagerNames();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -159,7 +159,7 @@ public class ReactInstanceManager {
|
||||
private final JavaScriptExecutorFactory mJavaScriptExecutorFactory;
|
||||
|
||||
// See {@code ReactInstanceManagerBuilder} for description of all flags here.
|
||||
private @Nullable List<String> mViewManagerNames = null;
|
||||
private @Nullable Collection<String> mViewManagerNames = null;
|
||||
private final @Nullable JSBundleLoader mBundleLoader;
|
||||
private final @Nullable String mJSMainModulePath; /* path to JS bundle root on Metro */
|
||||
private final List<ReactPackage> mPackages;
|
||||
@@ -962,9 +962,9 @@ public class ReactInstanceManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable List<String> getViewManagerNames() {
|
||||
public Collection<String> getViewManagerNames() {
|
||||
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstanceManager.getViewManagerNames");
|
||||
List<String> viewManagerNames = mViewManagerNames;
|
||||
Collection<String> viewManagerNames = mViewManagerNames;
|
||||
if (viewManagerNames != null) {
|
||||
return viewManagerNames;
|
||||
}
|
||||
@@ -972,7 +972,7 @@ public class ReactInstanceManager {
|
||||
synchronized (mReactContextLock) {
|
||||
context = (ReactApplicationContext) getCurrentReactContext();
|
||||
if (context == null || !context.hasActiveReactInstance()) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,7 +985,7 @@ public class ReactInstanceManager {
|
||||
.arg("Package", reactPackage.getClass().getSimpleName())
|
||||
.flush();
|
||||
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
|
||||
List<String> names =
|
||||
Collection<String> names =
|
||||
((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(context);
|
||||
if (names != null) {
|
||||
uniqueNames.addAll(names);
|
||||
@@ -994,7 +994,7 @@ public class ReactInstanceManager {
|
||||
SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
|
||||
}
|
||||
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
mViewManagerNames = new ArrayList<>(uniqueNames);
|
||||
mViewManagerNames = uniqueNames;
|
||||
}
|
||||
return mViewManagerNames;
|
||||
}
|
||||
|
||||
@@ -10,15 +10,14 @@ package com.facebook.react;
|
||||
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<String> getViewManagerNames(ReactApplicationContext reactContext);
|
||||
Collection<String> 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.
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
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 @@ import java.util.Map;
|
||||
*/
|
||||
/* package */ static Map<String, Object> createConstants(ViewManagerResolver resolver) {
|
||||
Map<String, Object> constants = UIManagerModuleConstants.getConstants();
|
||||
constants.put("ViewManagerNames", resolver.getViewManagerNames());
|
||||
constants.put("ViewManagerNames", new ArrayList<>(resolver.getViewManagerNames()));
|
||||
constants.put("LazyViewManagersEnabled", true);
|
||||
return constants;
|
||||
}
|
||||
|
||||
@@ -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<String> getViewManagerNames();
|
||||
Collection<String> getViewManagerNames();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user