feat: Implement display="none"

fixes: Enable display svg prop #1220
This commit is contained in:
Mikael Sand
2020-01-01 21:34:03 +02:00
parent 027b8c16aa
commit 3e3ad13b65
8 changed files with 38 additions and 1 deletions
@@ -94,6 +94,9 @@ class GroupView extends RenderableView {
} }
if (child instanceof VirtualView) { if (child instanceof VirtualView) {
VirtualView node = ((VirtualView)child); VirtualView node = ((VirtualView)child);
if ("none".equals(node.mDisplay)) {
continue;
}
if (node instanceof RenderableView) { if (node instanceof RenderableView) {
((RenderableView)node).mergeProperties(self); ((RenderableView)node).mergeProperties(self);
} }
@@ -1213,6 +1213,11 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
node.setName(name); node.setName(name);
} }
@ReactProp(name = "display")
public void setDisplay(VirtualView node, String display) {
node.setDisplay(display);
}
private void invalidateSvgView(VirtualView node) { private void invalidateSvgView(VirtualView node) {
SvgView view = node.getSvgView(); SvgView view = node.getSvgView();
if (view!= null) { if (view!= null) {
@@ -77,6 +77,7 @@ abstract public class VirtualView extends ReactViewGroup {
final float mScale; final float mScale;
private boolean mResponsible; private boolean mResponsible;
private boolean mOnLayout; private boolean mOnLayout;
String mDisplay;
String mName; String mName;
private SvgView svgView; private SvgView svgView;
@@ -242,6 +243,12 @@ abstract public class VirtualView extends ReactViewGroup {
invalidate(); invalidate();
} }
@ReactProp(name = "display")
public void setDisplay(String display) {
mDisplay = display;
invalidate();
}
@ReactProp(name = "onLayout") @ReactProp(name = "onLayout")
public void setOnLayout(boolean onLayout) { public void setOnLayout(boolean onLayout) {
mOnLayout = onLayout; mOnLayout = onLayout;
+3
View File
@@ -43,6 +43,9 @@
// no-op // no-op
} else if ([node isKindOfClass:[RNSVGNode class]]) { } else if ([node isKindOfClass:[RNSVGNode class]]) {
RNSVGNode* svgNode = (RNSVGNode*)node; RNSVGNode* svgNode = (RNSVGNode*)node;
if (svgNode.display && [@"none" isEqualToString:svgNode.display]) {
return YES;
}
if (svgNode.responsible && !self.svgView.responsible) { if (svgNode.responsible && !self.svgView.responsible) {
self.svgView.responsible = YES; self.svgView.responsible = YES;
} }
+1
View File
@@ -27,6 +27,7 @@ extern CGFloat const RNSVG_M_SQRT1_2l;
extern CGFloat const RNSVG_DEFAULT_FONT_SIZE; extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
@property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *display;
@property (nonatomic, assign) CGFloat opacity; @property (nonatomic, assign) CGFloat opacity;
@property (nonatomic, assign) RNSVGCGFCRule clipRule; @property (nonatomic, assign) RNSVGCGFCRule clipRule;
@property (nonatomic, strong) NSString *clipPath; @property (nonatomic, strong) NSString *clipPath;
+10
View File
@@ -174,6 +174,16 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
_name = name; _name = name;
} }
- (void)setDisplay:(NSString *)display
{
if ([display isEqualToString:_display]) {
return;
}
[self invalidate];
_display = display;
}
- (void)setOpacity:(CGFloat)opacity - (void)setOpacity:(CGFloat)opacity
{ {
if (opacity == _opacity) { if (opacity == _opacity) {
+4
View File
@@ -229,6 +229,10 @@ RCT_CUSTOM_SHADOW_PROPERTY(aspectRatio, id, RNSVGNode) {}
RCT_CUSTOM_SHADOW_PROPERTY(overflow, id, RNSVGNode) {} RCT_CUSTOM_SHADOW_PROPERTY(overflow, id, RNSVGNode) {}
RCT_CUSTOM_SHADOW_PROPERTY(display, id, RNSVGNode) {} RCT_CUSTOM_SHADOW_PROPERTY(display, id, RNSVGNode) {}
RCT_CUSTOM_VIEW_PROPERTY(display, id, RNSVGNode)
{
view.display = json;
}
RCT_CUSTOM_SHADOW_PROPERTY(direction, id, RNSVGNode) {} RCT_CUSTOM_SHADOW_PROPERTY(direction, id, RNSVGNode) {}
+5 -1
View File
@@ -46,6 +46,7 @@ export default function extractProps(
markerMid?: string; markerMid?: string;
markerEnd?: string; markerEnd?: string;
clipPath?: string; clipPath?: string;
display?: string;
opacity?: NumberProp; opacity?: NumberProp;
onLayout?: () => void; onLayout?: () => void;
transform?: number[] | string | TransformProps; transform?: number[] | string | TransformProps;
@@ -57,11 +58,12 @@ export default function extractProps(
ref: Object, ref: Object,
) { ) {
const { const {
id,
opacity, opacity,
onLayout, onLayout,
id,
clipPath, clipPath,
clipRule, clipRule,
display,
mask, mask,
marker, marker,
markerStart = marker, markerStart = marker,
@@ -85,6 +87,7 @@ export default function extractProps(
markerEnd?: string; markerEnd?: string;
clipPath?: string; clipPath?: string;
clipRule?: number; clipRule?: number;
display?: string;
} = { } = {
matrix, matrix,
...transformProps, ...transformProps,
@@ -93,6 +96,7 @@ export default function extractProps(
...extractResponder(props, ref), ...extractResponder(props, ref),
...extractFill(props, styleProperties), ...extractFill(props, styleProperties),
...extractStroke(props, styleProperties), ...extractStroke(props, styleProperties),
display: display === 'none' ? 'none' : undefined,
}; };
if (onLayout) { if (onLayout) {