[android] Override LayoutShadowNode layout prop handlers.

Fix mergeProperties for groups and text.
Some regressions with edge cases of inheritance still remain.
This commit is contained in:
Mikael Sand
2018-10-15 03:41:48 +03:00
parent e9e2454b06
commit 8dfabb5375
4 changed files with 110 additions and 26 deletions
@@ -31,8 +31,8 @@ import javax.annotation.Nullable;
*/ */
@SuppressLint("ViewConstructor") @SuppressLint("ViewConstructor")
class GroupView extends RenderableView { class GroupView extends RenderableView {
@Nullable ReadableMap mFont; public @Nullable ReadableMap mFont;
private GlyphContext mGlyphContext; public GlyphContext mGlyphContext;
public GroupView(ReactContext reactContext) { public GroupView(ReactContext reactContext) {
super(reactContext); super(reactContext);
@@ -59,25 +59,25 @@ abstract public class RenderableView extends VirtualView {
private static final int FILL_RULE_EVENODD = 0; private static final int FILL_RULE_EVENODD = 0;
static final int FILL_RULE_NONZERO = 1; static final int FILL_RULE_NONZERO = 1;
private @Nullable ReadableArray mStroke; public @Nullable ReadableArray mStroke;
private @Nullable String[] mStrokeDasharray; public @Nullable String[] mStrokeDasharray;
private String mStrokeWidth = "1"; public String mStrokeWidth = "1";
private float mStrokeOpacity = 1; public float mStrokeOpacity = 1;
private float mStrokeMiterlimit = 4; public float mStrokeMiterlimit = 4;
private float mStrokeDashoffset = 0; public float mStrokeDashoffset = 0;
private Paint.Cap mStrokeLinecap = Paint.Cap.ROUND; public Paint.Cap mStrokeLinecap = Paint.Cap.ROUND;
private Paint.Join mStrokeLinejoin = Paint.Join.ROUND; public Paint.Join mStrokeLinejoin = Paint.Join.ROUND;
private @Nullable ReadableArray mFill; public @Nullable ReadableArray mFill;
private float mFillOpacity = 1; public float mFillOpacity = 1;
private Path.FillType mFillRule = Path.FillType.WINDING; public Path.FillType mFillRule = Path.FillType.WINDING;
private @Nullable ArrayList<String> mLastMergedList; public @Nullable ArrayList<String> mLastMergedList;
private @Nullable ArrayList<Object> mOriginProperties; public @Nullable ArrayList<Object> mOriginProperties;
private @Nullable ArrayList<String> mPropList; public @Nullable ArrayList<String> mPropList;
private @Nullable ArrayList<String> mAttributeList; public @Nullable ArrayList<String> mAttributeList;
private static final Pattern regex = Pattern.compile("[0-9.-]+"); private static final Pattern regex = Pattern.compile("[0-9.-]+");
@@ -16,12 +16,15 @@ import com.facebook.react.bridge.Dynamic;
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.uimanager.DisplayMetricsHolder; import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.MatrixMathHelper; import com.facebook.react.uimanager.MatrixMathHelper;
import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.TransformHelper; import com.facebook.react.uimanager.TransformHelper;
import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.ViewGroupManager;
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.annotations.ReactPropGroup;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -35,6 +38,7 @@ import static com.facebook.react.uimanager.MatrixMathHelper.v3Cross;
import static com.facebook.react.uimanager.MatrixMathHelper.v3Dot; import static com.facebook.react.uimanager.MatrixMathHelper.v3Dot;
import static com.facebook.react.uimanager.MatrixMathHelper.v3Length; import static com.facebook.react.uimanager.MatrixMathHelper.v3Length;
import static com.facebook.react.uimanager.MatrixMathHelper.v3Normalize; import static com.facebook.react.uimanager.MatrixMathHelper.v3Normalize;
import static com.facebook.react.uimanager.ViewProps.*;
import static com.horcrux.svg.RenderableView.CAP_ROUND; import static com.horcrux.svg.RenderableView.CAP_ROUND;
import static com.horcrux.svg.RenderableView.FILL_RULE_NONZERO; import static com.horcrux.svg.RenderableView.FILL_RULE_NONZERO;
import static com.horcrux.svg.RenderableView.JOIN_ROUND; import static com.horcrux.svg.RenderableView.JOIN_ROUND;
@@ -65,6 +69,86 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
RNSVGMask, RNSVGMask,
} }
class RenderableShadowNode extends LayoutShadowNode {
@ReactPropGroup(
names = {
ALIGN_SELF,
ALIGN_ITEMS,
COLLAPSABLE,
FLEX,
FLEX_BASIS,
FLEX_DIRECTION,
FLEX_GROW,
FLEX_SHRINK,
FLEX_WRAP,
JUSTIFY_CONTENT,
OVERFLOW,
ALIGN_CONTENT,
DISPLAY,
/* position */
POSITION,
RIGHT,
TOP,
BOTTOM,
LEFT,
START,
END,
/* dimensions */
WIDTH,
HEIGHT,
MIN_WIDTH,
MAX_WIDTH,
MIN_HEIGHT,
MAX_HEIGHT,
/* margins */
MARGIN,
MARGIN_VERTICAL,
MARGIN_HORIZONTAL,
MARGIN_LEFT,
MARGIN_RIGHT,
MARGIN_TOP,
MARGIN_BOTTOM,
MARGIN_START,
MARGIN_END,
/* paddings */
PADDING,
PADDING_VERTICAL,
PADDING_HORIZONTAL,
PADDING_LEFT,
PADDING_RIGHT,
PADDING_TOP,
PADDING_BOTTOM,
PADDING_START,
PADDING_END,
BORDER_WIDTH,
BORDER_START_WIDTH,
BORDER_END_WIDTH,
BORDER_TOP_WIDTH,
BORDER_BOTTOM_WIDTH,
BORDER_LEFT_WIDTH,
BORDER_RIGHT_WIDTH,
}
)
public void ignoreLayoutProps(int index, Dynamic value) {}
}
@Override
public LayoutShadowNode createShadowNodeInstance() {
return new RenderableShadowNode();
}
@Override
public Class<RenderableShadowNode> getShadowNodeClass() {
return RenderableShadowNode.class;
}
private final SVGClass svgClass; private final SVGClass svgClass;
private final String mClassName; private final String mClassName;
@@ -32,15 +32,15 @@ import static com.horcrux.svg.TextProperties.*;
@SuppressLint("ViewConstructor") @SuppressLint("ViewConstructor")
class TextView extends GroupView { class TextView extends GroupView {
String mTextLength = null; public String mTextLength = null;
private String mBaselineShift = null; public String mBaselineShift = null;
TextLengthAdjust mLengthAdjust = TextLengthAdjust.spacing; public TextLengthAdjust mLengthAdjust = TextLengthAdjust.spacing;
private AlignmentBaseline mAlignmentBaseline; public AlignmentBaseline mAlignmentBaseline;
private @Nullable ReadableArray mPositionX; public @Nullable ReadableArray mPositionX;
private @Nullable ReadableArray mPositionY; public @Nullable ReadableArray mPositionY;
private @Nullable ReadableArray mRotate; public @Nullable ReadableArray mRotate;
private @Nullable ReadableArray mDeltaX; public @Nullable ReadableArray mDeltaX;
private @Nullable ReadableArray mDeltaY; public @Nullable ReadableArray mDeltaY;
public TextView(ReactContext reactContext) { public TextView(ReactContext reactContext) {
super(reactContext); super(reactContext);