Fix Nodes not having correct view managers externally

Reviewed By: ahmedre

Differential Revision: D4927963

fbshipit-source-id: f4993aa45f6313e814d03141f828d37eafade059
This commit is contained in:
Seth Kirby
2017-04-27 15:35:24 -07:00
committed by Facebook Github Bot
parent 6272ef87bc
commit c8bb422882
14 changed files with 207 additions and 143 deletions

View File

@@ -9,26 +9,26 @@
package com.facebook.react.flat; 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.BaseViewManager;
import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.views.art.ARTSurfaceView; 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 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() { private static final YogaMeasureFunction MEASURE_FUNCTION = new YogaMeasureFunction() {
@Override @Override
public long measure( public long measure(
YogaNode node, YogaNode node,
float width, float width,
YogaMeasureMode widthMode, YogaMeasureMode widthMode,
float height, float height,
YogaMeasureMode heightMode) { YogaMeasureMode heightMode) {
throw new IllegalStateException("SurfaceView should have explicit width and height set"); throw new IllegalStateException("SurfaceView should have explicit width and height set");
} }
}; };

View File

@@ -9,11 +9,6 @@
package com.facebook.react.flat; 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.infer.annotation.Assertions;
import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
@@ -28,6 +23,12 @@ import com.facebook.react.uimanager.ViewManagerRegistry;
import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.yoga.YogaDirection; 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 * FlatUIImplementation builds on top of UIImplementation and allows pre-creating everything
* required for drawing (DrawCommands) and touching (NodeRegions) views in background thread * required for drawing (DrawCommands) and touching (NodeRegions) views in background thread
@@ -35,15 +36,66 @@ import com.facebook.yoga.YogaDirection;
*/ */
public class FlatUIImplementation extends UIImplementation { 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( public static FlatUIImplementation createInstance(
ReactApplicationContext reactContext, ReactApplicationContext reactContext,
List<ViewManager> viewManagers, List<ViewManager> viewManagers,
EventDispatcher eventDispatcher, EventDispatcher eventDispatcher,
boolean memoryImprovementEnabled) { boolean memoryImprovementEnabled) {
RCTImageViewManager rctImageViewManager = findRCTImageManager(viewManagers); Map<String, ViewManager> viewManagerMap = buildViewManagerMap(viewManagers);
if (rctImageViewManager != null) {
Object callerContext = rctImageViewManager.getCallerContext(); RCTImageViewManager imageViewManager =
(RCTImageViewManager) viewManagerMap.get(RCTImageViewManager.REACT_CLASS);
if (imageViewManager != null) {
Object callerContext = imageViewManager.getCallerContext();
if (callerContext != null) { if (callerContext != null) {
RCTImageView.setCallerContext(callerContext); RCTImageView.setCallerContext(callerContext);
} }
@@ -52,15 +104,15 @@ public class FlatUIImplementation extends UIImplementation {
TypefaceCache.setAssetManager(reactContext.getAssets()); TypefaceCache.setAssetManager(reactContext.getAssets());
ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagers); ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagerMap);
FlatNativeViewHierarchyManager nativeViewHierarchyManager = new FlatNativeViewHierarchyManager( FlatNativeViewHierarchyManager nativeViewHierarchyManager = new FlatNativeViewHierarchyManager(
viewManagerRegistry); viewManagerRegistry);
FlatUIViewOperationQueue operationsQueue = new FlatUIViewOperationQueue( FlatUIViewOperationQueue operationsQueue = new FlatUIViewOperationQueue(
reactContext, reactContext,
nativeViewHierarchyManager); nativeViewHierarchyManager);
return new FlatUIImplementation( return new FlatUIImplementation(
reactContext, reactContext,
rctImageViewManager, imageViewManager,
viewManagerRegistry, viewManagerRegistry,
operationsQueue, operationsQueue,
eventDispatcher, eventDispatcher,
@@ -126,9 +178,9 @@ public class FlatUIImplementation extends UIImplementation {
@Override @Override
protected void handleCreateView( protected void handleCreateView(
ReactShadowNode cssNode, ReactShadowNode cssNode,
int rootViewTag, int rootViewTag,
@Nullable ReactStylesDiffMap styles) { @Nullable ReactStylesDiffMap styles) {
if (cssNode instanceof FlatShadowNode) { if (cssNode instanceof FlatShadowNode) {
FlatShadowNode node = (FlatShadowNode) cssNode; FlatShadowNode node = (FlatShadowNode) cssNode;
@@ -146,9 +198,9 @@ public class FlatUIImplementation extends UIImplementation {
@Override @Override
protected void handleUpdateView( protected void handleUpdateView(
ReactShadowNode cssNode, ReactShadowNode cssNode,
String className, String className,
ReactStylesDiffMap styles) { ReactStylesDiffMap styles) {
if (cssNode instanceof FlatShadowNode) { if (cssNode instanceof FlatShadowNode) {
FlatShadowNode node = (FlatShadowNode) cssNode; FlatShadowNode node = (FlatShadowNode) cssNode;
@@ -164,12 +216,12 @@ public class FlatUIImplementation extends UIImplementation {
@Override @Override
public void manageChildren( public void manageChildren(
int viewTag, int viewTag,
@Nullable ReadableArray moveFrom, @Nullable ReadableArray moveFrom,
@Nullable ReadableArray moveTo, @Nullable ReadableArray moveTo,
@Nullable ReadableArray addChildTags, @Nullable ReadableArray addChildTags,
@Nullable ReadableArray addAtIndices, @Nullable ReadableArray addAtIndices,
@Nullable ReadableArray removeFrom) { @Nullable ReadableArray removeFrom) {
ReactShadowNode parentNode = resolveShadowNode(viewTag); ReactShadowNode parentNode = resolveShadowNode(viewTag);
@@ -182,8 +234,8 @@ public class FlatUIImplementation extends UIImplementation {
@Override @Override
public void setChildren( public void setChildren(
int viewTag, int viewTag,
ReadableArray children) { ReadableArray children) {
ReactShadowNode parentNode = resolveShadowNode(viewTag); ReactShadowNode parentNode = resolveShadowNode(viewTag);
@@ -244,13 +296,13 @@ public class FlatUIImplementation extends UIImplementation {
FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue(); FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue();
operationsQueue.enqueueMeasureVirtualView( operationsQueue.enqueueMeasureVirtualView(
node.getReactTag(), node.getReactTag(),
xInParent / parentWidth, xInParent / parentWidth,
yInParent / parentHeight, yInParent / parentHeight,
width / parentWidth, width / parentWidth,
height / parentHeight, height / parentHeight,
relativeToWindow, relativeToWindow,
callback); callback);
} }
private void ensureMountsToViewAndBackingViewIsCreated(int reactTag) { private void ensureMountsToViewAndBackingViewIsCreated(int reactTag) {
@@ -304,10 +356,10 @@ public class FlatUIImplementation extends UIImplementation {
* preparing elements in moveFrom to be re-added at proper index. * preparing elements in moveFrom to be re-added at proper index.
*/ */
private void removeChildren( private void removeChildren(
ReactShadowNode parentNode, ReactShadowNode parentNode,
@Nullable ReadableArray moveFrom, @Nullable ReadableArray moveFrom,
@Nullable ReadableArray moveTo, @Nullable ReadableArray moveTo,
@Nullable ReadableArray removeFrom) { @Nullable ReadableArray removeFrom) {
int prevIndex = Integer.MAX_VALUE; int prevIndex = Integer.MAX_VALUE;
@@ -388,7 +440,7 @@ public class FlatUIImplementation extends UIImplementation {
if (tmpNode instanceof FlatShadowNode) { if (tmpNode instanceof FlatShadowNode) {
FlatShadowNode flatTmpNode = (FlatShadowNode) tmpNode; FlatShadowNode flatTmpNode = (FlatShadowNode) tmpNode;
if (flatTmpNode.mountsToView() && flatTmpNode.isBackingViewCreated() && if (flatTmpNode.mountsToView() && flatTmpNode.isBackingViewCreated() &&
flatTmpNode.getParent() != null) { flatTmpNode.getParent() != null) {
tag = flatTmpNode.getReactTag(); tag = flatTmpNode.getReactTag();
break; break;
} }
@@ -418,9 +470,9 @@ public class FlatUIImplementation extends UIImplementation {
* Adds all children from addChildTags and moveFrom/moveTo. * Adds all children from addChildTags and moveFrom/moveTo.
*/ */
private void addChildren( private void addChildren(
ReactShadowNode parentNode, ReactShadowNode parentNode,
@Nullable ReadableArray addChildTags, @Nullable ReadableArray addChildTags,
@Nullable ReadableArray addAtIndices) { @Nullable ReadableArray addAtIndices) {
int prevIndex = -1; int prevIndex = -1;
@@ -485,12 +537,12 @@ public class FlatUIImplementation extends UIImplementation {
* Removes a child from parent, verifying that we are removing in descending order. * Removes a child from parent, verifying that we are removing in descending order.
*/ */
private static ReactShadowNode removeChildAt( private static ReactShadowNode removeChildAt(
ReactShadowNode parentNode, ReactShadowNode parentNode,
int index, int index,
int prevIndex) { int prevIndex) {
if (index >= prevIndex) { if (index >= prevIndex) {
throw new RuntimeException( throw new RuntimeException(
"Invariant failure, needs sorting! " + index + " >= " + prevIndex); "Invariant failure, needs sorting! " + index + " >= " + prevIndex);
} }
return parentNode.removeChildAt(index); return parentNode.removeChildAt(index);
@@ -500,13 +552,13 @@ public class FlatUIImplementation extends UIImplementation {
* Adds a child to parent, verifying that we are adding in ascending order. * Adds a child to parent, verifying that we are adding in ascending order.
*/ */
private static void addChildAt( private static void addChildAt(
ReactShadowNode parentNode, ReactShadowNode parentNode,
ReactShadowNode childNode, ReactShadowNode childNode,
int index, int index,
int prevIndex) { int prevIndex) {
if (index <= prevIndex) { if (index <= prevIndex) {
throw new RuntimeException( throw new RuntimeException(
"Invariant failure, needs sorting! " + index + " <= " + prevIndex); "Invariant failure, needs sorting! " + index + " <= " + prevIndex);
} }
parentNode.addChildAt(childNode, index); parentNode.addChildAt(childNode, index);
@@ -520,9 +572,9 @@ public class FlatUIImplementation extends UIImplementation {
@Override @Override
protected void applyUpdatesRecursive( protected void applyUpdatesRecursive(
ReactShadowNode cssNode, ReactShadowNode cssNode,
float absoluteX, float absoluteX,
float absoluteY) { float absoluteY) {
mStateBuilder.applyUpdates((FlatRootShadowNode) cssNode); mStateBuilder.applyUpdates((FlatRootShadowNode) cssNode);
} }
@@ -551,18 +603,8 @@ public class FlatUIImplementation extends UIImplementation {
FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue(); FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue();
operationsQueue.enqueueSetJSResponder( operationsQueue.enqueueSetJSResponder(
node == null ? tag : node.getReactTag(), node == null ? tag : node.getReactTag(),
possiblyVirtualReactTag, possiblyVirtualReactTag,
blockNativeResponder); 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;
} }
} }

View File

@@ -9,21 +9,22 @@
package com.facebook.react.flat; 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.ReactShadowNode;
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.UIViewOperationQueue;
import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.ViewManager; 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.YogaUnit;
import com.facebook.yoga.YogaValue;
import javax.annotation.Nullable;
/* package */ final class NativeViewWrapper extends FlatShadowNode implements AndroidView { /* package */ final class NativeViewWrapper extends FlatShadowNode implements AndroidView {
@Nullable private final ReactShadowNode mReactShadowNode; @Nullable
private final ReactShadowNode mReactShadowNode;
private final boolean mNeedsCustomLayoutForChildren; private final boolean mNeedsCustomLayoutForChildren;
private boolean mPaddingChanged = false; private boolean mPaddingChanged = false;
private boolean mForceMountGrandChildrenToView; private boolean mForceMountGrandChildrenToView;

View File

@@ -9,13 +9,15 @@
package com.facebook.react.flat; package com.facebook.react.flat;
import javax.annotation.Nullable;
import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder; import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import javax.annotation.Nullable;
public final class RCTImageViewManager extends FlatViewManager { public final class RCTImageViewManager extends FlatViewManager {
/* package */ static final String REACT_CLASS = "RCTImageView";
private @Nullable AbstractDraweeControllerBuilder mDraweeControllerBuilder; private @Nullable AbstractDraweeControllerBuilder mDraweeControllerBuilder;
private final @Nullable Object mCallerContext; private final @Nullable Object mCallerContext;
@@ -32,7 +34,7 @@ public final class RCTImageViewManager extends FlatViewManager {
@Override @Override
public String getName() { public String getName() {
return "RCTImageView"; return REACT_CLASS;
} }
@Override @Override

View File

@@ -14,6 +14,8 @@ import com.facebook.react.views.modal.ReactModalHostManager;
public class RCTModalHostManager extends ReactModalHostManager { public class RCTModalHostManager extends ReactModalHostManager {
/* package */ static final String REACT_CLASS = ReactModalHostManager.REACT_CLASS;
@Override @Override
public LayoutShadowNode createShadowNodeInstance() { public LayoutShadowNode createShadowNodeInstance() {
return new FlatReactModalShadowNode(); return new FlatReactModalShadowNode();

View File

@@ -14,9 +14,11 @@ package com.facebook.react.flat;
*/ */
public final class RCTRawTextManager extends VirtualViewManager<RCTRawText> { public final class RCTRawTextManager extends VirtualViewManager<RCTRawText> {
/* package */ static final String REACT_CLASS = "RCTRawText";
@Override @Override
public String getName() { public String getName() {
return "RCTRawText"; return REACT_CLASS;
} }
@Override @Override

View File

@@ -14,9 +14,11 @@ package com.facebook.react.flat;
*/ */
public final class RCTTextInlineImageManager extends VirtualViewManager<RCTTextInlineImage> { public final class RCTTextInlineImageManager extends VirtualViewManager<RCTTextInlineImage> {
/* package */ static final String REACT_CLASS = "RCTTextInlineImage";
@Override @Override
public String getName() { public String getName() {
return "RCTTextInlineImage"; return REACT_CLASS;
} }
@Override @Override

View File

@@ -13,6 +13,8 @@ import com.facebook.react.views.textinput.ReactTextInputManager;
public class RCTTextInputManager extends ReactTextInputManager { public class RCTTextInputManager extends ReactTextInputManager {
/* package */ static final String REACT_CLASS = ReactTextInputManager.REACT_CLASS;
@Override @Override
public RCTTextInput createShadowNodeInstance() { public RCTTextInput createShadowNodeInstance() {
return new RCTTextInput(); return new RCTTextInput();

View File

@@ -14,9 +14,11 @@ package com.facebook.react.flat;
*/ */
public final class RCTTextManager extends FlatViewManager { public final class RCTTextManager extends FlatViewManager {
/* package */ static final String REACT_CLASS = "RCTText";
@Override @Override
public String getName() { public String getName() {
return "RCTText"; return REACT_CLASS;
} }
@Override @Override

View File

@@ -9,29 +9,29 @@
package com.facebook.react.flat; package com.facebook.react.flat;
import javax.annotation.Nullable;
import java.util.Map;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build; import android.os.Build;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder; import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.PointerEvents; import com.facebook.react.uimanager.PointerEvents;
import com.facebook.react.uimanager.ReactClippingViewGroupHelper;
import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.ReactClippingViewGroupHelper;
import com.facebook.react.views.view.ReactDrawableHelper; import com.facebook.react.views.view.ReactDrawableHelper;
import javax.annotation.Nullable;
import java.util.Map;
/** /**
* ViewManager that creates instances of RCTView. * ViewManager that creates instances of RCTView.
*/ */
public final class RCTViewManager extends FlatViewManager { public final class RCTViewManager extends FlatViewManager {
/* package */ static final String REACT_CLASS = ViewProps.VIEW_CLASS_NAME;
private static final int[] TMP_INT_ARRAY = new int[2]; private static final int[] TMP_INT_ARRAY = new int[2];
private static final int CMD_HOTSPOT_UPDATE = 1; private static final int CMD_HOTSPOT_UPDATE = 1;
@@ -39,7 +39,7 @@ public final class RCTViewManager extends FlatViewManager {
@Override @Override
public String getName() { public String getName() {
return ViewProps.VIEW_CLASS_NAME; return REACT_CLASS;
} }
public Map<String, Integer> getCommandsMap() { public Map<String, Integer> getCommandsMap() {
@@ -59,19 +59,19 @@ public final class RCTViewManager extends FlatViewManager {
@ReactProp(name = "nativeBackgroundAndroid") @ReactProp(name = "nativeBackgroundAndroid")
public void setHotspot(FlatViewGroup view, @Nullable ReadableMap bg) { public void setHotspot(FlatViewGroup view, @Nullable ReadableMap bg) {
view.setHotspot(bg == null ? view.setHotspot(bg == null ?
null : ReactDrawableHelper.createDrawableFromJSDescription(view.getContext(), bg)); null : ReactDrawableHelper.createDrawableFromJSDescription(view.getContext(), bg));
} }
@Override @Override
public void receiveCommand( public void receiveCommand(
FlatViewGroup view, FlatViewGroup view,
int commandId, int commandId,
@Nullable ReadableArray args) { @Nullable ReadableArray args) {
switch (commandId) { switch (commandId) {
case CMD_HOTSPOT_UPDATE: { case CMD_HOTSPOT_UPDATE: {
if (args == null || args.size() != 2) { if (args == null || args.size() != 2) {
throw new JSApplicationIllegalArgumentException( throw new JSApplicationIllegalArgumentException(
"Illegal number of arguments for 'updateHotspot' command"); "Illegal number of arguments for 'updateHotspot' command");
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.getLocationOnScreen(TMP_INT_ARRAY); view.getLocationOnScreen(TMP_INT_ARRAY);
@@ -84,7 +84,7 @@ public final class RCTViewManager extends FlatViewManager {
case CMD_SET_PRESSED: { case CMD_SET_PRESSED: {
if (args == null || args.size() != 1) { if (args == null || args.size() != 1) {
throw new JSApplicationIllegalArgumentException( throw new JSApplicationIllegalArgumentException(
"Illegal number of arguments for 'setPressed' command"); "Illegal number of arguments for 'setPressed' command");
} }
view.setPressed(args.getBoolean(0)); view.setPressed(args.getBoolean(0));
break; break;
@@ -94,8 +94,8 @@ public final class RCTViewManager extends FlatViewManager {
@ReactProp(name = ViewProps.NEEDS_OFFSCREEN_ALPHA_COMPOSITING) @ReactProp(name = ViewProps.NEEDS_OFFSCREEN_ALPHA_COMPOSITING)
public void setNeedsOffscreenAlphaCompositing( public void setNeedsOffscreenAlphaCompositing(
FlatViewGroup view, FlatViewGroup view,
boolean needsOffscreenAlphaCompositing) { boolean needsOffscreenAlphaCompositing) {
view.setNeedsOffscreenAlphaCompositing(needsOffscreenAlphaCompositing); view.setNeedsOffscreenAlphaCompositing(needsOffscreenAlphaCompositing);
} }
@@ -132,10 +132,10 @@ public final class RCTViewManager extends FlatViewManager {
view.setHitSlopRect(null); view.setHitSlopRect(null);
} else { } else {
view.setHitSlopRect(new Rect( view.setHitSlopRect(new Rect(
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")), (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")),
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")), (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")),
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")), (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")),
(int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")) (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom"))
)); ));
} }
} }

View File

@@ -9,15 +9,16 @@
package com.facebook.react.flat; package com.facebook.react.flat;
import java.util.List;
import android.view.View; import android.view.View;
import com.facebook.react.views.viewpager.ReactViewPager; import com.facebook.react.views.viewpager.ReactViewPager;
import com.facebook.react.views.viewpager.ReactViewPagerManager; import com.facebook.react.views.viewpager.ReactViewPagerManager;
import java.util.List;
public class RCTViewPagerManager extends ReactViewPagerManager { public class RCTViewPagerManager extends ReactViewPagerManager {
/* package */ static final String REACT_CLASS = ReactViewPagerManager.REACT_CLASS;
@Override @Override
public void addViews(ReactViewPager parent, List<View> views) { public void addViews(ReactViewPager parent, List<View> views) {
parent.setViews(views); parent.setViews(views);

View File

@@ -14,9 +14,11 @@ package com.facebook.react.flat;
*/ */
public final class RCTVirtualTextManager extends VirtualViewManager<RCTVirtualText> { public final class RCTVirtualTextManager extends VirtualViewManager<RCTVirtualText> {
/* package */ static final String REACT_CLASS = "RCTVirtualText";
@Override @Override
public String getName() { public String getName() {
return "RCTVirtualText"; return REACT_CLASS;
} }
@Override @Override

View File

@@ -9,16 +9,8 @@
package com.facebook.react.shell; package com.facebook.react.shell;
import javax.inject.Provider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.facebook.react.LazyReactPackage; import com.facebook.react.LazyReactPackage;
import com.facebook.react.animated.NativeAnimatedModule; import com.facebook.react.animated.NativeAnimatedModule;
import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.JavaScriptModule;
@@ -83,6 +75,12 @@ import com.facebook.react.views.view.ReactViewManager;
import com.facebook.react.views.viewpager.ReactViewPagerManager; import com.facebook.react.views.viewpager.ReactViewPagerManager;
import com.facebook.react.views.webview.ReactWebViewManager; import com.facebook.react.views.webview.ReactWebViewManager;
import javax.inject.Provider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/** /**
* Package defining basic modules and view managers. * Package defining basic modules and view managers.
*/ */
@@ -261,41 +259,44 @@ public class MainReactPackage extends LazyReactPackage {
viewManagers.add(ARTRenderableViewManager.createARTGroupViewManager()); viewManagers.add(ARTRenderableViewManager.createARTGroupViewManager());
viewManagers.add(ARTRenderableViewManager.createARTShapeViewManager()); viewManagers.add(ARTRenderableViewManager.createARTShapeViewManager());
viewManagers.add(ARTRenderableViewManager.createARTTextViewManager()); viewManagers.add(ARTRenderableViewManager.createARTTextViewManager());
viewManagers.add(new ARTSurfaceViewManager());
viewManagers.add(new ReactDialogPickerManager()); viewManagers.add(new ReactDialogPickerManager());
viewManagers.add(new ReactDrawerLayoutManager()); viewManagers.add(new ReactDrawerLayoutManager());
viewManagers.add(new ReactDropdownPickerManager()); viewManagers.add(new ReactDropdownPickerManager());
viewManagers.add(new ReactHorizontalScrollViewManager()); viewManagers.add(new ReactHorizontalScrollViewManager());
viewManagers.add(new ReactImageManager());
viewManagers.add(new ReactModalHostManager());
viewManagers.add(new ReactProgressBarViewManager()); viewManagers.add(new ReactProgressBarViewManager());
viewManagers.add(new ReactRawTextManager());
viewManagers.add(new ReactScrollViewManager()); viewManagers.add(new ReactScrollViewManager());
viewManagers.add(new ReactSliderManager()); viewManagers.add(new ReactSliderManager());
viewManagers.add(new ReactSwitchManager()); viewManagers.add(new ReactSwitchManager());
viewManagers.add(new FrescoBasedReactTextInlineImageViewManager());
viewManagers.add(new ReactTextInputManager());
viewManagers.add(new ReactTextViewManager());
viewManagers.add(new ReactToolbarManager()); viewManagers.add(new ReactToolbarManager());
viewManagers.add(new ReactViewManager());
viewManagers.add(new ReactViewPagerManager());
viewManagers.add(new ReactVirtualTextViewManager());
viewManagers.add(new ReactWebViewManager()); viewManagers.add(new ReactWebViewManager());
viewManagers.add(new SwipeRefreshLayoutManager()); viewManagers.add(new SwipeRefreshLayoutManager());
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(reactContext); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(reactContext);
if (preferences.getBoolean("flat_uiimplementation", false)) { boolean useFlatUi = preferences.getBoolean("flat_uiimplementation", false);
viewManagers.addAll(Arrays.asList( if (useFlatUi) {
new RCTViewManager(), // Flat managers
new RCTTextManager(), viewManagers.add(new FlatARTSurfaceViewManager());
new RCTRawTextManager(), viewManagers.add(new RCTTextInlineImageManager());
new RCTVirtualTextManager(), viewManagers.add(new RCTImageViewManager());
new RCTTextInlineImageManager(), viewManagers.add(new RCTModalHostManager());
new RCTImageViewManager(), viewManagers.add(new RCTRawTextManager());
new RCTTextInputManager(), viewManagers.add(new RCTTextInputManager());
new RCTViewPagerManager(), viewManagers.add(new RCTTextManager());
new FlatARTSurfaceViewManager(), viewManagers.add(new RCTViewManager());
new RCTModalHostManager())); viewManagers.add(new RCTViewPagerManager());
viewManagers.add(new RCTVirtualTextManager());
} else {
// Native equivalents
viewManagers.add(new ARTSurfaceViewManager());
viewManagers.add(new FrescoBasedReactTextInlineImageViewManager());
viewManagers.add(new ReactImageManager());
viewManagers.add(new ReactModalHostManager());
viewManagers.add(new ReactRawTextManager());
viewManagers.add(new ReactTextInputManager());
viewManagers.add(new ReactTextViewManager());
viewManagers.add(new ReactViewManager());
viewManagers.add(new ReactViewPagerManager());
viewManagers.add(new ReactVirtualTextViewManager());
} }
return viewManagers; return viewManagers;

View File

@@ -19,14 +19,19 @@ import java.util.Map;
*/ */
public class ViewManagerRegistry { public class ViewManagerRegistry {
private final Map<String, ViewManager> mViewManagers = new HashMap<>(); private final Map<String, ViewManager> mViewManagers;
public ViewManagerRegistry(List<ViewManager> viewManagerList) { public ViewManagerRegistry(List<ViewManager> viewManagerList) {
mViewManagers = new HashMap<>();
for (ViewManager viewManager : viewManagerList) { for (ViewManager viewManager : viewManagerList) {
mViewManagers.put(viewManager.getName(), viewManager); mViewManagers.put(viewManager.getName(), viewManager);
} }
} }
public ViewManagerRegistry(Map<String, ViewManager> viewManagerMap) {
mViewManagers = viewManagerMap;
}
public ViewManager get(String className) { public ViewManager get(String className) {
ViewManager viewManager = mViewManagers.get(className); ViewManager viewManager = mViewManagers.get(className);
if (viewManager != null) { if (viewManager != null) {