Permalink
Browse files

Fix Nodes not having correct view managers externally

Reviewed By: ahmedre

Differential Revision: D4927963

fbshipit-source-id: f4993aa45f6313e814d03141f828d37eafade059
  • Loading branch information...
sjkirby authored and facebook-github-bot committed Apr 27, 2017
1 parent 6272ef8 commit c8bb42288292e9c08ed208aae4a700fb4d05c464
@@ -9,26 +9,26 @@
package com.facebook.react.flat;
import com.facebook.yoga.YogaMeasureMode;
import com.facebook.yoga.YogaMeasureFunction;
import com.facebook.yoga.YogaNode;
import com.facebook.react.uimanager.BaseViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.views.art.ARTSurfaceView;
import com.facebook.yoga.YogaMeasureFunction;
import com.facebook.yoga.YogaMeasureMode;
import com.facebook.yoga.YogaNode;
public class FlatARTSurfaceViewManager extends
BaseViewManager<ARTSurfaceView, FlatARTSurfaceViewShadowNode> {
BaseViewManager<ARTSurfaceView, FlatARTSurfaceViewShadowNode> {
private static final String REACT_CLASS = "ARTSurfaceView";
/* package */ static final String REACT_CLASS = "ARTSurfaceView";
private static final YogaMeasureFunction MEASURE_FUNCTION = new YogaMeasureFunction() {
@Override
public long measure(
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
throw new IllegalStateException("SurfaceView should have explicit width and height set");
}
};
@@ -9,11 +9,6 @@
package com.facebook.react.flat;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
@@ -28,22 +23,79 @@
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.yoga.YogaDirection;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* FlatUIImplementation builds on top of UIImplementation and allows pre-creating everything
* required for drawing (DrawCommands) and touching (NodeRegions) views in background thread
* for faster drawing and interactions.
*/
public class FlatUIImplementation extends UIImplementation {
private static final Map<String, Class<? extends ViewManager>> flatManagerClassMap;
static {
flatManagerClassMap = new HashMap<>();
flatManagerClassMap.put(RCTViewManager.REACT_CLASS, RCTViewManager.class);
flatManagerClassMap.put(RCTTextManager.REACT_CLASS, RCTTextManager.class);
flatManagerClassMap.put(RCTRawTextManager.REACT_CLASS, RCTRawTextManager.class);
flatManagerClassMap.put(RCTVirtualTextManager.REACT_CLASS, RCTVirtualTextManager.class);
flatManagerClassMap.put(RCTTextInlineImageManager.REACT_CLASS, RCTTextInlineImageManager.class);
flatManagerClassMap.put(RCTImageViewManager.REACT_CLASS, RCTImageViewManager.class);
flatManagerClassMap.put(RCTTextInputManager.REACT_CLASS, RCTTextInputManager.class);
flatManagerClassMap.put(RCTViewPagerManager.REACT_CLASS, RCTViewPagerManager.class);
flatManagerClassMap.put(FlatARTSurfaceViewManager.REACT_CLASS, FlatARTSurfaceViewManager.class);
flatManagerClassMap.put(RCTModalHostManager.REACT_CLASS, RCTModalHostManager.class);
}
/**
* Build the map of view managers, checking that the managers FlatUI requires are correctly
* overriden.
*/
private static Map<String, ViewManager> buildViewManagerMap(List<ViewManager> viewManagers) {
Map<String, ViewManager> viewManagerMap = new HashMap<>();
for (ViewManager viewManager : viewManagers) {
viewManagerMap.put(viewManager.getName(), viewManager);
}
for (Map.Entry<String, Class<? extends ViewManager>> entry : flatManagerClassMap.entrySet()) {
String name = entry.getKey();
ViewManager maybeFlatViewManager = viewManagerMap.get(name);
if (maybeFlatViewManager == null) {
// We don't have a view manager for this name in the package, no need to add one.
continue;
}
Class<? extends ViewManager> flatClazz = entry.getValue();
if (maybeFlatViewManager.getClass() != flatClazz) {
// If we have instances that have flat equivalents, override them.
try {
viewManagerMap.put(name, flatClazz.newInstance());
} catch (IllegalAccessException e) {
throw new RuntimeException("Unable to access flat class for " + name, e);
} catch (InstantiationException e) {
throw new RuntimeException("Unable to instantiate flat class for " + name, e);
}
}
}
return viewManagerMap;
}
public static FlatUIImplementation createInstance(
ReactApplicationContext reactContext,
List<ViewManager> viewManagers,
EventDispatcher eventDispatcher,
boolean memoryImprovementEnabled) {
RCTImageViewManager rctImageViewManager = findRCTImageManager(viewManagers);
if (rctImageViewManager != null) {
Object callerContext = rctImageViewManager.getCallerContext();
Map<String, ViewManager> viewManagerMap = buildViewManagerMap(viewManagers);
RCTImageViewManager imageViewManager =
(RCTImageViewManager) viewManagerMap.get(RCTImageViewManager.REACT_CLASS);
if (imageViewManager != null) {
Object callerContext = imageViewManager.getCallerContext();
if (callerContext != null) {
RCTImageView.setCallerContext(callerContext);
}
@@ -52,15 +104,15 @@ public static FlatUIImplementation createInstance(
TypefaceCache.setAssetManager(reactContext.getAssets());
ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagers);
ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagerMap);
FlatNativeViewHierarchyManager nativeViewHierarchyManager = new FlatNativeViewHierarchyManager(
viewManagerRegistry);
viewManagerRegistry);
FlatUIViewOperationQueue operationsQueue = new FlatUIViewOperationQueue(
reactContext,
nativeViewHierarchyManager);
reactContext,
nativeViewHierarchyManager);
return new FlatUIImplementation(
reactContext,
rctImageViewManager,
imageViewManager,
viewManagerRegistry,
operationsQueue,
eventDispatcher,
@@ -126,9 +178,9 @@ protected ReactShadowNode createShadowNode(String className) {
@Override
protected void handleCreateView(
ReactShadowNode cssNode,
int rootViewTag,
@Nullable ReactStylesDiffMap styles) {
ReactShadowNode cssNode,
int rootViewTag,
@Nullable ReactStylesDiffMap styles) {
if (cssNode instanceof FlatShadowNode) {
FlatShadowNode node = (FlatShadowNode) cssNode;
@@ -146,9 +198,9 @@ protected void handleCreateView(
@Override
protected void handleUpdateView(
ReactShadowNode cssNode,
String className,
ReactStylesDiffMap styles) {
ReactShadowNode cssNode,
String className,
ReactStylesDiffMap styles) {
if (cssNode instanceof FlatShadowNode) {
FlatShadowNode node = (FlatShadowNode) cssNode;
@@ -164,12 +216,12 @@ protected void handleUpdateView(
@Override
public void manageChildren(
int viewTag,
@Nullable ReadableArray moveFrom,
@Nullable ReadableArray moveTo,
@Nullable ReadableArray addChildTags,
@Nullable ReadableArray addAtIndices,
@Nullable ReadableArray removeFrom) {
int viewTag,
@Nullable ReadableArray moveFrom,
@Nullable ReadableArray moveTo,
@Nullable ReadableArray addChildTags,
@Nullable ReadableArray addAtIndices,
@Nullable ReadableArray removeFrom) {
ReactShadowNode parentNode = resolveShadowNode(viewTag);
@@ -182,8 +234,8 @@ public void manageChildren(
@Override
public void setChildren(
int viewTag,
ReadableArray children) {
int viewTag,
ReadableArray children) {
ReactShadowNode parentNode = resolveShadowNode(viewTag);
@@ -244,13 +296,13 @@ private void measureHelper(int reactTag, boolean relativeToWindow, Callback call
FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue();
operationsQueue.enqueueMeasureVirtualView(
node.getReactTag(),
xInParent / parentWidth,
yInParent / parentHeight,
width / parentWidth,
height / parentHeight,
relativeToWindow,
callback);
node.getReactTag(),
xInParent / parentWidth,
yInParent / parentHeight,
width / parentWidth,
height / parentHeight,
relativeToWindow,
callback);
}
private void ensureMountsToViewAndBackingViewIsCreated(int reactTag) {
@@ -304,10 +356,10 @@ public void sendAccessibilityEvent(int reactTag, int eventType) {
* preparing elements in moveFrom to be re-added at proper index.
*/
private void removeChildren(
ReactShadowNode parentNode,
@Nullable ReadableArray moveFrom,
@Nullable ReadableArray moveTo,
@Nullable ReadableArray removeFrom) {
ReactShadowNode parentNode,
@Nullable ReadableArray moveFrom,
@Nullable ReadableArray moveTo,
@Nullable ReadableArray removeFrom) {
int prevIndex = Integer.MAX_VALUE;
@@ -388,7 +440,7 @@ private void dropNativeViews(ReactShadowNode child, ReactShadowNode parentNode)
if (tmpNode instanceof FlatShadowNode) {
FlatShadowNode flatTmpNode = (FlatShadowNode) tmpNode;
if (flatTmpNode.mountsToView() && flatTmpNode.isBackingViewCreated() &&
flatTmpNode.getParent() != null) {
flatTmpNode.getParent() != null) {
tag = flatTmpNode.getReactTag();
break;
}
@@ -418,9 +470,9 @@ private void moveChild(ReactShadowNode child, int moveFromIndex) {
* Adds all children from addChildTags and moveFrom/moveTo.
*/
private void addChildren(
ReactShadowNode parentNode,
@Nullable ReadableArray addChildTags,
@Nullable ReadableArray addAtIndices) {
ReactShadowNode parentNode,
@Nullable ReadableArray addChildTags,
@Nullable ReadableArray addAtIndices) {
int prevIndex = -1;
@@ -485,12 +537,12 @@ private void addChildren(
* Removes a child from parent, verifying that we are removing in descending order.
*/
private static ReactShadowNode removeChildAt(
ReactShadowNode parentNode,
int index,
int prevIndex) {
ReactShadowNode parentNode,
int index,
int prevIndex) {
if (index >= prevIndex) {
throw new RuntimeException(
"Invariant failure, needs sorting! " + index + " >= " + prevIndex);
"Invariant failure, needs sorting! " + index + " >= " + prevIndex);
}
return parentNode.removeChildAt(index);
@@ -500,13 +552,13 @@ private static ReactShadowNode removeChildAt(
* Adds a child to parent, verifying that we are adding in ascending order.
*/
private static void addChildAt(
ReactShadowNode parentNode,
ReactShadowNode childNode,
int index,
int prevIndex) {
ReactShadowNode parentNode,
ReactShadowNode childNode,
int index,
int prevIndex) {
if (index <= prevIndex) {
throw new RuntimeException(
"Invariant failure, needs sorting! " + index + " <= " + prevIndex);
"Invariant failure, needs sorting! " + index + " <= " + prevIndex);
}
parentNode.addChildAt(childNode, index);
@@ -520,9 +572,9 @@ protected void updateViewHierarchy() {
@Override
protected void applyUpdatesRecursive(
ReactShadowNode cssNode,
float absoluteX,
float absoluteY) {
ReactShadowNode cssNode,
float absoluteX,
float absoluteY) {
mStateBuilder.applyUpdates((FlatRootShadowNode) cssNode);
}
@@ -551,18 +603,8 @@ public void setJSResponder(int possiblyVirtualReactTag, boolean blockNativeRespo
FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue();
operationsQueue.enqueueSetJSResponder(
node == null ? tag : node.getReactTag(),
possiblyVirtualReactTag,
blockNativeResponder);
}
private static @Nullable RCTImageViewManager findRCTImageManager(List<ViewManager> viewManagers) {
for (int i = 0, size = viewManagers.size(); i != size; ++i) {
if (viewManagers.get(i) instanceof RCTImageViewManager) {
return (RCTImageViewManager) viewManagers.get(i);
}
}
return null;
node == null ? tag : node.getReactTag(),
possiblyVirtualReactTag,
blockNativeResponder);
}
}
@@ -9,21 +9,22 @@
package com.facebook.react.flat;
import javax.annotation.Nullable;
import com.facebook.yoga.YogaMeasureFunction;
import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.ReactShadowNode;
import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIViewOperationQueue;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.yoga.YogaValue;
import com.facebook.yoga.YogaMeasureFunction;
import com.facebook.yoga.YogaUnit;
import com.facebook.yoga.YogaValue;
import javax.annotation.Nullable;
/* package */ final class NativeViewWrapper extends FlatShadowNode implements AndroidView {
@Nullable private final ReactShadowNode mReactShadowNode;
@Nullable
private final ReactShadowNode mReactShadowNode;
private final boolean mNeedsCustomLayoutForChildren;
private boolean mPaddingChanged = false;
private boolean mForceMountGrandChildrenToView;
@@ -9,13 +9,15 @@
package com.facebook.react.flat;
import javax.annotation.Nullable;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import javax.annotation.Nullable;
public final class RCTImageViewManager extends FlatViewManager {
/* package */ static final String REACT_CLASS = "RCTImageView";
private @Nullable AbstractDraweeControllerBuilder mDraweeControllerBuilder;
private final @Nullable Object mCallerContext;
@@ -32,7 +34,7 @@ public RCTImageViewManager(
@Override
public String getName() {
return "RCTImageView";
return REACT_CLASS;
}
@Override
Oops, something went wrong.

0 comments on commit c8bb422

Please sign in to comment.