diff --git a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java index 43515b59f..ecda01613 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java @@ -170,7 +170,7 @@ import javax.inject.Provider; } else { return new UIManagerModule( reactContext, - mReactInstanceManager.createAllViewManagers(reactContext), + mReactInstanceManager.getOrCreateViewManagers(reactContext), mUIImplementationProvider, mMinTimeLeftInFrameForNonBatchedOperationMs); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 2ba53056f..4c2b56099 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -156,6 +156,7 @@ public class ReactInstanceManager { private final boolean mLazyNativeModulesEnabled; private final boolean mDelayViewManagerClassLoadsEnabled; private final @Nullable BridgeListener mBridgeListener; + private List mViewManagers; private class ReactContextInitParams { private final JavaScriptExecutorFactory mJsExecutorFactory; @@ -774,18 +775,23 @@ public class ReactInstanceManager { /** * Uses configured {@link ReactPackage} instances to create all view managers. */ - public List createAllViewManagers( + public List getOrCreateViewManagers( ReactApplicationContext catalystApplicationContext) { ReactMarker.logMarker(CREATE_VIEW_MANAGERS_START); Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers"); try { - synchronized (mPackages) { - List allViewManagers = new ArrayList<>(); - for (ReactPackage reactPackage : mPackages) { - allViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext)); + if (mViewManagers == null) { + synchronized (mPackages) { + if (mViewManagers == null) { + mViewManagers = new ArrayList<>(); + for (ReactPackage reactPackage : mPackages) { + mViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext)); + } + return mViewManagers; + } } - return allViewManagers; } + return mViewManagers; } finally { Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); ReactMarker.logMarker(CREATE_VIEW_MANAGERS_END); diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java index 0e52bcd36..10acfbc27 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerModule.java @@ -4,7 +4,15 @@ package com.facebook.react.fabric; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.MeasureSpecProvider; +import com.facebook.react.uimanager.NativeViewHierarchyOptimizer; +import com.facebook.react.uimanager.ReactRootViewTagGenerator; import com.facebook.react.uimanager.ReactShadowNode; +import com.facebook.react.uimanager.ReactStylesDiffMap; +import com.facebook.react.uimanager.SizeMonitoringFrameLayout; +import com.facebook.react.uimanager.UIModule; +import com.facebook.react.uimanager.ViewManager; +import com.facebook.react.uimanager.ViewManagerRegistry; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; @@ -13,12 +21,16 @@ import javax.annotation.Nullable; * This class is responsible to create, clone and update {@link ReactShadowNode} using the * Fabric API. */ -public class FabricUIManagerModule { +@SuppressWarnings("unused") // used from JNI +public class FabricUIManagerModule implements UIModule { private final ReactApplicationContext mReactApplicationContext; + private final ViewManagerRegistry mViewManagerRegistry; - public FabricUIManagerModule(ReactApplicationContext reactContext) { + public FabricUIManagerModule(ReactApplicationContext reactContext, + ViewManagerRegistry viewManagerRegistry) { mReactApplicationContext = reactContext; + mViewManagerRegistry = viewManagerRegistry; } /** @@ -28,10 +40,24 @@ public class FabricUIManagerModule { public ReactShadowNode createNode(int reactTag, String viewName, int rootTag, - ReadableMap props, - int instanceHandle) { - //TODO T25560658 - return null; + ReadableMap props) { + + ViewManager viewManager = mViewManagerRegistry.get(viewName); + ReactShadowNode shadowNode = viewManager.createShadowNodeInstance(mReactApplicationContext); + shadowNode.setRootTag(rootTag); + shadowNode.setReactTag(reactTag); + ReactStylesDiffMap styles = updateProps(props, shadowNode); + + return shadowNode; + } + + private ReactStylesDiffMap updateProps(ReadableMap props, ReactShadowNode shadowNode) { + ReactStylesDiffMap styles = null; + if (props != null) { + styles = new ReactStylesDiffMap(props); + shadowNode.updateProperties(styles); + } + return styles; } /** @@ -41,8 +67,7 @@ public class FabricUIManagerModule { */ @Nullable public ReactShadowNode cloneNode(ReactShadowNode node) { - //TODO T25560658 - return null; + return node.mutableCopy(); } /** @@ -52,8 +77,9 @@ public class FabricUIManagerModule { */ @Nullable public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node) { - //TODO T25560658 - return null; + ReactShadowNode clone = cloneNode(node); + clone.removeAllChildren(); + return clone; } /** @@ -63,8 +89,9 @@ public class FabricUIManagerModule { */ @Nullable public ReactShadowNode cloneNodeWithNewProps(ReactShadowNode node, ReadableMap newProps) { - //TODO T25560658 - return null; + ReactShadowNode clone = cloneNode(node); + updateProps(newProps, clone); + return clone; } /** @@ -77,8 +104,9 @@ public class FabricUIManagerModule { public ReactShadowNode cloneNodeWithNewChildrenAndProps( ReactShadowNode node, ReadableMap newProps) { - //TODO T25560658 - return null; + ReactShadowNode clone = cloneNodeWithNewChildren(node); + updateProps(newProps, clone); + return clone; } /** @@ -87,7 +115,7 @@ public class FabricUIManagerModule { */ @Nullable public void appendChild(ReactShadowNode parent, ReactShadowNode child) { - //TODO T25560658 + parent.addChildAt(child, parent.getChildCount()); } /** @@ -106,7 +134,15 @@ public class FabricUIManagerModule { } public void completeRoot(int rootTag, List childList) { - //TODO T25560658 + // TODO Diffing old Tree with new Tree? + // Do we need to hold references to old and new tree? + } + + @Override + public int addRootView( + final T rootView) { + // TODO: complete with actual implementation + return ReactRootViewTagGenerator.getNextRootViewTag(); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java index 98e4a592c..7c59caafb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java @@ -277,6 +277,7 @@ public class UIImplementation { cssNode.setReactTag(tag); cssNode.setViewClassName(className); cssNode.setRootNode(rootNode); + if (rootNode != null) cssNode.setRootTag(rootNode.getReactTag()); cssNode.setThemedContext(rootNode.getThemedContext()); mShadowNodeRegistry.addNode(cssNode); diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index 6a8d6db53..d4ceecfb6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -72,7 +72,7 @@ import javax.annotation.Nullable; */ @ReactModule(name = UIManagerModule.NAME) public class UIManagerModule extends ReactContextBaseJavaModule implements - OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter { + OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter, UIModule { /** * Enables lazy discovery of a specific {@link ViewManager} by its name. @@ -287,6 +287,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements * *

TODO(6242243): Make addRootView thread safe NB: this method is horribly not-thread-safe. */ + @Override public int addRootView( final T rootView) { Systrace.beginSection( diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIModule.java new file mode 100644 index 000000000..a3fee6652 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIModule.java @@ -0,0 +1,7 @@ +package com.facebook.react.uimanager; + +public interface UIModule { + + int addRootView(final T rootView); + +}