Support native animation of fill and stroke

This commit is contained in:
Mikael Sand
2018-08-17 22:09:47 +03:00
parent 0eb501d5e8
commit 3879c90bd8
4 changed files with 258 additions and 206 deletions
+20
View File
@@ -13,6 +13,8 @@
#import <React/RCTLog.h>
#import <React/RCTFont.h>
NSRegularExpression *regex;
@implementation RCTConvert (RNSVG)
RCT_ENUM_CONVERTER(RNSVGCGFCRule, (@{
@@ -54,6 +56,24 @@ RCT_ENUM_CONVERTER(RNSVGUnits, (@{
+ (RNSVGBrush *)RNSVGBrush:(id)json
{
if ([json isKindOfClass:[NSString class]]) {
NSString *value = [self NSString:json];
if (!regex) {
regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9.-]+" options:NSRegularExpressionCaseInsensitive error:nil];
}
NSArray<NSTextCheckingResult*> *_matches = [regex matchesInString:value options:0 range:NSMakeRange(0, [value length])];
NSMutableArray *output = [NSMutableArray array];
NSUInteger i = 0;
[output addObject:[NSNumber numberWithInteger:0]];
for (NSTextCheckingResult *match in _matches) {
NSString* strNumber = [value substringWithRange:match.range];
[output addObject:[NSNumber numberWithDouble:(i++ < 3 ? strNumber.doubleValue / 255 : strNumber.doubleValue)]];
}
if ([output count] < 5) {
[output addObject:[NSNumber numberWithDouble:1]];
}
return [[RNSVGSolidColorBrush alloc] initWithArray:output];
}
NSArray *arr = [self NSArray:json];
NSUInteger type = [self NSUInteger:arr.firstObject];