Permalink
Browse files

Create UIManager interface and extract common classes in uimanager/co…

…mmon

Reviewed By: achen1

Differential Revision: D7102674

fbshipit-source-id: e14b6782ad102ec1c3d37988df4bbd4190511f09
  • Loading branch information...
mdvacca authored and facebook-github-bot committed Mar 1, 2018
1 parent b181b77 commit 6b45fb2cb1ca44fa7375bc7696bf90a68a85df3c
Showing with 69 additions and 71 deletions.
  1. +7 −39 ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java
  2. +2 −2 ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
  3. +1 −0 ReactAndroid/src/main/java/com/facebook/react/bridge/BUCK
  4. +1 −1 ReactAndroid/src/main/java/com/facebook/react/bridge/BridgeListener.java
  5. +4 −0 ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java
  6. +11 −14 ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java
  7. +13 −0 ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java
  8. +4 −4 ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java
  9. +1 −1 ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java
  10. +2 −0 ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK
  11. +1 −0 ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java
  12. +1 −0 ReactAndroid/src/main/java/com/facebook/react/uimanager/RootViewManager.java
  13. +2 −0 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java
  14. +4 −1 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java
  15. +0 −7 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIModule.java
  16. +1 −0 ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java
  17. +12 −0 ReactAndroid/src/main/java/com/facebook/react/uimanager/common/BUCK
  18. +1 −1 ReactAndroid/src/main/java/com/facebook/react/uimanager/{ → common}/MeasureSpecProvider.java
  19. +1 −1 ReactAndroid/src/main/java/com/facebook/react/uimanager/{ → common}/SizeMonitoringFrameLayout.java
@@ -58,6 +58,7 @@
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec;
import com.facebook.react.common.LifecycleState;
@@ -328,40 +329,6 @@ public void createReactContextInBackground() {
recreateReactContextInBackgroundInner();
}
@ThreadConfined(UI)
public void registerAdditionalPackages(List<ReactPackage> packages) {
if (packages == null || packages.isEmpty()) {
return;
}
// CatalystInstance hasn't been created, so add packages for later evaluation
if (!hasStartedCreatingInitialContext()) {
synchronized (mPackages) {
for (ReactPackage p : packages) {
if (!mPackages.contains(p)) {
mPackages.add(p);
}
}
}
return;
}
ReactContext context = getCurrentReactContext();
CatalystInstance catalystInstance = context != null ? context.getCatalystInstance() : null;
Assertions.assertNotNull(catalystInstance, "CatalystInstance null after hasStartedCreatingInitialContext true.");
final ReactApplicationContext reactContext = getReactApplicationContext();
NativeModuleRegistry nativeModuleRegistry = processPackages(reactContext, packages, true);
catalystInstance.extendNativeModules(nativeModuleRegistry);
}
@VisibleForTesting
public @Nullable ReactApplicationContext getReactApplicationContext() {
return new ReactApplicationContext(mApplicationContext);
}
/**
* Recreate the react application and context. This should be called if configuration has changed
* or the developer has requested the app to be reloaded. It should only be called after an
@@ -1040,8 +1007,7 @@ private void attachRootViewToInstance(
CatalystInstance catalystInstance) {
Log.d(ReactConstants.TAG, "ReactInstanceManager.attachRootViewToInstance()");
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachRootViewToInstance");
UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
final int rootTag = uiManagerModule.addRootView(rootView);
final int rootTag = catalystInstance.getNativeModule(UIManagerModule.class).addRootView(rootView);
rootView.setRootViewTag(rootTag);
rootView.invokeJSEntryPoint();
Systrace.beginAsyncSection(
@@ -1097,7 +1063,7 @@ private ReactApplicationContext createReactContext(
JSBundleLoader jsBundleLoader) {
Log.d(ReactConstants.TAG, "ReactInstanceManager.createReactContext()");
ReactMarker.logMarker(CREATE_REACT_CONTEXT_START);
final ReactApplicationContext reactContext = getReactApplicationContext();
final ReactApplicationContext reactContext = new ReactApplicationContext(mApplicationContext);
if (mUseDeveloperSupport) {
reactContext.setNativeModuleCallExceptionHandler(mDevSupportManager);
@@ -1113,8 +1079,7 @@ private ReactApplicationContext createReactContext(
.setJSExecutor(jsExecutor)
.setRegistry(nativeModuleRegistry)
.setJSBundleLoader(jsBundleLoader)
.setNativeModuleCallExceptionHandler(exceptionHandler)
.setBridgeListener(mBridgeListener);
.setNativeModuleCallExceptionHandler(exceptionHandler);
ReactMarker.logMarker(CREATE_CATALYST_INSTANCE_START);
// CREATE_CATALYST_INSTANCE_END is in JSCExecutor.cpp
@@ -1126,6 +1091,9 @@ private ReactApplicationContext createReactContext(
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_CATALYST_INSTANCE_END);
}
if (mBridgeListener != null) {
mBridgeListener.onBridgeStarted(reactContext, catalystInstance);
}
if (mBridgeIdleDebugListener != null) {
catalystInstance.addBridgeIdleDebugListener(mBridgeIdleDebugListener);
@@ -41,10 +41,10 @@
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.facebook.react.uimanager.JSTouchDispatcher;
import com.facebook.react.uimanager.MeasureSpecProvider;
import com.facebook.react.uimanager.common.MeasureSpecProvider;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.RootView;
import com.facebook.react.uimanager.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.systrace.Systrace;
@@ -27,5 +27,6 @@ rn_android_library(
react_native_target("java/com/facebook/debug/holder:holder"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/module/model:model"),
react_native_target("java/com/facebook/react/uimanager/common:common"),
] + ([react_native_target("jni/react/jni:jni")] if not IS_OSS_BUILD else []),
)
@@ -9,6 +9,6 @@
* Called right after the RN Bridge is initialized
* @param catalystInstance {@link CatalystInstance} bridge
*/
void onBridgeStarted(CatalystInstance catalystInstance);
void onBridgeStarted(ReactApplicationContext reactApplicationContext, CatalystInstance catalystInstance);
}
@@ -98,4 +98,8 @@ void callFunction(
* synchronized(jsContext) { nativeThingNeedingJsContext(jsContext.get()); }
*/
JavaScriptContextHolder getJavaScriptContextHolder();
<T extends UIManager> void setFabricUIManager(T fabricUIManager);
<T extends UIManager> T getFabricUIManager();
}
@@ -85,6 +85,7 @@ public String toString() {
private volatile boolean mAcceptCalls = false;
private boolean mJSBundleHasLoaded;
private UIManager mFabricUIManager;
private @Nullable String mSourceURL;
private JavaScriptContextHolder mJavaScriptContextHolder;
@@ -98,8 +99,7 @@ private CatalystInstanceImpl(
final JavaScriptExecutor jsExecutor,
final NativeModuleRegistry nativeModuleRegistry,
final JSBundleLoader jsBundleLoader,
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
final BridgeListener bridgeListener) {
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler) {
Log.d(ReactConstants.TAG, "Initializing React Xplat Bridge.");
mHybridData = initHybrid();
@@ -125,9 +125,6 @@ private CatalystInstanceImpl(
Log.d(ReactConstants.TAG, "Initializing React Xplat Bridge after initializeBridge");
mJavaScriptContextHolder = new JavaScriptContextHolder(getJavaScriptContext());
if (bridgeListener != null) {
bridgeListener.onBridgeStarted(this);
}
}
private static class BridgeCallback implements ReactCallback {
@@ -456,6 +453,14 @@ public JavaScriptContextHolder getJavaScriptContextHolder() {
return mJavaScriptContextHolder;
}
public UIManager getFabricUIManager() {
return mFabricUIManager;
}
public void setFabricUIManager(UIManager fabricUIManager) {
mFabricUIManager = fabricUIManager;
}
private native long getJavaScriptContext();
private void incrementPendingJSCalls() {
@@ -555,7 +560,6 @@ public void onTraceStopped() {
private @Nullable NativeModuleRegistry mRegistry;
private @Nullable JavaScriptExecutor mJSExecutor;
private @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
private @Nullable BridgeListener mBridgeListener;
public Builder setReactQueueConfigurationSpec(
@@ -585,20 +589,13 @@ public Builder setNativeModuleCallExceptionHandler(
return this;
}
public Builder setBridgeListener(
BridgeListener listener) {
mBridgeListener = listener;
return this;
}
public CatalystInstanceImpl build() {
return new CatalystInstanceImpl(
Assertions.assertNotNull(mReactQueueConfigurationSpec),
Assertions.assertNotNull(mJSExecutor),
Assertions.assertNotNull(mRegistry),
Assertions.assertNotNull(mJSBundleLoader),
Assertions.assertNotNull(mNativeModuleCallExceptionHandler),
mBridgeListener);
Assertions.assertNotNull(mNativeModuleCallExceptionHandler));
}
}
}
@@ -0,0 +1,13 @@
package com.facebook.react.bridge;
import com.facebook.react.uimanager.common.MeasureSpecProvider;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
public interface UIManager {
/**
* Registers a new root view.
*/
<T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(final T rootView);
}
@@ -5,17 +5,17 @@
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.modules.i18nmanager.I18nUtil;
import com.facebook.react.uimanager.MeasureSpecProvider;
import com.facebook.react.uimanager.ReactRootViewTagGenerator;
import com.facebook.react.uimanager.ReactShadowNode;
import com.facebook.react.uimanager.ReactShadowNodeImpl;
import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.uimanager.ViewManagerRegistry;
import com.facebook.react.uimanager.common.MeasureSpecProvider;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
@@ -24,7 +24,7 @@
* Fabric API.
*/
@SuppressWarnings("unused") // used from JNI
public class FabricUIManagerModule implements UIModule {
public class FabricUIManagerModule implements UIManager {
private final RootShadowNodeRegistry mRootShadowNodeRegistry = new RootShadowNodeRegistry();
private final ReactApplicationContext mReactApplicationContext;
@@ -19,7 +19,7 @@
import android.view.ViewGroup;
import com.facebook.react.uimanager.NativeViewHierarchyManager;
import com.facebook.react.uimanager.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.ViewManagerRegistry;
@@ -14,6 +14,7 @@ rn_android_library(
exported_deps = [
":DisplayMetrics",
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/uimanager/common:common"),
],
provided_deps = [
react_native_dep("third-party/android/support/v4:lib-support-v4"),
@@ -40,6 +41,7 @@ rn_android_library(
react_native_target("java/com/facebook/react/touch:touch"),
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
react_native_target("java/com/facebook/react/uimanager/util:util"),
react_native_target("java/com/facebook/react/uimanager/common:common"),
react_native_target("res:uimanager"),
],
)
@@ -29,6 +29,7 @@
import com.facebook.react.bridge.SoftAssertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.touch.JSResponderHandler;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.layoutanimation.LayoutAnimationController;
import com.facebook.react.uimanager.layoutanimation.LayoutAnimationListener;
import com.facebook.systrace.Systrace;
@@ -8,6 +8,7 @@
package com.facebook.react.uimanager;
import android.view.ViewGroup;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
/**
* View manager for ReactRootView components.
@@ -24,6 +24,8 @@
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.modules.i18nmanager.I18nUtil;
import com.facebook.react.uimanager.common.MeasureSpecProvider;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.systrace.Systrace;
@@ -28,10 +28,13 @@
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.common.MeasureSpecProvider;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.systrace.Systrace;
@@ -72,7 +75,7 @@
*/
@ReactModule(name = UIManagerModule.NAME)
public class UIManagerModule extends ReactContextBaseJavaModule implements
OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter, UIModule {
OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter, UIManager {
/**
* Enables lazy discovery of a specific {@link ViewManager} by its name.

This file was deleted.

Oops, something went wrong.
@@ -21,6 +21,7 @@
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
@@ -0,0 +1,12 @@
load("//ReactNative:DEFS.bzl", "rn_android_library", "react_native_dep", "react_native_target")
rn_android_library(
name = "common",
srcs = glob(["*.java"]),
visibility = [
"PUBLIC",
],
deps = [
react_native_dep("third-party/java/jsr-305:jsr-305"),
],
)
@@ -1,6 +1,6 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react.uimanager;
package com.facebook.react.uimanager.common;
import android.view.View;
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.uimanager;
package com.facebook.react.uimanager.common;
import javax.annotation.Nullable;

2 comments on commit 6b45fb2

@codyi96

This comment has been minimized.

codyi96 replied Mar 6, 2018

Why removed registerAdditionalPackages function. It's very useful as some package should added after js run to some condition

@xiayezhicheng

This comment has been minimized.

xiayezhicheng replied Oct 9, 2018

Why removed registerAdditionalPackages function? It's very useful as some package should added after js run to some condition,Are there any alternatives to registerAdditionalPackages ?

Please sign in to comment.