Adding simple View rendering support using FabricUIManager.
Reviewed By: achen1 Differential Revision: D7102725 fbshipit-source-id: d2878d036843ba01201c4df617680269b5f59039
This commit is contained in:
parent
b5b0ee853e
commit
c0c388c8aa
|
@ -3,15 +3,19 @@
|
||||||
package com.facebook.react.fabric;
|
package com.facebook.react.fabric;
|
||||||
|
|
||||||
import com.facebook.infer.annotation.Assertions;
|
import com.facebook.infer.annotation.Assertions;
|
||||||
|
import com.facebook.react.bridge.JavaOnlyArray;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
import com.facebook.react.bridge.ReadableNativeMap;
|
import com.facebook.react.bridge.ReadableNativeMap;
|
||||||
import com.facebook.react.bridge.UIManager;
|
import com.facebook.react.bridge.UIManager;
|
||||||
import com.facebook.react.modules.i18nmanager.I18nUtil;
|
import com.facebook.react.modules.i18nmanager.I18nUtil;
|
||||||
|
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
||||||
import com.facebook.react.uimanager.ReactRootViewTagGenerator;
|
import com.facebook.react.uimanager.ReactRootViewTagGenerator;
|
||||||
import com.facebook.react.uimanager.ReactShadowNode;
|
import com.facebook.react.uimanager.ReactShadowNode;
|
||||||
import com.facebook.react.uimanager.ReactShadowNodeImpl;
|
import com.facebook.react.uimanager.ReactShadowNodeImpl;
|
||||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||||
import com.facebook.react.uimanager.ThemedReactContext;
|
import com.facebook.react.uimanager.ThemedReactContext;
|
||||||
|
import com.facebook.react.uimanager.UIViewOperationQueue;
|
||||||
import com.facebook.react.uimanager.ViewManager;
|
import com.facebook.react.uimanager.ViewManager;
|
||||||
import com.facebook.react.uimanager.ViewManagerRegistry;
|
import com.facebook.react.uimanager.ViewManagerRegistry;
|
||||||
import com.facebook.react.uimanager.common.MeasureSpecProvider;
|
import com.facebook.react.uimanager.common.MeasureSpecProvider;
|
||||||
|
@ -19,6 +23,7 @@ import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.Nullable;
|
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.
|
||||||
|
@ -26,14 +31,17 @@ import javax.annotation.Nullable;
|
||||||
@SuppressWarnings("unused") // used from JNI
|
@SuppressWarnings("unused") // used from JNI
|
||||||
public class FabricUIManagerModule implements UIManager {
|
public class FabricUIManagerModule implements UIManager {
|
||||||
|
|
||||||
|
private static final String TAG = FabricUIManagerModule.class.toString();
|
||||||
private final RootShadowNodeRegistry mRootShadowNodeRegistry = new RootShadowNodeRegistry();
|
private final RootShadowNodeRegistry mRootShadowNodeRegistry = new RootShadowNodeRegistry();
|
||||||
private final ReactApplicationContext mReactApplicationContext;
|
private final ReactApplicationContext mReactApplicationContext;
|
||||||
private final ViewManagerRegistry mViewManagerRegistry;
|
private final ViewManagerRegistry mViewManagerRegistry;
|
||||||
|
private final UIViewOperationQueue mUIViewOperationQueue;
|
||||||
|
|
||||||
public FabricUIManagerModule(ReactApplicationContext reactContext,
|
public FabricUIManagerModule(ReactApplicationContext reactContext,
|
||||||
ViewManagerRegistry viewManagerRegistry) {
|
ViewManagerRegistry viewManagerRegistry) {
|
||||||
mReactApplicationContext = reactContext;
|
mReactApplicationContext = reactContext;
|
||||||
mViewManagerRegistry = viewManagerRegistry;
|
mViewManagerRegistry = viewManagerRegistry;
|
||||||
|
mUIViewOperationQueue = new UIViewOperationQueue(reactContext, new NativeViewHierarchyManager(viewManagerRegistry), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,16 +49,21 @@ public class FabricUIManagerModule implements UIManager {
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public ReactShadowNode createNode(int reactTag,
|
public ReactShadowNode createNode(int reactTag,
|
||||||
String viewName,
|
String viewName,
|
||||||
int rootTag,
|
int rootTag,
|
||||||
ReadableNativeMap props) {
|
ReadableNativeMap props) {
|
||||||
|
|
||||||
ViewManager viewManager = mViewManagerRegistry.get(viewName);
|
ViewManager viewManager = mViewManagerRegistry.get(viewName);
|
||||||
ReactShadowNode node = viewManager.createShadowNodeInstance(mReactApplicationContext);
|
ReactShadowNode node = viewManager.createShadowNodeInstance(mReactApplicationContext);
|
||||||
node.setRootNode(getRootNode(rootTag));
|
ReactShadowNode rootNode = getRootNode(rootTag);
|
||||||
|
node.setRootNode(rootNode);
|
||||||
node.setReactTag(reactTag);
|
node.setReactTag(reactTag);
|
||||||
|
node.setThemedContext(rootNode.getThemedContext());
|
||||||
|
|
||||||
ReactStylesDiffMap styles = updateProps(node, props);
|
ReactStylesDiffMap styles = updateProps(node, props);
|
||||||
|
|
||||||
|
mUIViewOperationQueue
|
||||||
|
.enqueueCreateView(rootNode.getThemedContext(), reactTag, viewName, styles);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +148,7 @@ public class FabricUIManagerModule implements UIManager {
|
||||||
@Nullable
|
@Nullable
|
||||||
public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
|
public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
|
||||||
parent.addChildAt(child, parent.getChildCount());
|
parent.addChildAt(child, parent.getChildCount());
|
||||||
|
setChildren(parent.getReactTag(), child.getReactTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,8 +167,60 @@ public class FabricUIManagerModule implements UIManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void completeRoot(int rootTag, List<ReactShadowNode> childList) {
|
public void completeRoot(int rootTag, List<ReactShadowNode> childList) {
|
||||||
// TODO Diffing old Tree with new Tree
|
if (!childList.isEmpty()) {
|
||||||
// Do we need to hold references to old and new tree?
|
ReactShadowNode rootNode = getRootNode(rootTag);
|
||||||
|
for (int i = 0; i < childList.size(); i++) {
|
||||||
|
ReactShadowNode child = childList.get(i);
|
||||||
|
rootNode.addChildAt(child, i);
|
||||||
|
setChildren(rootTag, child.getReactTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateRootLayout(rootNode);
|
||||||
|
applyUpdatesRecursive(rootNode, 0, 0);
|
||||||
|
mUIViewOperationQueue.dispatchViewUpdates(1, System.currentTimeMillis(), System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChildren(int parent, int child) {
|
||||||
|
JavaOnlyArray childrenTags = new JavaOnlyArray();
|
||||||
|
childrenTags.pushInt(child);
|
||||||
|
mUIViewOperationQueue.enqueueSetChildren(
|
||||||
|
parent,
|
||||||
|
childrenTags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateRootLayout(ReactShadowNode cssRoot) {
|
||||||
|
cssRoot.calculateLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyUpdatesRecursive(
|
||||||
|
ReactShadowNode cssNode,
|
||||||
|
float absoluteX,
|
||||||
|
float absoluteY) {
|
||||||
|
|
||||||
|
if (!cssNode.hasUpdates()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cssNode.isVirtualAnchor()) {
|
||||||
|
for (int i = 0; i < cssNode.getChildCount(); i++) {
|
||||||
|
applyUpdatesRecursive(
|
||||||
|
cssNode.getChildAt(i),
|
||||||
|
absoluteX + cssNode.getLayoutX(),
|
||||||
|
absoluteY + cssNode.getLayoutY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int tag = cssNode.getReactTag();
|
||||||
|
if (mRootShadowNodeRegistry.getNode(tag) == null) {
|
||||||
|
boolean frameDidChange = cssNode.dispatchUpdates(
|
||||||
|
absoluteX,
|
||||||
|
absoluteY,
|
||||||
|
mUIViewOperationQueue,
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
cssNode.markUpdateSeen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -162,10 +228,18 @@ public class FabricUIManagerModule implements UIManager {
|
||||||
final T rootView) {
|
final T rootView) {
|
||||||
int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
|
int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
|
||||||
ThemedReactContext themedRootContext = new ThemedReactContext(
|
ThemedReactContext themedRootContext = new ThemedReactContext(
|
||||||
mReactApplicationContext,
|
mReactApplicationContext,
|
||||||
rootView.getContext());
|
rootView.getContext());
|
||||||
|
|
||||||
mRootShadowNodeRegistry.addNode(createRootShadowNode(rootTag, themedRootContext));
|
ReactShadowNode rootShadowNode = createRootShadowNode(rootTag, themedRootContext);
|
||||||
|
|
||||||
|
int widthMeasureSpec = rootView.getWidthMeasureSpec();
|
||||||
|
int heightMeasureSpec = rootView.getHeightMeasureSpec();
|
||||||
|
rootShadowNode.setStyleWidthAuto();
|
||||||
|
rootShadowNode.setStyleHeightAuto();
|
||||||
|
|
||||||
|
mRootShadowNodeRegistry.addNode(rootShadowNode);
|
||||||
|
mUIViewOperationQueue.addRootView(rootTag, rootView, themedRootContext);
|
||||||
return rootTag;
|
return rootTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue