Implement FabricUIManagerModule in Android

Reviewed By: achen1

Differential Revision: D7031902

fbshipit-source-id: a8d9d505f981ac4268760efa32f4cbc7955aec32
This commit is contained in:
David Vacca 2018-02-21 09:21:34 -08:00 committed by Facebook Github Bot
parent 47addd8e34
commit 4371d1e1d0
6 changed files with 75 additions and 24 deletions

View File

@ -170,7 +170,7 @@ import javax.inject.Provider;
} else { } else {
return new UIManagerModule( return new UIManagerModule(
reactContext, reactContext,
mReactInstanceManager.createAllViewManagers(reactContext), mReactInstanceManager.getOrCreateViewManagers(reactContext),
mUIImplementationProvider, mUIImplementationProvider,
mMinTimeLeftInFrameForNonBatchedOperationMs); mMinTimeLeftInFrameForNonBatchedOperationMs);
} }

View File

@ -156,6 +156,7 @@ public class ReactInstanceManager {
private final boolean mLazyNativeModulesEnabled; private final boolean mLazyNativeModulesEnabled;
private final boolean mDelayViewManagerClassLoadsEnabled; private final boolean mDelayViewManagerClassLoadsEnabled;
private final @Nullable BridgeListener mBridgeListener; private final @Nullable BridgeListener mBridgeListener;
private List<ViewManager> mViewManagers;
private class ReactContextInitParams { private class ReactContextInitParams {
private final JavaScriptExecutorFactory mJsExecutorFactory; private final JavaScriptExecutorFactory mJsExecutorFactory;
@ -774,18 +775,23 @@ public class ReactInstanceManager {
/** /**
* Uses configured {@link ReactPackage} instances to create all view managers. * Uses configured {@link ReactPackage} instances to create all view managers.
*/ */
public List<ViewManager> createAllViewManagers( public List<ViewManager> getOrCreateViewManagers(
ReactApplicationContext catalystApplicationContext) { ReactApplicationContext catalystApplicationContext) {
ReactMarker.logMarker(CREATE_VIEW_MANAGERS_START); ReactMarker.logMarker(CREATE_VIEW_MANAGERS_START);
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers"); Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers");
try { try {
synchronized (mPackages) { if (mViewManagers == null) {
List<ViewManager> allViewManagers = new ArrayList<>(); synchronized (mPackages) {
for (ReactPackage reactPackage : mPackages) { if (mViewManagers == null) {
allViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext)); mViewManagers = new ArrayList<>();
for (ReactPackage reactPackage : mPackages) {
mViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
}
return mViewManagers;
}
} }
return allViewManagers;
} }
return mViewManagers;
} finally { } finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(CREATE_VIEW_MANAGERS_END); ReactMarker.logMarker(CREATE_VIEW_MANAGERS_END);

View File

@ -4,7 +4,15 @@ package com.facebook.react.fabric;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap; 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.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.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nullable; 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 * This class is responsible to create, clone and update {@link ReactShadowNode} using the
* Fabric API. * Fabric API.
*/ */
public class FabricUIManagerModule { @SuppressWarnings("unused") // used from JNI
public class FabricUIManagerModule implements UIModule {
private final ReactApplicationContext mReactApplicationContext; private final ReactApplicationContext mReactApplicationContext;
private final ViewManagerRegistry mViewManagerRegistry;
public FabricUIManagerModule(ReactApplicationContext reactContext) { public FabricUIManagerModule(ReactApplicationContext reactContext,
ViewManagerRegistry viewManagerRegistry) {
mReactApplicationContext = reactContext; mReactApplicationContext = reactContext;
mViewManagerRegistry = viewManagerRegistry;
} }
/** /**
@ -28,10 +40,24 @@ public class FabricUIManagerModule {
public ReactShadowNode createNode(int reactTag, public ReactShadowNode createNode(int reactTag,
String viewName, String viewName,
int rootTag, int rootTag,
ReadableMap props, ReadableMap props) {
int instanceHandle) {
//TODO T25560658 ViewManager viewManager = mViewManagerRegistry.get(viewName);
return null; 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 @Nullable
public ReactShadowNode cloneNode(ReactShadowNode node) { public ReactShadowNode cloneNode(ReactShadowNode node) {
//TODO T25560658 return node.mutableCopy();
return null;
} }
/** /**
@ -52,8 +77,9 @@ public class FabricUIManagerModule {
*/ */
@Nullable @Nullable
public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node) { public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node) {
//TODO T25560658 ReactShadowNode clone = cloneNode(node);
return null; clone.removeAllChildren();
return clone;
} }
/** /**
@ -63,8 +89,9 @@ public class FabricUIManagerModule {
*/ */
@Nullable @Nullable
public ReactShadowNode cloneNodeWithNewProps(ReactShadowNode node, ReadableMap newProps) { public ReactShadowNode cloneNodeWithNewProps(ReactShadowNode node, ReadableMap newProps) {
//TODO T25560658 ReactShadowNode clone = cloneNode(node);
return null; updateProps(newProps, clone);
return clone;
} }
/** /**
@ -77,8 +104,9 @@ public class FabricUIManagerModule {
public ReactShadowNode cloneNodeWithNewChildrenAndProps( public ReactShadowNode cloneNodeWithNewChildrenAndProps(
ReactShadowNode node, ReactShadowNode node,
ReadableMap newProps) { ReadableMap newProps) {
//TODO T25560658 ReactShadowNode clone = cloneNodeWithNewChildren(node);
return null; updateProps(newProps, clone);
return clone;
} }
/** /**
@ -87,7 +115,7 @@ public class FabricUIManagerModule {
*/ */
@Nullable @Nullable
public void appendChild(ReactShadowNode parent, ReactShadowNode child) { 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<ReactShadowNode> childList) { public void completeRoot(int rootTag, List<ReactShadowNode> childList) {
//TODO T25560658 // TODO Diffing old Tree with new Tree?
// Do we need to hold references to old and new tree?
}
@Override
public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(
final T rootView) {
// TODO: complete with actual implementation
return ReactRootViewTagGenerator.getNextRootViewTag();
} }
} }

View File

@ -277,6 +277,7 @@ public class UIImplementation {
cssNode.setReactTag(tag); cssNode.setReactTag(tag);
cssNode.setViewClassName(className); cssNode.setViewClassName(className);
cssNode.setRootNode(rootNode); cssNode.setRootNode(rootNode);
if (rootNode != null) cssNode.setRootTag(rootNode.getReactTag());
cssNode.setThemedContext(rootNode.getThemedContext()); cssNode.setThemedContext(rootNode.getThemedContext());
mShadowNodeRegistry.addNode(cssNode); mShadowNodeRegistry.addNode(cssNode);

View File

@ -72,7 +72,7 @@ import javax.annotation.Nullable;
*/ */
@ReactModule(name = UIManagerModule.NAME) @ReactModule(name = UIManagerModule.NAME)
public class UIManagerModule extends ReactContextBaseJavaModule implements public class UIManagerModule extends ReactContextBaseJavaModule implements
OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter { OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter, UIModule {
/** /**
* Enables lazy discovery of a specific {@link ViewManager} by its name. * Enables lazy discovery of a specific {@link ViewManager} by its name.
@ -287,6 +287,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
* *
* <p>TODO(6242243): Make addRootView thread safe NB: this method is horribly not-thread-safe. * <p>TODO(6242243): Make addRootView thread safe NB: this method is horribly not-thread-safe.
*/ */
@Override
public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView( public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(
final T rootView) { final T rootView) {
Systrace.beginSection( Systrace.beginSection(

View File

@ -0,0 +1,7 @@
package com.facebook.react.uimanager;
public interface UIModule {
<T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(final T rootView);
}