Permalink
Browse files

Implement lazy discovery for ViewManagers.

Reviewed By: kathryngray

Differential Revision: D5865095

fbshipit-source-id: c94970e4cd7aafb20cf844c48feea053ac8b6b0f
  • Loading branch information...
Dmitry Zakharov authored and facebook-github-bot committed Sep 28, 2017
1 parent c4f7ce9 commit da30b047037a1b4a97159b22abfd5244ecfaee19
Showing with 466 additions and 166 deletions.
  1. +2 −5 Libraries/ReactNative/UIManager.js
  2. +1 −1 ...droid/src/androidTest/java/com/facebook/react/tests/CatalystNativeJSToJavaParametersTestCase.java
  3. +1 −1 ...ndroid/src/androidTest/java/com/facebook/react/tests/CatalystNativeJavaToJSArgumentsTestCase.java
  4. +1 −1 ...oid/src/androidTest/java/com/facebook/react/tests/CatalystNativeJavaToJSReturnValuesTestCase.java
  5. +1 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystUIManagerTestCase.java
  6. +0 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/JSLocaleTest.java
  7. +1 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ProgressBarTestCase.java
  8. +1 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ViewRenderingTestCase.java
  9. +50 −12 ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackage.java
  10. +26 −9 ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java
  11. +81 −41 ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java
  12. +28 −9 ReactAndroid/src/main/java/com/facebook/react/ReactNativeCorePackage.java
  13. +28 −0 ReactAndroid/src/main/java/com/facebook/react/ViewManagerOnDemandReactPackage.java
  14. +11 −0 ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementationProvider.java
  15. +12 −0 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java
  16. +17 −2 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementationProvider.java
  17. +88 −18 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java
  18. +82 −46 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java
  19. +25 −7 ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagerRegistry.java
  20. +1 −1 ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.java
  21. +6 −6 ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleConstantsTest.java
  22. +1 −1 ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java
  23. +1 −1 ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextTest.java
  24. +1 −1 ReactAndroid/src/test/java/com/facebook/react/views/textinput/TextInputTest.java
@@ -79,13 +79,10 @@ if (Platform.OS === 'ios') {
});
}
});
} else if (
Platform.OS === 'android' &&
UIManager.AndroidLazyViewManagersEnabled
) {
} else if (Platform.OS === 'android' && UIManager.ViewManagerNames) {
UIManager.ViewManagerNames.forEach(viewManagerName => {
defineLazyObjectProperty(UIManager, viewManagerName, {
get: () => NativeModules[viewManagerName.replace(/^(RCT|RK)/, '')],
get: () => UIManager.getConstantsForViewManager(viewManagerName),
});
});
}
@@ -86,7 +86,7 @@ protected void setUp() throws Exception {
List<ViewManager> viewManagers = Arrays.<ViewManager>asList(
new ReactViewManager());
final UIManagerModule mUIManager =
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), false, 0);
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), 0);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -63,7 +63,7 @@ protected void setUp() throws Exception {
List<ViewManager> viewManagers = Arrays.<ViewManager>asList(
new ReactViewManager());
final UIManagerModule mUIManager =
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), false, 0);
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), 0);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -113,7 +113,7 @@ protected void setUp() throws Exception {
final UIManagerModule mUIManager =
new UIManagerModule(
getContext(), new ArrayList<ViewManager>(), new UIImplementationProvider(), false, 0);
getContext(), new ArrayList<ViewManager>(), new UIImplementationProvider(), 0);
mAssertModule = new AssertModule();
@@ -79,7 +79,7 @@ protected void setUp() throws Exception {
new ReactTextViewManager(),
new ReactRawTextManager());
uiManager =
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), false, 0);
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), 0);
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -49,7 +49,6 @@ protected void setUp() throws Exception {
getContext(),
viewManagers,
new UIImplementationProvider(),
false,
0);
UiThreadUtil.runOnUiThread(
new Runnable() {
@@ -69,7 +69,7 @@ protected void setUp() throws Exception {
new ReactViewManager(),
new ReactProgressBarViewManager());
mUIManager =
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), false, 0);
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), 0);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -50,7 +50,7 @@ protected void setUp() throws Exception {
List<ViewManager> viewManagers = Arrays.<ViewManager>asList(new ReactViewManager());
final UIManagerModule uiManager =
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), false, 0);
new UIManagerModule(getContext(), viewManagers, new UIImplementationProvider(), 0);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -9,23 +9,25 @@
package com.facebook.react;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import javax.annotation.Nullable;
/**
* {@code CompositeReactPackage} allows to create a single package composed of views and modules
* from several other packages.
*/
public class CompositeReactPackage extends ReactInstancePackage {
public class CompositeReactPackage extends ReactInstancePackage
implements ViewManagerOnDemandReactPackage {
private final List<ReactPackage> mChildReactPackages = new ArrayList<>();
@@ -39,9 +41,7 @@ public CompositeReactPackage(ReactPackage arg1, ReactPackage arg2, ReactPackage.
mChildReactPackages.add(arg1);
mChildReactPackages.add(arg2);
for (ReactPackage reactPackage: args) {
mChildReactPackages.add(reactPackage);
}
Collections.addAll(mChildReactPackages, args);
}
/**
@@ -56,7 +56,7 @@ public CompositeReactPackage(ReactPackage arg1, ReactPackage arg2, ReactPackage.
moduleMap.put(nativeModule.getName(), nativeModule);
}
}
return new ArrayList(moduleMap.values());
return new ArrayList<>(moduleMap.values());
}
/**
@@ -81,7 +81,7 @@ public CompositeReactPackage(ReactPackage arg1, ReactPackage arg2, ReactPackage.
moduleMap.put(nativeModule.getName(), nativeModule);
}
}
return new ArrayList(moduleMap.values());
return new ArrayList<>(moduleMap.values());
}
/**
@@ -95,6 +95,44 @@ public CompositeReactPackage(ReactPackage arg1, ReactPackage arg2, ReactPackage.
viewManagerMap.put(viewManager.getName(), viewManager);
}
}
return new ArrayList(viewManagerMap.values());
return new ArrayList<>(viewManagerMap.values());
}
/**
* {@inheritDoc}
*/
@Override
public List<String> getViewManagerNames(ReactApplicationContext reactContext) {
Set<String> uniqueNames = new HashSet<>();
for (ReactPackage reactPackage : mChildReactPackages) {
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
List<String> names =
((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(reactContext);
if (names != null) {
uniqueNames.addAll(names);
}
}
}
return new ArrayList<>(uniqueNames);
}
/**
* {@inheritDoc}
*/
@Override
public @Nullable ViewManager createViewManager(
ReactApplicationContext reactContext, String viewManagerName) {
ListIterator<ReactPackage> iterator = mChildReactPackages.listIterator(mChildReactPackages.size());
while (iterator.hasPrevious()) {
ReactPackage reactPackage = iterator.previous();
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
ViewManager viewManager =
((ViewManagerOnDemandReactPackage) reactPackage).createViewManager(reactContext, viewManagerName);
if (viewManager != null) {
return viewManager;
}
}
}
return null;
}
}
@@ -38,6 +38,7 @@
import com.facebook.systrace.Systrace;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import javax.inject.Provider;
/**
* This module should be removed following the completion of an experiment into splitting this into
@@ -183,18 +184,34 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
return LazyReactPackage.getReactModuleInfoProviderViaReflection(this);
}
private UIManagerModule createUIManager(ReactApplicationContext reactContext) {
private UIManagerModule createUIManager(final ReactApplicationContext reactContext) {
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_START);
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule");
try {
List<ViewManager> viewManagersList = mReactInstanceManager.createAllViewManagers(
reactContext);
return new UIManagerModule(
reactContext,
viewManagersList,
mUIImplementationProvider,
mLazyViewManagersEnabled,
mMinTimeLeftInFrameForNonBatchedOperationMs);
if (mLazyViewManagersEnabled) {
UIManagerModule.ViewManagerResolver resolver = new UIManagerModule.ViewManagerResolver() {
@Override
public @Nullable ViewManager getViewManager(String viewManagerName) {
return mReactInstanceManager.createViewManager(viewManagerName);
}
@Override
public List<String> getViewManagerNames() {
return mReactInstanceManager.getViewManagerNames();
}
};
return new UIManagerModule(
reactContext,
resolver,
mUIImplementationProvider,
mMinTimeLeftInFrameForNonBatchedOperationMs);
} else {
return new UIManagerModule(
reactContext,
mReactInstanceManager.createAllViewManagers(reactContext),
mUIImplementationProvider,
mMinTimeLeftInFrameForNonBatchedOperationMs);
}
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);
Oops, something went wrong.

0 comments on commit da30b04

Please sign in to comment.