Skip to content

Commit

Permalink
feat: Implement display="none"
Browse files Browse the repository at this point in the history
fixes: Enable display svg prop #1220
  • Loading branch information
msand committed Jan 1, 2020
1 parent 027b8c1 commit 3e3ad13
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions android/src/main/java/com/horcrux/svg/GroupView.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
}
if (child instanceof VirtualView) {
VirtualView node = ((VirtualView)child);
if ("none".equals(node.mDisplay)) {
continue;
}
if (node instanceof RenderableView) {
((RenderableView)node).mergeProperties(self);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,11 @@ public void setName(VirtualView node, String name) {
node.setName(name);
}

@ReactProp(name = "display")
public void setDisplay(VirtualView node, String display) {
node.setDisplay(display);
}

private void invalidateSvgView(VirtualView node) {
SvgView view = node.getSvgView();
if (view!= null) {
Expand Down
7 changes: 7 additions & 0 deletions android/src/main/java/com/horcrux/svg/VirtualView.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ abstract public class VirtualView extends ReactViewGroup {
final float mScale;
private boolean mResponsible;
private boolean mOnLayout;
String mDisplay;
String mName;

private SvgView svgView;
Expand Down Expand Up @@ -242,6 +243,12 @@ public void setName(String name) {
invalidate();
}

@ReactProp(name = "display")
public void setDisplay(String display) {
mDisplay = display;
invalidate();
}

@ReactProp(name = "onLayout")
public void setOnLayout(boolean onLayout) {
mOnLayout = onLayout;
Expand Down
3 changes: 3 additions & 0 deletions ios/Elements/RNSVGGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ - (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
// no-op
} else if ([node isKindOfClass:[RNSVGNode class]]) {
RNSVGNode* svgNode = (RNSVGNode*)node;
if (svgNode.display && [@"none" isEqualToString:svgNode.display]) {
return YES;
}
if (svgNode.responsible && !self.svgView.responsible) {
self.svgView.responsible = YES;
}
Expand Down
1 change: 1 addition & 0 deletions ios/RNSVGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern CGFloat const RNSVG_M_SQRT1_2l;
extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *display;
@property (nonatomic, assign) CGFloat opacity;
@property (nonatomic, assign) RNSVGCGFCRule clipRule;
@property (nonatomic, strong) NSString *clipPath;
Expand Down
10 changes: 10 additions & 0 deletions ios/RNSVGNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ - (void)setName:(NSString *)name
_name = name;
}

- (void)setDisplay:(NSString *)display
{
if ([display isEqualToString:_display]) {
return;
}

[self invalidate];
_display = display;
}

- (void)setOpacity:(CGFloat)opacity
{
if (opacity == _opacity) {
Expand Down
4 changes: 4 additions & 0 deletions ios/ViewManagers/RNSVGNodeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ - (UIView *)view

RCT_CUSTOM_SHADOW_PROPERTY(overflow, 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) {}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/extract/extractProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function extractProps(
markerMid?: string;
markerEnd?: string;
clipPath?: string;
display?: string;
opacity?: NumberProp;
onLayout?: () => void;
transform?: number[] | string | TransformProps;
Expand All @@ -57,11 +58,12 @@ export default function extractProps(
ref: Object,
) {
const {
id,
opacity,
onLayout,
id,
clipPath,
clipRule,
display,
mask,
marker,
markerStart = marker,
Expand All @@ -85,6 +87,7 @@ export default function extractProps(
markerEnd?: string;
clipPath?: string;
clipRule?: number;
display?: string;
} = {
matrix,
...transformProps,
Expand All @@ -93,6 +96,7 @@ export default function extractProps(
...extractResponder(props, ref),
...extractFill(props, styleProperties),
...extractStroke(props, styleProperties),
display: display === 'none' ? 'none' : undefined,
};

if (onLayout) {
Expand Down

0 comments on commit 3e3ad13

Please sign in to comment.