access view managers as Native Modules
Reviewed By: achen1 Differential Revision: D4338782 fbshipit-source-id: 1573e45ee3af5a44d033a166424e556b2c091fb6
This commit is contained in:
parent
577fd0cbb9
commit
5e9db574ee
|
@ -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 @@ public class CatalystNativeJSToJavaParametersTestCase extends ReactIntegrationTe
|
|||
final UIManagerModule mUIManager = new UIManagerModule(
|
||||
getContext(),
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -62,7 +62,8 @@ public class CatalystNativeJavaToJSArgumentsTestCase extends ReactIntegrationTes
|
|||
final UIManagerModule mUIManager = new UIManagerModule(
|
||||
getContext(),
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -82,7 +82,8 @@ public class CatalystUIManagerTestCase extends ReactIntegrationTestCase {
|
|||
uiManager = new UIManagerModule(
|
||||
getContext(),
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
UiThreadUtil.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -46,7 +46,8 @@ public class JSLocaleTest extends ReactIntegrationTestCase {
|
|||
final UIManagerModule mUIManager = new UIManagerModule(
|
||||
getContext(),
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -72,7 +72,8 @@ public class ProgressBarTestCase extends ReactIntegrationTestCase {
|
|||
mUIManager = new UIManagerModule(
|
||||
getContext(),
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -53,7 +53,8 @@ public class ViewRenderingTestCase extends ReactIntegrationTestCase {
|
|||
final UIManagerModule uiManager = new UIManagerModule(
|
||||
getContext(),
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -73,14 +73,17 @@ import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_M
|
|||
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 @@ import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_M
|
|||
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 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
|||
"createAndProcessCoreModulesPackage");
|
||||
try {
|
||||
CoreModulesPackage coreModulesPackage =
|
||||
new CoreModulesPackage(this, mBackBtnHandler, mUIImplementationProvider);
|
||||
new CoreModulesPackage(
|
||||
this,
|
||||
mBackBtnHandler,
|
||||
mUIImplementationProvider,
|
||||
mLazyViewManagersEnabled);
|
||||
processPackage(
|
||||
coreModulesPackage,
|
||||
reactContext,
|
||||
|
|
|
@ -89,11 +89,12 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
|||
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 class UIManagerModule extends ReactContextBaseJavaModule implements
|
|||
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 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
|||
* {@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 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
|||
|
||||
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 class ReactPropConstantsTest {
|
|||
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 class UIManagerModuleConstantsTest {
|
|||
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 class UIManagerModuleConstantsTest {
|
|||
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 class UIManagerModuleConstantsTest {
|
|||
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 class UIManagerModuleConstantsTest {
|
|||
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 class UIManagerModuleConstantsTest {
|
|||
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 class UIManagerModuleConstantsTest {
|
|||
|
||||
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 @@ public class UIManagerModuleTest {
|
|||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
mReactContext,
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
|
|
@ -434,7 +434,8 @@ public class ReactTextTest {
|
|||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
reactContext,
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
|
|
@ -186,7 +186,8 @@ public class TextInputTest {
|
|||
UIManagerModule uiManagerModule = new UIManagerModule(
|
||||
reactContext,
|
||||
viewManagers,
|
||||
new UIImplementationProvider());
|
||||
new UIImplementationProvider(),
|
||||
false);
|
||||
uiManagerModule.onHostResume();
|
||||
return uiManagerModule;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue