First attempt at partial currentColor support

This commit is contained in:
Mikael Sand
2018-10-04 22:17:18 +03:00
parent ad99f97c84
commit 1827b91883
7 changed files with 39 additions and 3 deletions
@@ -394,6 +394,9 @@ abstract public class RenderableShadowNode extends VirtualNode {
} }
brush.setupPaint(paint, mBox, mScale, opacity); brush.setupPaint(paint, mBox, mScale, opacity);
} }
} else if (colorType == 2) {
int brush = getSvgShadowNode().mTintColor;
paint.setColor(brush);
} }
} }
@@ -30,6 +30,8 @@ import java.io.ByteArrayOutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable;
/** /**
* Shadow node for RNSVG virtual tree root - RNSVGSvgView * Shadow node for RNSVG virtual tree root - RNSVGSvgView
*/ */
@@ -54,6 +56,7 @@ public class SvgViewShadowNode extends LayoutShadowNode {
private Matrix mInvViewBoxMatrix = new Matrix(); private Matrix mInvViewBoxMatrix = new Matrix();
private boolean mInvertible = true; private boolean mInvertible = true;
private boolean mRendered = false; private boolean mRendered = false;
int mTintColor = 0;
public SvgViewShadowNode() { public SvgViewShadowNode() {
mScale = DisplayMetricsHolder.getScreenDisplayMetrics().density; mScale = DisplayMetricsHolder.getScreenDisplayMetrics().density;
@@ -74,6 +77,15 @@ public class SvgViewShadowNode extends LayoutShadowNode {
}); });
} }
@ReactProp(name = "tintColor", customType = "Color")
public void setTintColor(@Nullable Integer tintColor) {
if (tintColor == null) {
mTintColor = 0;
} else {
mTintColor = tintColor;
}
}
@ReactProp(name = "minX") @ReactProp(name = "minX")
public void setMinX(float minX) { public void setMinX(float minX) {
mMinX = minX; mMinX = minX;
+4 -1
View File
@@ -75,6 +75,7 @@ class Svg extends Shape {
viewBox, viewBox,
preserveAspectRatio, preserveAspectRatio,
style, style,
color,
...props ...props
} = this.props; } = this.props;
let dimensions; let dimensions;
@@ -95,6 +96,7 @@ class Svg extends Shape {
{...props} {...props}
bbWidth={w} bbWidth={w}
bbHeight={h} bbHeight={h}
tintColor={color}
{...extractResponder(props, this)} {...extractResponder(props, this)}
{...extractViewBox({ viewBox, preserveAspectRatio })} {...extractViewBox({ viewBox, preserveAspectRatio })}
ref={ele => { ref={ele => {
@@ -117,7 +119,8 @@ const NativeSvgView = requireNativeComponent("RNSVGSvgView", null, {
nativeOnly: { nativeOnly: {
...ViewBoxAttributes, ...ViewBoxAttributes,
width: true, width: true,
height: true height: true,
tintColor: true
} }
}); });
+14 -2
View File
@@ -298,7 +298,12 @@ UInt32 saturate(double value) {
BOOL evenodd = self.fillRule == kRNSVGCGFCRuleEvenodd; BOOL evenodd = self.fillRule == kRNSVGCGFCRuleEvenodd;
if (self.fill) { if (self.fill) {
fillColor = [self.fill applyFillColor:context opacity:self.fillOpacity]; if (self.fill.class == RNSVGBrush.class) {
CGContextSetFillColorWithColor(context, [self.tintColor CGColor]);
fillColor = YES;
} else {
fillColor = [self.fill applyFillColor:context opacity:self.fillOpacity];
}
if (fillColor) { if (fillColor) {
mode = evenodd ? kCGPathEOFill : kCGPathFill; mode = evenodd ? kCGPathEOFill : kCGPathFill;
@@ -336,7 +341,14 @@ UInt32 saturate(double value) {
CGContextClip(context); CGContextClip(context);
} }
BOOL strokeColor = [self.stroke applyStrokeColor:context opacity:self.strokeOpacity]; BOOL strokeColor;
if (self.stroke.class == RNSVGBrush.class) {
CGContextSetStrokeColorWithColor(context,[self.tintColor CGColor]);
strokeColor = YES;
} else {
strokeColor = [self.stroke applyStrokeColor:context opacity:self.strokeOpacity];
}
if (strokeColor && fillColor) { if (strokeColor && fillColor) {
mode = evenodd ? kCGPathEOFillStroke : kCGPathFillStroke; mode = evenodd ? kCGPathEOFillStroke : kCGPathFillStroke;
+2
View File
@@ -84,6 +84,8 @@ RCT_ENUM_CONVERTER(RNSVGUnits, (@{
return [[RNSVGSolidColorBrush alloc] initWithArray:arr]; return [[RNSVGSolidColorBrush alloc] initWithArray:arr];
case 1: // brush case 1: // brush
return [[RNSVGPainterBrush alloc] initWithArray:arr]; return [[RNSVGPainterBrush alloc] initWithArray:arr];
case 2: // currentColor
return [[RNSVGBrush alloc] initWithArray:nil];
default: default:
RCTLogError(@"Unknown brush type: %zd", type); RCTLogError(@"Unknown brush type: %zd", type);
return nil; return nil;
+1
View File
@@ -28,6 +28,7 @@ RCT_EXPORT_VIEW_PROPERTY(vbWidth, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(vbHeight, CGFloat) RCT_EXPORT_VIEW_PROPERTY(vbHeight, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(align, NSString) RCT_EXPORT_VIEW_PROPERTY(align, NSString)
RCT_EXPORT_VIEW_PROPERTY(meetOrSlice, RNSVGVBMOS) RCT_EXPORT_VIEW_PROPERTY(meetOrSlice, RNSVGVBMOS)
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor)
RCT_EXPORT_METHOD(toDataURL:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(toDataURL:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback)
{ {
+3
View File
@@ -6,6 +6,9 @@ export default function(colorOrBrush) {
return null; return null;
} }
if (colorOrBrush === 'currentColor') {
return [2]
}
try { try {
let matched = colorOrBrush.match(patternReg); let matched = colorOrBrush.match(patternReg);
// brush // brush