mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 07:59:28 +00:00
First attempt at partial currentColor support
This commit is contained in:
@@ -394,6 +394,9 @@ abstract public class RenderableShadowNode extends VirtualNode {
|
||||
}
|
||||
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.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Shadow node for RNSVG virtual tree root - RNSVGSvgView
|
||||
*/
|
||||
@@ -54,6 +56,7 @@ public class SvgViewShadowNode extends LayoutShadowNode {
|
||||
private Matrix mInvViewBoxMatrix = new Matrix();
|
||||
private boolean mInvertible = true;
|
||||
private boolean mRendered = false;
|
||||
int mTintColor = 0;
|
||||
|
||||
public SvgViewShadowNode() {
|
||||
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")
|
||||
public void setMinX(float minX) {
|
||||
mMinX = minX;
|
||||
|
||||
+4
-1
@@ -75,6 +75,7 @@ class Svg extends Shape {
|
||||
viewBox,
|
||||
preserveAspectRatio,
|
||||
style,
|
||||
color,
|
||||
...props
|
||||
} = this.props;
|
||||
let dimensions;
|
||||
@@ -95,6 +96,7 @@ class Svg extends Shape {
|
||||
{...props}
|
||||
bbWidth={w}
|
||||
bbHeight={h}
|
||||
tintColor={color}
|
||||
{...extractResponder(props, this)}
|
||||
{...extractViewBox({ viewBox, preserveAspectRatio })}
|
||||
ref={ele => {
|
||||
@@ -117,7 +119,8 @@ const NativeSvgView = requireNativeComponent("RNSVGSvgView", null, {
|
||||
nativeOnly: {
|
||||
...ViewBoxAttributes,
|
||||
width: true,
|
||||
height: true
|
||||
height: true,
|
||||
tintColor: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+14
-2
@@ -298,7 +298,12 @@ UInt32 saturate(double value) {
|
||||
BOOL evenodd = self.fillRule == kRNSVGCGFCRuleEvenodd;
|
||||
|
||||
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) {
|
||||
mode = evenodd ? kCGPathEOFill : kCGPathFill;
|
||||
@@ -336,7 +341,14 @@ UInt32 saturate(double value) {
|
||||
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) {
|
||||
mode = evenodd ? kCGPathEOFillStroke : kCGPathFillStroke;
|
||||
|
||||
@@ -84,6 +84,8 @@ RCT_ENUM_CONVERTER(RNSVGUnits, (@{
|
||||
return [[RNSVGSolidColorBrush alloc] initWithArray:arr];
|
||||
case 1: // brush
|
||||
return [[RNSVGPainterBrush alloc] initWithArray:arr];
|
||||
case 2: // currentColor
|
||||
return [[RNSVGBrush alloc] initWithArray:nil];
|
||||
default:
|
||||
RCTLogError(@"Unknown brush type: %zd", type);
|
||||
return nil;
|
||||
|
||||
@@ -28,6 +28,7 @@ RCT_EXPORT_VIEW_PROPERTY(vbWidth, CGFloat)
|
||||
RCT_EXPORT_VIEW_PROPERTY(vbHeight, CGFloat)
|
||||
RCT_EXPORT_VIEW_PROPERTY(align, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(meetOrSlice, RNSVGVBMOS)
|
||||
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor)
|
||||
|
||||
RCT_EXPORT_METHOD(toDataURL:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,9 @@ export default function(colorOrBrush) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (colorOrBrush === 'currentColor') {
|
||||
return [2]
|
||||
}
|
||||
try {
|
||||
let matched = colorOrBrush.match(patternReg);
|
||||
// brush
|
||||
|
||||
Reference in New Issue
Block a user