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;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.ReadableNativeMap;
|
||||
import com.facebook.react.bridge.UIManager;
|
||||
import com.facebook.react.modules.i18nmanager.I18nUtil;
|
||||
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
||||
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.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.UIViewOperationQueue;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.react.uimanager.ViewManagerRegistry;
|
||||
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.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This class is responsible to create, clone and update {@link ReactShadowNode} using the
|
||||
* Fabric API.
|
||||
|
@ -26,14 +31,17 @@ import javax.annotation.Nullable;
|
|||
@SuppressWarnings("unused") // used from JNI
|
||||
public class FabricUIManagerModule implements UIManager {
|
||||
|
||||
private static final String TAG = FabricUIManagerModule.class.toString();
|
||||
private final RootShadowNodeRegistry mRootShadowNodeRegistry = new RootShadowNodeRegistry();
|
||||
private final ReactApplicationContext mReactApplicationContext;
|
||||
private final ViewManagerRegistry mViewManagerRegistry;
|
||||
private final UIViewOperationQueue mUIViewOperationQueue;
|
||||
|
||||
public FabricUIManagerModule(ReactApplicationContext reactContext,
|
||||
ViewManagerRegistry viewManagerRegistry) {
|
||||
mReactApplicationContext = reactContext;
|
||||
mViewManagerRegistry = viewManagerRegistry;
|
||||
mUIViewOperationQueue = new UIViewOperationQueue(reactContext, new NativeViewHierarchyManager(viewManagerRegistry), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,10 +55,15 @@ public class FabricUIManagerModule implements UIManager {
|
|||
|
||||
ViewManager viewManager = mViewManagerRegistry.get(viewName);
|
||||
ReactShadowNode node = viewManager.createShadowNodeInstance(mReactApplicationContext);
|
||||
node.setRootNode(getRootNode(rootTag));
|
||||
ReactShadowNode rootNode = getRootNode(rootTag);
|
||||
node.setRootNode(rootNode);
|
||||
node.setReactTag(reactTag);
|
||||
node.setThemedContext(rootNode.getThemedContext());
|
||||
|
||||
ReactStylesDiffMap styles = updateProps(node, props);
|
||||
|
||||
mUIViewOperationQueue
|
||||
.enqueueCreateView(rootNode.getThemedContext(), reactTag, viewName, styles);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -135,6 +148,7 @@ public class FabricUIManagerModule implements UIManager {
|
|||
@Nullable
|
||||
public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
|
||||
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) {
|
||||
// TODO Diffing old Tree with new Tree
|
||||
// Do we need to hold references to old and new tree?
|
||||
if (!childList.isEmpty()) {
|
||||
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
|
||||
|
@ -165,7 +231,15 @@ public class FabricUIManagerModule implements UIManager {
|
|||
mReactApplicationContext,
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue