Skip to content

Commit

Permalink
fix: handling of color/tintColor, fixes #1088 and #1115
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Sep 25, 2019
1 parent d21213d commit 1eaf3a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion android/src/main/java/com/horcrux/svg/SvgView.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void clearChildCache() {
}
}

@ReactProp(name = "tintColor", customType = "Color")
@ReactProp(name = "tintColor")
public void setTintColor(@Nullable Integer tintColor) {
if (tintColor == null) {
mTintColor = 0;
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/com/horcrux/svg/SvgViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public boolean needsCustomLayoutForChildren() {
return true;
}

@ReactProp(name = "tintColor", customType = "Color")
@ReactProp(name = "tintColor")
public void setTintColor(SvgView node, @Nullable Integer tintColor) {
node.setTintColor(tintColor);
}

@ReactProp(name = "color", customType = "Color")
@ReactProp(name = "color")
public void setColor(SvgView node, @Nullable Integer color) {
node.setTintColor(color);
}
Expand Down
7 changes: 6 additions & 1 deletion src/elements/Svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
MeasureInWindowOnSuccessCallback,
} from 'react-native';
import {
Color,
ClipProps,
FillProps,
NumberProp,
Expand All @@ -19,6 +20,7 @@ import {
} from '../lib/extract/types';
import extractResponder from '../lib/extract/extractResponder';
import extractViewBox from '../lib/extract/extractViewBox';
import extractColor from '../lib/extract/extractColor';
import Shape from './Shape';
import G from './G';

Expand All @@ -33,6 +35,7 @@ const styles = StyleSheet.create({

export default class Svg extends Shape<
{
color?: Color;
style?: [] | {};
viewBox?: string;
opacity?: NumberProp;
Expand Down Expand Up @@ -148,12 +151,14 @@ export default class Svg extends Shape<
}
: null;

const tint = extractColor(color);
return (
<RNSVGSvg
{...props}
bbWidth={width}
bbHeight={height}
tintColor={color}
color={tint}
tintColor={tint}
onLayout={onLayout}
ref={this.refMethod}
style={[styles.svg, style, opacityStyle, dimensions]}
Expand Down

0 comments on commit 1eaf3a6

Please sign in to comment.