From 498376678ea098eea9380f98b0e8eddd267b2fd1 Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Sat, 18 Jan 2020 02:32:00 +0200 Subject: [PATCH] fix: compatibility with reanimated color, fixes #1241 --- android/src/main/java/com/horcrux/svg/RenderableView.java | 8 ++++++-- ios/Brushes/RNSVGBrush.h | 2 +- ios/Brushes/RNSVGBrush.m | 2 -- ios/Brushes/RNSVGSolidColorBrush.h | 2 ++ ios/Brushes/RNSVGSolidColorBrush.m | 8 ++++++++ ios/Utils/RCTConvert+RNSVG.m | 3 +++ 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/RenderableView.java b/android/src/main/java/com/horcrux/svg/RenderableView.java index 8b758e9b..e7769b2a 100644 --- a/android/src/main/java/com/horcrux/svg/RenderableView.java +++ b/android/src/main/java/com/horcrux/svg/RenderableView.java @@ -116,7 +116,9 @@ abstract public class RenderableView extends VirtualView { 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(); @@ -162,7 +164,9 @@ abstract public class RenderableView extends VirtualView { 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(); diff --git a/ios/Brushes/RNSVGBrush.h b/ios/Brushes/RNSVGBrush.h index 0bc84d2c..edf3fc40 100644 --- a/ios/Brushes/RNSVGBrush.h +++ b/ios/Brushes/RNSVGBrush.h @@ -15,7 +15,7 @@ @property (nonatomic, strong) NSString* brushRef; /* @abstract */ -- (instancetype)initWithArray:(NSArray *)data NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithArray:(NSArray *)data; /** * @abstract diff --git a/ios/Brushes/RNSVGBrush.m b/ios/Brushes/RNSVGBrush.m index c988aedc..e7c8ae66 100644 --- a/ios/Brushes/RNSVGBrush.m +++ b/ios/Brushes/RNSVGBrush.m @@ -16,8 +16,6 @@ return [super init]; } -RCT_NOT_IMPLEMENTED(- (instancetype)init) - - (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter bounds:(CGRect)bounds { diff --git a/ios/Brushes/RNSVGSolidColorBrush.h b/ios/Brushes/RNSVGSolidColorBrush.h index f7c30d07..6e12929c 100644 --- a/ios/Brushes/RNSVGSolidColorBrush.h +++ b/ios/Brushes/RNSVGSolidColorBrush.h @@ -10,4 +10,6 @@ @interface RNSVGSolidColorBrush : RNSVGBrush +- (instancetype)initWithNumber:(NSNumber *)number; + @end diff --git a/ios/Brushes/RNSVGSolidColorBrush.m b/ios/Brushes/RNSVGSolidColorBrush.m index 2e1178d6..82eda8a0 100644 --- a/ios/Brushes/RNSVGSolidColorBrush.m +++ b/ios/Brushes/RNSVGSolidColorBrush.m @@ -24,6 +24,14 @@ return self; } +- (instancetype)initWithNumber:(NSNumber *)number +{ + if ((self = [super init])) { + _color = CGColorRetain([RCTConvert CGColor:number]); + } + return self; +} + - (void)dealloc { CGColorRelease(_color); diff --git a/ios/Utils/RCTConvert+RNSVG.m b/ios/Utils/RCTConvert+RNSVG.m index c4f1a04f..94ef7eb8 100644 --- a/ios/Utils/RCTConvert+RNSVG.m +++ b/ios/Utils/RCTConvert+RNSVG.m @@ -36,6 +36,9 @@ RCT_ENUM_CONVERTER(RNSVGUnits, (@{ + (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) {