Create UIManager interface and extract common classes in uimanager/common
Reviewed By: achen1 Differential Revision: D7102674 fbshipit-source-id: e14b6782ad102ec1c3d37988df4bbd4190511f09
This commit is contained in:
parent
b181b7797f
commit
6b45fb2cb1
|
@ -58,6 +58,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
|||
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 class ReactInstanceManager {
|
|||
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 @@ public class ReactInstanceManager {
|
|||
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 @@ public class ReactInstanceManager {
|
|||
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 @@ public class ReactInstanceManager {
|
|||
.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 @@ public class ReactInstanceManager {
|
|||
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.modules.deviceinfo.DeviceInfoModule;
|
|||
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 @@ public interface BridgeListener {
|
|||
* 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 @@ public interface CatalystInstance
|
|||
* synchronized(jsContext) { nativeThingNeedingJsContext(jsContext.get()); }
|
||||
*/
|
||||
JavaScriptContextHolder getJavaScriptContextHolder();
|
||||
|
||||
<T extends UIManager> void setFabricUIManager(T fabricUIManager);
|
||||
|
||||
<T extends UIManager> T getFabricUIManager();
|
||||
}
|
||||
|
|
|
@ -85,6 +85,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
private volatile boolean mAcceptCalls = false;
|
||||
|
||||
private boolean mJSBundleHasLoaded;
|
||||
private UIManager mFabricUIManager;
|
||||
private @Nullable String mSourceURL;
|
||||
|
||||
private JavaScriptContextHolder mJavaScriptContextHolder;
|
||||
|
@ -98,8 +99,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
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 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
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 class CatalystInstanceImpl implements CatalystInstance {
|
|||
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 class CatalystInstanceImpl implements CatalystInstance {
|
|||
private @Nullable NativeModuleRegistry mRegistry;
|
||||
private @Nullable JavaScriptExecutor mJSExecutor;
|
||||
private @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
|
||||
private @Nullable BridgeListener mBridgeListener;
|
||||
|
||||
|
||||
public Builder setReactQueueConfigurationSpec(
|
||||
|
@ -585,20 +589,13 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
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 @@ package com.facebook.react.fabric;
|
|||
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 @@ import javax.annotation.Nullable;
|
|||
* 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.View.MeasureSpec;
|
|||
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.ReadableMap;
|
|||
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.UiThreadUtil;
|
|||
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.ReactMarker;
|
|||
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 @@ import javax.annotation.Nullable;
|
|||
*/
|
||||
@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.
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package com.facebook.react.uimanager;
|
||||
|
||||
public interface UIModule {
|
||||
|
||||
<T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(final T rootView);
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ import com.facebook.react.bridge.SoftAssertions;
|
|||
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;
|
||||
|
Loading…
Reference in New Issue