Introduce DeviceInfo as a new native module

Summary:
The `UIManager` already has a lot of responsibilities and is deeply
tied with React Native's view architecture. This diff separates out a
`DeviceInfo` native module to provide information about screen dimensions and
font scale, etc.

Reviewed By: fkgozali

Differential Revision: D4713834

fbshipit-source-id: f2ee93acf876a4221c29a8c731f5abeffbb97974
This commit is contained in:
Ashwin Bharambe
2017-03-17 16:47:51 -07:00
committed by Facebook Github Bot
parent 238fd4ad19
commit 95c1926193
25 changed files with 345 additions and 125 deletions

View File

@@ -87,7 +87,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
private final Map<String, Object> mModuleConstants;
private final UIImplementation mUIImplementation;
private final MemoryTrimCallback mMemoryTrimCallback = new MemoryTrimCallback();
private float mFontScale;
private int mNextRootViewTag = 1;
private int mBatchId = 0;
@@ -100,8 +99,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
super(reactContext);
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mEventDispatcher = new EventDispatcher(reactContext);
mFontScale = getReactApplicationContext().getResources().getConfiguration().fontScale;
mModuleConstants = createConstants(viewManagerList, lazyViewManagersEnabled, mFontScale);
mModuleConstants = createConstants(viewManagerList, lazyViewManagersEnabled);
mUIImplementation = uiImplementationProvider
.createUIImplementation(reactContext, viewManagerList, mEventDispatcher);
@@ -134,12 +132,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
@Override
public void onHostResume() {
mUIImplementation.onHostResume();
float fontScale = getReactApplicationContext().getResources().getConfiguration().fontScale;
if (mFontScale != fontScale) {
mFontScale = fontScale;
emitUpdateDimensionsEvent();
}
}
@Override
@@ -163,15 +155,13 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
private static Map<String, Object> createConstants(
List<ViewManager> viewManagerList,
boolean lazyViewManagersEnabled,
float fontScale) {
boolean lazyViewManagersEnabled) {
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_START);
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
try {
return UIManagerModuleConstantsHelper.createConstants(
viewManagerList,
lazyViewManagersEnabled,
fontScale);
lazyViewManagersEnabled);
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_END);
@@ -550,16 +540,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
mUIImplementation.sendAccessibilityEvent(tag, eventType);
}
public void emitUpdateDimensionsEvent() {
sendEvent("didUpdateDimensions", UIManagerModuleConstants.getDimensionsConstants(mFontScale));
}
private void sendEvent(String eventName, @Nullable WritableMap params) {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
/**
* Schedule a block to be executed on the UI thread. Useful if you need to execute
* view logic after all currently queued view updates have completed.