Permalink
Browse files

access view managers as Native Modules

Reviewed By: achen1

Differential Revision: D4338782

fbshipit-source-id: 1573e45ee3af5a44d033a166424e556b2c091fb6
  • Loading branch information...
AaaChiuuu authored and facebook-github-bot committed Jan 20, 2017
1 parent 577fd0c commit 5e9db574ee3aee6c44cbc270120e57d43e38cc74
Showing with 73 additions and 37 deletions.
  1. +5 −1 Libraries/ReactNative/UIManager.js
  2. +2 −1 ...droid/src/androidTest/java/com/facebook/react/tests/CatalystNativeJSToJavaParametersTestCase.java
  3. +2 −1 ...ndroid/src/androidTest/java/com/facebook/react/tests/CatalystNativeJavaToJSArgumentsTestCase.java
  4. +2 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystUIManagerTestCase.java
  5. +2 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/JSLocaleTest.java
  6. +2 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ProgressBarTestCase.java
  7. +2 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ViewRenderingTestCase.java
  8. +6 −2 ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java
  9. +5 −1 ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java
  10. +9 −4 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java
  11. +4 −1 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java
  12. +2 −1 ReactAndroid/src/test/java/com/facebook/react/uimanager/ReactPropConstantsTest.java
  13. +24 −18 ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleConstantsTest.java
  14. +2 −1 ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java
  15. +2 −1 ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextTest.java
  16. +2 −1 ReactAndroid/src/test/java/com/facebook/react/views/textinput/TextInputTest.java
@@ -101,7 +101,11 @@ if (Platform.OS === 'ios') {
}
});
} else if (Platform.OS === 'android' && UIManager.AndroidLazyViewManagersEnabled) {
// TODO fill this out
UIManager.ViewManagerNames.forEach(viewManagerName => {
defineLazyObjectProperty(UIManager, viewManagerName, {
get: () => NativeModules[viewManagerName.replace(/^(RCT|RK)/, '')],
});
});
}
module.exports = UIManager;
@@ -81,7 +81,8 @@ protected void setUp() throws Exception {
final UIManagerModule mUIManager = new UIManagerModule(
getContext(),
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -62,7 +62,8 @@ protected void setUp() throws Exception {
final UIManagerModule mUIManager = new UIManagerModule(
getContext(),
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -82,7 +82,8 @@ protected void setUp() throws Exception {
uiManager = new UIManagerModule(
getContext(),
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -46,7 +46,8 @@ protected void setUp() throws Exception {
final UIManagerModule mUIManager = new UIManagerModule(
getContext(),
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -72,7 +72,8 @@ protected void setUp() throws Exception {
mUIManager = new UIManagerModule(
getContext(),
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -53,7 +53,8 @@ protected void setUp() throws Exception {
final UIManagerModule uiManager = new UIManagerModule(
getContext(),
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
@@ -73,14 +73,17 @@
private final ReactInstanceManager mReactInstanceManager;
private final DefaultHardwareBackBtnHandler mHardwareBackBtnHandler;
private final UIImplementationProvider mUIImplementationProvider;
private final boolean mLazyViewManagersEnabled;
CoreModulesPackage(
ReactInstanceManager reactInstanceManager,
DefaultHardwareBackBtnHandler hardwareBackBtnHandler,
UIImplementationProvider uiImplementationProvider) {
UIImplementationProvider uiImplementationProvider,
boolean lazyViewManagersEnabled) {
mReactInstanceManager = reactInstanceManager;
mHardwareBackBtnHandler = hardwareBackBtnHandler;
mUIImplementationProvider = uiImplementationProvider;
mLazyViewManagersEnabled = lazyViewManagersEnabled;
}
@Override
@@ -208,7 +211,8 @@ private UIManagerModule createUIManager(ReactApplicationContext reactContext) {
return new UIManagerModule(
reactContext,
viewManagersList,
mUIImplementationProvider);
mUIImplementationProvider,
mLazyViewManagersEnabled);
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);
@@ -841,7 +841,11 @@ private ReactApplicationContext createReactContext(
"createAndProcessCoreModulesPackage");
try {
CoreModulesPackage coreModulesPackage =
new CoreModulesPackage(this, mBackBtnHandler, mUIImplementationProvider);
new CoreModulesPackage(
this,
mBackBtnHandler,
mUIImplementationProvider,
mLazyViewManagersEnabled);
processPackage(
coreModulesPackage,
reactContext,
@@ -89,11 +89,12 @@
public UIManagerModule(
ReactApplicationContext reactContext,
List<ViewManager> viewManagerList,
UIImplementationProvider uiImplementationProvider) {
UIImplementationProvider uiImplementationProvider,
boolean lazyViewManagersEnabled) {
super(reactContext);
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mEventDispatcher = new EventDispatcher(reactContext);
mModuleConstants = createConstants(viewManagerList);
mModuleConstants = createConstants(viewManagerList, lazyViewManagersEnabled);
mUIImplementation = uiImplementationProvider
.createUIImplementation(reactContext, viewManagerList, mEventDispatcher);
@@ -147,11 +148,15 @@ public void onCatalystInstanceDestroy() {
YogaNodePool.get().clear();
}
private static Map<String, Object> createConstants(List<ViewManager> viewManagerList) {
private static Map<String, Object> createConstants(
List<ViewManager> viewManagerList,
boolean lazyViewManagersEnabled) {
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_START);
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
try {
return UIManagerModuleConstantsHelper.createConstants(viewManagerList);
return UIManagerModuleConstantsHelper.createConstants(
viewManagerList,
lazyViewManagersEnabled);
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_END);
@@ -40,7 +40,9 @@
* {@link UIManagerModuleConstants}.
* TODO(6845124): Create a test for this
*/
/* package */ static Map<String, Object> createConstants(List<ViewManager> viewManagers) {
/* package */ static Map<String, Object> createConstants(
List<ViewManager> viewManagers,
boolean lazyViewManagersEnabled) {
Map<String, Object> constants = UIManagerModuleConstants.getConstants();
Map bubblingEventTypesConstants = UIManagerModuleConstants.getBubblingEventTypeConstants();
Map directEventTypesConstants = UIManagerModuleConstants.getDirectEventTypeConstants();
@@ -81,6 +83,7 @@
constants.put(CUSTOM_BUBBLING_EVENT_TYPES_KEY, bubblingEventTypesConstants);
constants.put(CUSTOM_DIRECT_EVENT_TYPES_KEY, directEventTypesConstants);
constants.put("AndroidLazyViewManagersEnabled", lazyViewManagersEnabled);
return constants;
}
@@ -148,7 +148,8 @@ public void testNativePropsIncludeCorrectTypes() {
UIManagerModule uiManagerModule = new UIManagerModule(
reactContext,
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
Map<String, String> constants =
(Map) valueAtPath(uiManagerModule.getConstants(), "SomeView", "NativeProps");
assertThat(constants).isEqualTo(
@@ -69,9 +69,10 @@ public void setUp() {
public void testNoCustomConstants() {
List<ViewManager> viewManagers = Arrays.asList(mock(ViewManager.class));
UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext,
viewManagers,
mUIImplementationProvider);
mReactContext,
viewManagers,
mUIImplementationProvider,
false);
Map<String, Object> constants = uiManagerModule.getConstants();
assertThat(constants)
.containsKey(CUSTOM_BUBBLING_EVENT_TYPES)
@@ -86,9 +87,10 @@ public void testCustomBubblingEvents() {
when(mockViewManager.getExportedCustomBubblingEventTypeConstants())
.thenReturn(MapBuilder.of("onTwirl", TWIRL_BUBBLING_EVENT_MAP));
UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext,
viewManagers,
mUIImplementationProvider);
mReactContext,
viewManagers,
mUIImplementationProvider,
false);
Map<String, Object> constants = uiManagerModule.getConstants();
assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
.contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
@@ -102,9 +104,10 @@ public void testCustomDirectEvents() {
when(mockViewManager.getExportedCustomDirectEventTypeConstants())
.thenReturn(MapBuilder.of("onTwirl", TWIRL_DIRECT_EVENT_MAP));
UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext,
viewManagers,
mUIImplementationProvider);
mReactContext,
viewManagers,
mUIImplementationProvider,
false);
Map<String, Object> constants = uiManagerModule.getConstants();
assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
.contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
@@ -119,9 +122,10 @@ public void testCustomViewConstants() {
when(mockViewManager.getExportedViewConstants())
.thenReturn(MapBuilder.of("PhotoSizeType", MapBuilder.of("Small", 1, "Large", 2)));
UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext,
viewManagers,
mUIImplementationProvider);
mReactContext,
viewManagers,
mUIImplementationProvider,
false);
Map<String, Object> constants = uiManagerModule.getConstants();
assertThat(constants).containsKey("RedPandaPhotoOfTheDayView");
assertThat((Map) constants.get("RedPandaPhotoOfTheDayView")).containsKey("Constants");
@@ -137,9 +141,10 @@ public void testNativeProps() {
when(mockViewManager.getNativeProps())
.thenReturn(MapBuilder.of("fooProp", "number"));
UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext,
viewManagers,
mUIImplementationProvider);
mReactContext,
viewManagers,
mUIImplementationProvider,
false);
Map<String, Object> constants = uiManagerModule.getConstants();
assertThat((String) valueAtPath(constants, "SomeView", "NativeProps", "fooProp"))
.isEqualTo("number");
@@ -171,9 +176,10 @@ public void testMergeConstants() {
List<ViewManager> viewManagers = Arrays.asList(managerX, managerY);
UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext,
viewManagers,
mUIImplementationProvider);
mReactContext,
viewManagers,
mUIImplementationProvider,
false);
Map<String, Object> constants = uiManagerModule.getConstants();
assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");
@@ -820,7 +820,8 @@ private UIManagerModule getUIManagerModule() {
UIManagerModule uiManagerModule = new UIManagerModule(
mReactContext,
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
uiManagerModule.onHostResume();
return uiManagerModule;
}
@@ -434,7 +434,8 @@ public UIManagerModule getUIManagerModule() {
UIManagerModule uiManagerModule = new UIManagerModule(
reactContext,
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
uiManagerModule.onHostResume();
return uiManagerModule;
}
@@ -186,7 +186,8 @@ public UIManagerModule getUIManagerModule() {
UIManagerModule uiManagerModule = new UIManagerModule(
reactContext,
viewManagers,
new UIImplementationProvider());
new UIImplementationProvider(),
false);
uiManagerModule.onHostResume();
return uiManagerModule;
}

0 comments on commit 5e9db57

Please sign in to comment.