Skip to content

Commit

Permalink
fix: compatibility with reanimated color, fixes #1241
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Jan 18, 2020
1 parent 61bc9bd commit 4983766
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
8 changes: 6 additions & 2 deletions android/src/main/java/com/horcrux/svg/RenderableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public void setFill(@Nullable Dynamic fill) {
return;
}
ReadableType type = fill.getType();
if (type.equals(ReadableType.Array)) {
if (type.equals(ReadableType.Number)) {
this.fill = JavaOnlyArray.of(0, fill.asInt());
} else if (type.equals(ReadableType.Array)) {
this.fill = fill.asArray();
} else {
JavaOnlyArray arr = new JavaOnlyArray();
Expand Down Expand Up @@ -162,7 +164,9 @@ public void setStroke(@Nullable Dynamic strokeColors) {
return;
}
ReadableType type = strokeColors.getType();
if (type.equals(ReadableType.Array)) {
if (type.equals(ReadableType.Number)) {
stroke = JavaOnlyArray.of(0, strokeColors.asInt());
} else if (type.equals(ReadableType.Array)) {
stroke = strokeColors.asArray();
} else {
JavaOnlyArray arr = new JavaOnlyArray();
Expand Down
2 changes: 1 addition & 1 deletion ios/Brushes/RNSVGBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@property (nonatomic, strong) NSString* brushRef;

/* @abstract */
- (instancetype)initWithArray:(NSArray *)data NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithArray:(NSArray *)data;

/**
* @abstract
Expand Down
2 changes: 0 additions & 2 deletions ios/Brushes/RNSVGBrush.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ - (instancetype)initWithArray:(NSArray *)data
return [super init];
}

RCT_NOT_IMPLEMENTED(- (instancetype)init)

- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter bounds:(CGRect)bounds
{

Expand Down
2 changes: 2 additions & 0 deletions ios/Brushes/RNSVGSolidColorBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

@interface RNSVGSolidColorBrush : RNSVGBrush

- (instancetype)initWithNumber:(NSNumber *)number;

@end
8 changes: 8 additions & 0 deletions ios/Brushes/RNSVGSolidColorBrush.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ - (instancetype)initWithArray:(NSArray<RNSVGLength *> *)array
return self;
}

- (instancetype)initWithNumber:(NSNumber *)number
{
if ((self = [super init])) {
_color = CGColorRetain([RCTConvert CGColor:number]);
}
return self;
}

- (void)dealloc
{
CGColorRelease(_color);
Expand Down
3 changes: 3 additions & 0 deletions ios/Utils/RCTConvert+RNSVG.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ @implementation RCTConvert (RNSVG)

+ (RNSVGBrush *)RNSVGBrush:(id)json
{
if ([json isKindOfClass:[NSNumber class]]) {
return [[RNSVGSolidColorBrush alloc] initWithNumber:json];
}
if ([json isKindOfClass:[NSString class]]) {
NSString *value = [self NSString:json];
if (!RNSVGDigitRegEx) {
Expand Down

0 comments on commit 4983766

Please sign in to comment.