mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 07:59:28 +00:00
Add gradientUnits support
This commit is contained in:
@@ -9,12 +9,9 @@
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "RNSVGPercentageConverter.h"
|
||||
#import "RNSVGBrushConverter.h"
|
||||
#import "RNSVGPainter.h"
|
||||
|
||||
@interface RNSVGBrush : NSObject
|
||||
{
|
||||
NSArray *_points;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) NSString* brushRef;
|
||||
|
||||
@@ -38,6 +35,6 @@
|
||||
* be clipped.
|
||||
* @abstract
|
||||
*/
|
||||
- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity brushConverter:(RNSVGBrushConverter *)brushConverter;
|
||||
- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter;
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
#import "RNSVGBrush.h"
|
||||
|
||||
#import <React/RCTDefines.h>
|
||||
|
||||
@implementation RNSVGBrush
|
||||
@@ -29,7 +28,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity brushConverter:(RNSVGBrushConverter *)brushConverter
|
||||
- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter
|
||||
{
|
||||
// abstract
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Horcrux.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTConvert+RNSVG.h"
|
||||
#import "RNSVGBrushType.h"
|
||||
|
||||
@interface RNSVGBrushConverter : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSArray<NSString *> *points;
|
||||
@property (nonatomic, copy) NSArray<NSNumber *> *colors;
|
||||
@property (nonatomic, assign) RNSVGBrushType type;
|
||||
|
||||
- (void) drawLinearGradient:(CGContextRef)context;
|
||||
|
||||
- (void) drawRidialGradient:(CGContextRef)context;
|
||||
|
||||
@end
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
kRNSVGUndefinedType,
|
||||
kRNSVGLinearGradient,
|
||||
kRNSVGRadialGradient,
|
||||
kRNSVGPattern
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Horcrux.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTConvert+RNSVG.h"
|
||||
#import "RNSVGBrushType.h"
|
||||
#import "RNSVGUnits.h"
|
||||
|
||||
@interface RNSVGPainter : NSObject
|
||||
|
||||
- (instancetype)initWithPointsArray:(NSArray<NSString *> *)pointsArray NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (void)paint:(CGContextRef)context;
|
||||
|
||||
- (void)setUnits:(RNSVGUnits)unit;
|
||||
|
||||
- (void)setUserSpaceBoundingBox:(CGRect)userSpaceBoundingBox;
|
||||
|
||||
- (void)setTransform:(CGAffineTransform)transform;
|
||||
|
||||
- (void)setLinearGradientColors:(NSArray<NSNumber *> *)colors;
|
||||
|
||||
- (void)setRadialGradientColors:(NSArray<NSNumber *> *)colors;
|
||||
|
||||
@end
|
||||
@@ -6,71 +6,150 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RNSVGBrushConverter.h"
|
||||
#import "RNSVGPainter.h"
|
||||
#import "RNSVGPercentageConverter.h"
|
||||
|
||||
@implementation RNSVGBrushConverter
|
||||
@implementation RNSVGPainter
|
||||
{
|
||||
NSArray<NSString *> *_points;
|
||||
NSArray<NSNumber *> *_colors;
|
||||
RNSVGBrushType _type;
|
||||
BOOL _useObjectBoundingBox;
|
||||
CGAffineTransform _transform;
|
||||
CGRect _userSpaceBoundingBox;
|
||||
}
|
||||
|
||||
- (void)drawLinearGradient:(CGContextRef)context
|
||||
- (instancetype)initWithPointsArray:(NSArray<NSString *> *)pointsArray
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
_points = pointsArray;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
|
||||
- (void)setUnits:(RNSVGUnits)unit
|
||||
{
|
||||
_useObjectBoundingBox = unit == kRNSVGUnitsObjectBoundingBox;
|
||||
}
|
||||
|
||||
- (void)setUserSpaceBoundingBox:(CGRect)userSpaceBoundingBox
|
||||
{
|
||||
_userSpaceBoundingBox = userSpaceBoundingBox;
|
||||
}
|
||||
|
||||
- (void)setTransform:(CGAffineTransform)transform
|
||||
{
|
||||
_transform = transform;
|
||||
}
|
||||
|
||||
- (void)setLinearGradientColors:(NSArray<NSNumber *> *)colors
|
||||
{
|
||||
if (_type != kRNSVGUndefinedType) {
|
||||
// todo: throw error
|
||||
return;
|
||||
}
|
||||
|
||||
_type = kRNSVGLinearGradient;
|
||||
_colors = colors;
|
||||
}
|
||||
|
||||
- (void)setRadialGradientColors:(NSArray<NSNumber *> *)colors
|
||||
{
|
||||
if (_type != kRNSVGUndefinedType) {
|
||||
// todo: throw error
|
||||
return;
|
||||
}
|
||||
|
||||
_type = kRNSVGRadialGradient;
|
||||
_colors = colors;
|
||||
}
|
||||
|
||||
- (void)paint:(CGContextRef)context
|
||||
{
|
||||
if (_type == kRNSVGLinearGradient) {
|
||||
[self paintLinearGradient:context];
|
||||
} else if (_type == kRNSVGRadialGradient) {
|
||||
[self paintRidialGradient:context];
|
||||
} else if (_type == kRNSVGPattern) {
|
||||
// todo:
|
||||
}
|
||||
}
|
||||
|
||||
- (CGRect)getPaintRect:(CGContextRef)context
|
||||
{
|
||||
CGRect rect = _useObjectBoundingBox ? CGContextGetClipBoundingBox(context) : _userSpaceBoundingBox;
|
||||
float height = CGRectGetHeight(rect);
|
||||
float width = CGRectGetWidth(rect);
|
||||
float x = 0.0;
|
||||
float y = 0.0;
|
||||
|
||||
if (_useObjectBoundingBox) {
|
||||
x = CGRectGetMinX(rect);
|
||||
y = CGRectGetMinY(rect);
|
||||
}
|
||||
|
||||
return CGRectMake(x, y, width, height);
|
||||
}
|
||||
|
||||
- (void)paintLinearGradient:(CGContextRef)context
|
||||
{
|
||||
|
||||
CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:self.colors offset:0]);
|
||||
CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:_colors offset:0]);
|
||||
CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
|
||||
|
||||
CGRect box = CGContextGetClipBoundingBox(context);
|
||||
float height = CGRectGetHeight(box);
|
||||
float width = CGRectGetWidth(box);
|
||||
float midX = CGRectGetMidX(box);
|
||||
float midY = CGRectGetMidY(box);
|
||||
float offsetX = (midX - width / 2);
|
||||
float offsetY = (midY - height / 2);
|
||||
CGRect rect = [self getPaintRect:context];
|
||||
float height = CGRectGetHeight(rect);
|
||||
float width = CGRectGetWidth(rect);
|
||||
float offsetX = CGRectGetMinX(rect);
|
||||
float offsetY = CGRectGetMinY(rect);
|
||||
|
||||
CGFloat x1 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:0]
|
||||
CGFloat x1 = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:0]
|
||||
relative:width
|
||||
offset:offsetX];
|
||||
CGFloat y1 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:1]
|
||||
CGFloat y1 = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:1]
|
||||
relative:height
|
||||
offset:offsetY];
|
||||
CGFloat x2 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:2]
|
||||
CGFloat x2 = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:2]
|
||||
relative:width
|
||||
offset:offsetX];
|
||||
CGFloat y2 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:3]
|
||||
CGFloat y2 = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:3]
|
||||
relative:height
|
||||
offset:offsetY];
|
||||
|
||||
|
||||
CGContextDrawLinearGradient(context, gradient, CGPointMake(x1, y1), CGPointMake(x2, y2), extendOptions);
|
||||
CGGradientRelease(gradient);
|
||||
}
|
||||
|
||||
- (void)drawRidialGradient:(CGContextRef)context
|
||||
- (void)paintRidialGradient:(CGContextRef)context
|
||||
{
|
||||
CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:self.colors offset:0]);
|
||||
CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:_colors offset:0]);
|
||||
CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
|
||||
|
||||
CGRect box = CGContextGetClipBoundingBox(context);
|
||||
float height = CGRectGetHeight(box);
|
||||
float width = CGRectGetWidth(box);
|
||||
float midX = CGRectGetMidX(box);
|
||||
float midY = CGRectGetMidY(box);
|
||||
float offsetX = (midX - width / 2);
|
||||
float offsetY = (midY - height / 2);
|
||||
CGRect rect = [self getPaintRect:context];
|
||||
float height = CGRectGetHeight(rect);
|
||||
float width = CGRectGetWidth(rect);
|
||||
float offsetX = CGRectGetMinX(rect);
|
||||
float offsetY = CGRectGetMinY(rect);
|
||||
|
||||
CGFloat rx = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:2]
|
||||
CGFloat rx = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:2]
|
||||
relative:width
|
||||
offset:0];
|
||||
CGFloat ry = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:3]
|
||||
CGFloat ry = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:3]
|
||||
relative:height
|
||||
offset:0];
|
||||
CGFloat fx = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:0]
|
||||
CGFloat fx = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:0]
|
||||
relative:width
|
||||
offset:offsetX];
|
||||
CGFloat fy = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:1]
|
||||
CGFloat fy = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:1]
|
||||
relative:height
|
||||
offset:offsetY] / (ry / rx);
|
||||
CGFloat cx = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:4]
|
||||
CGFloat cx = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:4]
|
||||
relative:width
|
||||
offset:offsetX];
|
||||
CGFloat cy = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:5]
|
||||
CGFloat cy = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:5]
|
||||
relative:height
|
||||
offset:offsetY] / (ry / rx);
|
||||
|
||||
@@ -8,10 +8,6 @@
|
||||
|
||||
#import "RNSVGBrush.h"
|
||||
|
||||
@interface RNSVGBaseBrush : RNSVGBrush
|
||||
|
||||
- (instancetype)initWithArray:(NSArray *)array;
|
||||
|
||||
- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity brushConverter:(RNSVGBrushConverter *)brushConverter;
|
||||
@interface RNSVGPainterBrush : RNSVGBrush
|
||||
|
||||
@end
|
||||
@@ -6,11 +6,12 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RNSVGBaseBrush.h"
|
||||
#import "RNSVGPainterBrush.h"
|
||||
#import "RNSVGPainter.h"
|
||||
#import "RCTConvert+RNSVG.h"
|
||||
#import <React/RCTLog.h>
|
||||
|
||||
@implementation RNSVGBaseBrush
|
||||
@implementation RNSVGPainterBrush
|
||||
|
||||
- (instancetype)initWithArray:(NSArray *)array
|
||||
{
|
||||
@@ -26,7 +27,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity brushConverter:(RNSVGBrushConverter *)brushConverter
|
||||
- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter
|
||||
{
|
||||
BOOL transparency = opacity < 1;
|
||||
if (transparency) {
|
||||
@@ -34,13 +35,7 @@
|
||||
CGContextBeginTransparencyLayer(context, NULL);
|
||||
}
|
||||
|
||||
if (brushConverter.type == kRNSVGLinearGradient) {
|
||||
[brushConverter drawLinearGradient:context];
|
||||
} else if (brushConverter.type == kRNSVGRadialGradient) {
|
||||
[brushConverter drawRidialGradient:context];
|
||||
} else if (brushConverter.type == kRNSVGPattern) {
|
||||
// todo:
|
||||
}
|
||||
[painter paint:context];
|
||||
|
||||
if (transparency) {
|
||||
CGContextEndTransparencyLayer(context);
|
||||
@@ -15,5 +15,7 @@
|
||||
@property (nonatomic, strong) NSString *x2;
|
||||
@property (nonatomic, strong) NSString *y2;
|
||||
@property (nonatomic, copy) NSArray<NSNumber *> *gradient;
|
||||
@property (nonatomic, assign)RNSVGUnits gradientUnits;
|
||||
@property (nonatomic, assign)CGAffineTransform gradientTransform;
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
#import "RNSVGLinearGradient.h"
|
||||
#import "RNSVGBrushConverter.h"
|
||||
#import "RNSVGPainter.h"
|
||||
#import "RNSVGBrushType.h"
|
||||
|
||||
@implementation RNSVGLinearGradient
|
||||
@@ -28,11 +28,18 @@
|
||||
|
||||
- (void)saveDefinition
|
||||
{
|
||||
RNSVGBrushConverter *converter = [[RNSVGBrushConverter alloc] init];
|
||||
converter.colors = self.gradient;
|
||||
converter.points = @[self.x1, self.y1, self.x2, self.y2];
|
||||
converter.type = kRNSVGLinearGradient;
|
||||
[[self getSvgView] defineBrushConverter:converter brushConverterName:self.name];
|
||||
NSArray<NSString *> *points = @[self.x1, self.y1, self.x2, self.y2];
|
||||
RNSVGPainter *painter = [[RNSVGPainter alloc] initWithPointsArray:points];
|
||||
[painter setUnits:self.gradientUnits];
|
||||
[painter setTransform:self.gradientTransform];
|
||||
[painter setLinearGradientColors:self.gradient];
|
||||
|
||||
RNSVGSvgView *svg = [self getSvgView];
|
||||
if (self.gradientUnits == kRNSVGUnitsUserSpaceOnUse) {
|
||||
[painter setUserSpaceBoundingBox:[svg getContextBounds]];
|
||||
}
|
||||
|
||||
[svg definePainter:painter painterName:self.name];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@@ -17,5 +17,7 @@
|
||||
@property (nonatomic, strong) NSString *cx;
|
||||
@property (nonatomic, strong) NSString *cy;
|
||||
@property (nonatomic, copy) NSArray<NSNumber *> *gradient;
|
||||
@property (nonatomic, assign)RNSVGUnits gradientUnits;
|
||||
@property (nonatomic, assign)CGAffineTransform gradientTransform;
|
||||
|
||||
@end
|
||||
|
||||
@@ -26,11 +26,18 @@
|
||||
|
||||
- (void)saveDefinition
|
||||
{
|
||||
RNSVGBrushConverter *converter = [[RNSVGBrushConverter alloc] init];
|
||||
converter.colors = self.gradient;
|
||||
converter.points = @[self.fx, self.fy, self.rx, self.ry, self.cx, self.cy];
|
||||
converter.type = kRNSVGRadialGradient;
|
||||
[[self getSvgView] defineBrushConverter:converter brushConverterName:self.name];
|
||||
NSArray<NSString *> *points = @[self.fx, self.fy, self.rx, self.ry, self.cx, self.cy];
|
||||
RNSVGPainter *painter = [[RNSVGPainter alloc] initWithPointsArray:points];
|
||||
[painter setUnits:self.gradientUnits];
|
||||
[painter setTransform:self.gradientTransform];
|
||||
[painter setRadialGradientColors:self.gradient];
|
||||
|
||||
RNSVGSvgView *svg = [self getSvgView];
|
||||
if (self.gradientUnits == kRNSVGUnitsUserSpaceOnUse) {
|
||||
[painter setUserSpaceBoundingBox:[svg getContextBounds]];
|
||||
}
|
||||
|
||||
[svg definePainter:painter painterName:self.name];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "RNSVGBrushCOnverter.h"
|
||||
#import "RNSVGPainter.h"
|
||||
#import "RNSVGContainer.h"
|
||||
#import "RNSVGVBMOS.h"
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
|
||||
- (RNSVGNode *)getDefinedTemplate:(NSString *)templateName;
|
||||
|
||||
- (void)defineBrushConverter:(RNSVGBrushConverter *)brushConverter brushConverterName:(NSString *)brushConverterName;
|
||||
- (void)definePainter:(RNSVGPainter *)painter painterName:(NSString *)painterName;
|
||||
|
||||
- (RNSVGBrushConverter *)getDefinedBrushConverter:(NSString *)brushConverterName;
|
||||
- (RNSVGPainter *)getDefinedPainter:(NSString *)painterName;
|
||||
|
||||
- (NSString *)getDataURL;
|
||||
|
||||
|
||||
+20
-20
@@ -13,9 +13,9 @@
|
||||
|
||||
@implementation RNSVGSvgView
|
||||
{
|
||||
NSMutableDictionary<NSString *, RNSVGNode *> *clipPaths;
|
||||
NSMutableDictionary<NSString *, RNSVGNode *> *templates;
|
||||
NSMutableDictionary<NSString *, RNSVGBrushConverter *> *brushConverters;
|
||||
NSMutableDictionary<NSString *, RNSVGNode *> *_clipPaths;
|
||||
NSMutableDictionary<NSString *, RNSVGNode *> *_templates;
|
||||
NSMutableDictionary<NSString *, RNSVGPainter *> *_painters;
|
||||
CGRect _boundingBox;
|
||||
CGAffineTransform _viewBoxTransform;
|
||||
}
|
||||
@@ -105,9 +105,9 @@
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
clipPaths = nil;
|
||||
templates = nil;
|
||||
brushConverters = nil;
|
||||
_clipPaths = nil;
|
||||
_templates = nil;
|
||||
_painters = nil;
|
||||
_boundingBox = rect;
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
|
||||
@@ -177,42 +177,42 @@
|
||||
|
||||
- (void)defineClipPath:(__kindof RNSVGNode *)clipPath clipPathName:(NSString *)clipPathName
|
||||
{
|
||||
if (!clipPaths) {
|
||||
clipPaths = [[NSMutableDictionary alloc] init];
|
||||
if (!_clipPaths) {
|
||||
_clipPaths = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
[clipPaths setObject:clipPath forKey:clipPathName];
|
||||
[_clipPaths setObject:clipPath forKey:clipPathName];
|
||||
}
|
||||
|
||||
- (RNSVGNode *)getDefinedClipPath:(NSString *)clipPathName
|
||||
{
|
||||
return clipPaths ? [clipPaths objectForKey:clipPathName] : nil;
|
||||
return _clipPaths ? [_clipPaths objectForKey:clipPathName] : nil;
|
||||
}
|
||||
|
||||
- (void)defineTemplate:(RNSVGNode *)template templateName:(NSString *)templateName
|
||||
{
|
||||
if (!templates) {
|
||||
templates = [[NSMutableDictionary alloc] init];
|
||||
if (!_templates) {
|
||||
_templates = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
[templates setObject:template forKey:templateName];
|
||||
[_templates setObject:template forKey:templateName];
|
||||
}
|
||||
|
||||
- (RNSVGNode *)getDefinedTemplate:(NSString *)templateName
|
||||
{
|
||||
return templates ? [templates objectForKey:templateName] : nil;
|
||||
return _templates ? [_templates objectForKey:templateName] : nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)defineBrushConverter:(RNSVGBrushConverter *)brushConverter brushConverterName:(NSString *)brushConverterName
|
||||
- (void)definePainter:(RNSVGPainter *)painter painterName:(NSString *)painterName
|
||||
{
|
||||
if (!brushConverters) {
|
||||
brushConverters = [[NSMutableDictionary alloc] init];
|
||||
if (!_painters) {
|
||||
_painters = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
[brushConverters setObject:brushConverter forKey:brushConverterName];
|
||||
[_painters setObject:painter forKey:painterName];
|
||||
}
|
||||
|
||||
- (RNSVGBrushConverter *)getDefinedBrushConverter:(NSString *)brushConverterName
|
||||
- (RNSVGPainter *)getDefinedPainter:(NSString *)painterName;
|
||||
{
|
||||
return brushConverters ? [brushConverters objectForKey:brushConverterName] : nil;
|
||||
return _painters ? [_painters objectForKey:painterName] : nil;
|
||||
}
|
||||
|
||||
- (CGRect)getContextBounds
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
0CF68B071AF0549300FF9E5C /* RNSVGRenderable.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF68AE21AF0549300FF9E5C /* RNSVGRenderable.m */; };
|
||||
0CF68B0B1AF0549300FF9E5C /* RNSVGBrush.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF68AEC1AF0549300FF9E5C /* RNSVGBrush.m */; };
|
||||
0CF68B0D1AF0549300FF9E5C /* RNSVGPattern.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF68AF01AF0549300FF9E5C /* RNSVGPattern.m */; };
|
||||
0CF68B0F1AF0549300FF9E5C /* RNSVGSolidColorBrush.m in Sources */ = {isa = PBXBuildFile; fileRef = 0CF68AF41AF0549300FF9E5C /* RNSVGSolidColorBrush.m */; };
|
||||
1023B48D1D3DDCCE0051496D /* RNSVGDefsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1023B48C1D3DDCCE0051496D /* RNSVGDefsManager.m */; };
|
||||
1023B4901D3DF4C40051496D /* RNSVGDefs.m in Sources */ = {isa = PBXBuildFile; fileRef = 1023B48F1D3DF4C40051496D /* RNSVGDefs.m */; };
|
||||
@@ -42,11 +41,11 @@
|
||||
10BEC1BD1D3F66F500FDCB19 /* RNSVGRadialGradient.m in Sources */ = {isa = PBXBuildFile; fileRef = 10BEC1BB1D3F66F500FDCB19 /* RNSVGRadialGradient.m */; };
|
||||
10BEC1C21D3F680F00FDCB19 /* RNSVGLinearGradientManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10BEC1BF1D3F680F00FDCB19 /* RNSVGLinearGradientManager.m */; };
|
||||
10BEC1C31D3F680F00FDCB19 /* RNSVGRadialGradientManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10BEC1C11D3F680F00FDCB19 /* RNSVGRadialGradientManager.m */; };
|
||||
10BEC1C61D3F7BD300FDCB19 /* RNSVGBrushConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 10BEC1C51D3F7BD300FDCB19 /* RNSVGBrushConverter.m */; };
|
||||
10BEC1C61D3F7BD300FDCB19 /* RNSVGPainter.m in Sources */ = {isa = PBXBuildFile; fileRef = 10BEC1C51D3F7BD300FDCB19 /* RNSVGPainter.m */; };
|
||||
10ED4A9B1CF065260078BC02 /* RNSVGClipPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ED4A9A1CF065260078BC02 /* RNSVGClipPath.m */; };
|
||||
10ED4A9E1CF0656A0078BC02 /* RNSVGClipPathManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ED4A9D1CF0656A0078BC02 /* RNSVGClipPathManager.m */; };
|
||||
10ED4AA21CF078830078BC02 /* RNSVGNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ED4AA11CF078830078BC02 /* RNSVGNode.m */; };
|
||||
10FDEEB21D3FB60500A5C46C /* RNSVGBaseBrush.m in Sources */ = {isa = PBXBuildFile; fileRef = 10FDEEB11D3FB60500A5C46C /* RNSVGBaseBrush.m */; };
|
||||
10FDEEB21D3FB60500A5C46C /* RNSVGPainterBrush.m in Sources */ = {isa = PBXBuildFile; fileRef = 10FDEEB11D3FB60500A5C46C /* RNSVGPainterBrush.m */; };
|
||||
7F08CE9A1E23476900650F83 /* RNSVGTextPathManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F08CE971E23476900650F83 /* RNSVGTextPathManager.m */; };
|
||||
7F08CE9B1E23476900650F83 /* RNSVGTSpanManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F08CE991E23476900650F83 /* RNSVGTSpanManager.m */; };
|
||||
7F08CEA01E23479700650F83 /* RNSVGTextPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F08CE9D1E23479700650F83 /* RNSVGTextPath.m */; };
|
||||
@@ -76,8 +75,6 @@
|
||||
0CF68AE21AF0549300FF9E5C /* RNSVGRenderable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGRenderable.m; sourceTree = "<group>"; };
|
||||
0CF68AEB1AF0549300FF9E5C /* RNSVGBrush.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGBrush.h; sourceTree = "<group>"; };
|
||||
0CF68AEC1AF0549300FF9E5C /* RNSVGBrush.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGBrush.m; sourceTree = "<group>"; };
|
||||
0CF68AEF1AF0549300FF9E5C /* RNSVGPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGPattern.h; sourceTree = "<group>"; };
|
||||
0CF68AF01AF0549300FF9E5C /* RNSVGPattern.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGPattern.m; sourceTree = "<group>"; };
|
||||
0CF68AF31AF0549300FF9E5C /* RNSVGSolidColorBrush.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGSolidColorBrush.h; sourceTree = "<group>"; };
|
||||
0CF68AF41AF0549300FF9E5C /* RNSVGSolidColorBrush.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGSolidColorBrush.m; sourceTree = "<group>"; };
|
||||
1023B48B1D3DDCCE0051496D /* RNSVGDefsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGDefsManager.h; sourceTree = "<group>"; };
|
||||
@@ -146,16 +143,16 @@
|
||||
10BEC1BF1D3F680F00FDCB19 /* RNSVGLinearGradientManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGLinearGradientManager.m; sourceTree = "<group>"; };
|
||||
10BEC1C01D3F680F00FDCB19 /* RNSVGRadialGradientManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGRadialGradientManager.h; sourceTree = "<group>"; };
|
||||
10BEC1C11D3F680F00FDCB19 /* RNSVGRadialGradientManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGRadialGradientManager.m; sourceTree = "<group>"; };
|
||||
10BEC1C41D3F793100FDCB19 /* RNSVGBrushConverter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSVGBrushConverter.h; sourceTree = "<group>"; };
|
||||
10BEC1C51D3F7BD300FDCB19 /* RNSVGBrushConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGBrushConverter.m; sourceTree = "<group>"; };
|
||||
10BEC1C41D3F793100FDCB19 /* RNSVGPainter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSVGPainter.h; sourceTree = "<group>"; };
|
||||
10BEC1C51D3F7BD300FDCB19 /* RNSVGPainter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGPainter.m; sourceTree = "<group>"; };
|
||||
10ED4A991CF065260078BC02 /* RNSVGClipPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGClipPath.h; path = Elements/RNSVGClipPath.h; sourceTree = "<group>"; };
|
||||
10ED4A9A1CF065260078BC02 /* RNSVGClipPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGClipPath.m; path = Elements/RNSVGClipPath.m; sourceTree = "<group>"; };
|
||||
10ED4A9C1CF0656A0078BC02 /* RNSVGClipPathManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGClipPathManager.h; sourceTree = "<group>"; };
|
||||
10ED4A9D1CF0656A0078BC02 /* RNSVGClipPathManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGClipPathManager.m; sourceTree = "<group>"; };
|
||||
10ED4AA01CF078830078BC02 /* RNSVGNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGNode.h; sourceTree = "<group>"; };
|
||||
10ED4AA11CF078830078BC02 /* RNSVGNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGNode.m; sourceTree = "<group>"; };
|
||||
10FDEEB01D3FB60500A5C46C /* RNSVGBaseBrush.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGBaseBrush.h; sourceTree = "<group>"; };
|
||||
10FDEEB11D3FB60500A5C46C /* RNSVGBaseBrush.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGBaseBrush.m; sourceTree = "<group>"; };
|
||||
10FDEEB01D3FB60500A5C46C /* RNSVGPainterBrush.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGPainterBrush.h; sourceTree = "<group>"; };
|
||||
10FDEEB11D3FB60500A5C46C /* RNSVGPainterBrush.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGPainterBrush.m; sourceTree = "<group>"; };
|
||||
10FDEEB31D3FBED400A5C46C /* RNSVGBrushType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGBrushType.h; sourceTree = "<group>"; };
|
||||
7F08CE961E23476900650F83 /* RNSVGTextPathManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGTextPathManager.h; sourceTree = "<group>"; };
|
||||
7F08CE971E23476900650F83 /* RNSVGTextPathManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGTextPathManager.m; sourceTree = "<group>"; };
|
||||
@@ -166,6 +163,7 @@
|
||||
7F08CE9E1E23479700650F83 /* RNSVGTSpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTSpan.h; path = Text/RNSVGTSpan.h; sourceTree = "<group>"; };
|
||||
7F08CE9F1E23479700650F83 /* RNSVGTSpan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGTSpan.m; path = Text/RNSVGTSpan.m; sourceTree = "<group>"; };
|
||||
7F08CEA31E23481F00650F83 /* RNSVGTextAnchor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextAnchor.h; path = Utils/RNSVGTextAnchor.h; sourceTree = "<group>"; };
|
||||
7F69160D1E3703D800DA6EDC /* RNSVGUnits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGUnits.h; path = Utils/RNSVGUnits.h; sourceTree = "<group>"; };
|
||||
7F9CDAF81E1F809C00E0C805 /* RNSVGPathParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGPathParser.h; path = Utils/RNSVGPathParser.h; sourceTree = "<group>"; };
|
||||
7F9CDAF91E1F809C00E0C805 /* RNSVGPathParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGPathParser.m; path = Utils/RNSVGPathParser.m; sourceTree = "<group>"; };
|
||||
7FC260CC1E3499BC00A39833 /* RNSVGViewBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGViewBox.h; path = Utils/RNSVGViewBox.h; sourceTree = "<group>"; };
|
||||
@@ -219,16 +217,14 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
10FDEEB31D3FBED400A5C46C /* RNSVGBrushType.h */,
|
||||
10FDEEB01D3FB60500A5C46C /* RNSVGBaseBrush.h */,
|
||||
10FDEEB11D3FB60500A5C46C /* RNSVGBaseBrush.m */,
|
||||
10FDEEB01D3FB60500A5C46C /* RNSVGPainterBrush.h */,
|
||||
10FDEEB11D3FB60500A5C46C /* RNSVGPainterBrush.m */,
|
||||
0CF68AEB1AF0549300FF9E5C /* RNSVGBrush.h */,
|
||||
0CF68AEC1AF0549300FF9E5C /* RNSVGBrush.m */,
|
||||
0CF68AEF1AF0549300FF9E5C /* RNSVGPattern.h */,
|
||||
0CF68AF01AF0549300FF9E5C /* RNSVGPattern.m */,
|
||||
0CF68AF31AF0549300FF9E5C /* RNSVGSolidColorBrush.h */,
|
||||
0CF68AF41AF0549300FF9E5C /* RNSVGSolidColorBrush.m */,
|
||||
10BEC1C41D3F793100FDCB19 /* RNSVGBrushConverter.h */,
|
||||
10BEC1C51D3F7BD300FDCB19 /* RNSVGBrushConverter.m */,
|
||||
10BEC1C41D3F793100FDCB19 /* RNSVGPainter.h */,
|
||||
10BEC1C51D3F7BD300FDCB19 /* RNSVGPainter.m */,
|
||||
);
|
||||
path = Brushes;
|
||||
sourceTree = "<group>";
|
||||
@@ -340,12 +336,13 @@
|
||||
1039D29A1CE7212C001E90A8 /* Utils */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FC260CC1E3499BC00A39833 /* RNSVGViewBox.h */,
|
||||
7FC260CD1E3499BC00A39833 /* RNSVGViewBox.m */,
|
||||
7F08CEA31E23481F00650F83 /* RNSVGTextAnchor.h */,
|
||||
1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */,
|
||||
7F69160D1E3703D800DA6EDC /* RNSVGUnits.h */,
|
||||
10ABC7381D43982B006CCF6E /* RNSVGVBMOS.h */,
|
||||
10ABC7371D439779006CCF6E /* RNSVGCGFCRule.h */,
|
||||
7F08CEA31E23481F00650F83 /* RNSVGTextAnchor.h */,
|
||||
7FC260CC1E3499BC00A39833 /* RNSVGViewBox.h */,
|
||||
7FC260CD1E3499BC00A39833 /* RNSVGViewBox.m */,
|
||||
1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */,
|
||||
1039D2AE1CE72F27001E90A8 /* RNSVGPercentageConverter.h */,
|
||||
1039D2AF1CE72F27001E90A8 /* RNSVGPercentageConverter.m */,
|
||||
7F9CDAF81E1F809C00E0C805 /* RNSVGPathParser.h */,
|
||||
@@ -421,7 +418,6 @@
|
||||
10BA0D491CE74E3D00887C2B /* RNSVGEllipse.m in Sources */,
|
||||
1039D28B1CE71EB7001E90A8 /* RNSVGPath.m in Sources */,
|
||||
7F08CEA01E23479700650F83 /* RNSVGTextPath.m in Sources */,
|
||||
0CF68B0D1AF0549300FF9E5C /* RNSVGPattern.m in Sources */,
|
||||
1023B4931D3DF5060051496D /* RNSVGUse.m in Sources */,
|
||||
10BEC1C21D3F680F00FDCB19 /* RNSVGLinearGradientManager.m in Sources */,
|
||||
1039D2951CE71EC2001E90A8 /* RNSVGText.m in Sources */,
|
||||
@@ -429,7 +425,7 @@
|
||||
0CF68B071AF0549300FF9E5C /* RNSVGRenderable.m in Sources */,
|
||||
1039D2891CE71EB7001E90A8 /* RNSVGGroup.m in Sources */,
|
||||
10ED4A9E1CF0656A0078BC02 /* RNSVGClipPathManager.m in Sources */,
|
||||
10BEC1C61D3F7BD300FDCB19 /* RNSVGBrushConverter.m in Sources */,
|
||||
10BEC1C61D3F7BD300FDCB19 /* RNSVGPainter.m in Sources */,
|
||||
10ED4AA21CF078830078BC02 /* RNSVGNode.m in Sources */,
|
||||
10ED4A9B1CF065260078BC02 /* RNSVGClipPath.m in Sources */,
|
||||
10BA0D3E1CE74E3100887C2B /* RNSVGSvgViewManager.m in Sources */,
|
||||
@@ -456,7 +452,7 @@
|
||||
7FC260CE1E3499BC00A39833 /* RNSVGViewBox.m in Sources */,
|
||||
7F08CEA11E23479700650F83 /* RNSVGTSpan.m in Sources */,
|
||||
10BA0D4A1CE74E3D00887C2B /* RNSVGLine.m in Sources */,
|
||||
10FDEEB21D3FB60500A5C46C /* RNSVGBaseBrush.m in Sources */,
|
||||
10FDEEB21D3FB60500A5C46C /* RNSVGPainterBrush.m in Sources */,
|
||||
1039D28C1CE71EB7001E90A8 /* RNSVGSvgView.m in Sources */,
|
||||
1023B4961D3DF57D0051496D /* RNSVGUseManager.m in Sources */,
|
||||
1023B48D1D3DDCCE0051496D /* RNSVGDefsManager.m in Sources */,
|
||||
|
||||
@@ -175,7 +175,6 @@
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CGPathDrawingMode mode = kCGPathStroke;
|
||||
BOOL fillColor = NO;
|
||||
[self clip:context];
|
||||
@@ -193,7 +192,7 @@
|
||||
CGContextClip(context);
|
||||
[self.fill paint:context
|
||||
opacity:self.fillOpacity
|
||||
brushConverter:[[self getSvgView] getDefinedBrushConverter:self.fill.brushRef]
|
||||
painter:[[self getSvgView] getDefinedPainter:self.fill.brushRef]
|
||||
];
|
||||
CGContextRestoreGState(context);
|
||||
|
||||
@@ -237,7 +236,7 @@
|
||||
|
||||
[self.stroke paint:context
|
||||
opacity:self.strokeOpacity
|
||||
brushConverter:[[self getSvgView] getDefinedBrushConverter:self.stroke.brushRef]
|
||||
painter:[[self getSvgView] getDefinedPainter:self.stroke.brushRef]
|
||||
];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#import "RNSVGCGFCRule.h"
|
||||
#import "RNSVGVBMOS.h"
|
||||
#import "RNSVGTextAnchor.h"
|
||||
#import "RNSVGUnits.h"
|
||||
#import "RNSVGPathParser.h"
|
||||
|
||||
@class RNSVGBrush;
|
||||
@@ -23,6 +24,7 @@
|
||||
+ (RNSVGTextAnchor)RNSVGTextAnchor:(id)json;
|
||||
+ (RNSVGCGFCRule)RNSVGCGFCRule:(id)json;
|
||||
+ (RNSVGVBMOS)RNSVGVBMOS:(id)json;
|
||||
+ (RNSVGUnits)RNSVGUnits:(id)json;
|
||||
+ (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json;
|
||||
+ (RNSVGBrush *)RNSVGBrush:(id)json;
|
||||
+ (RNSVGPathParser *)RNSVGCGPath:(NSString *)d;
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
|
||||
#import "RCTConvert+RNSVG.h"
|
||||
|
||||
#import "RNSVGBaseBrush.h"
|
||||
#import "RNSVGPattern.h"
|
||||
#import "RNSVGPainterBrush.h"
|
||||
#import "RNSVGSolidColorBrush.h"
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTFont.h>
|
||||
@@ -34,6 +33,11 @@ RCT_ENUM_CONVERTER(RNSVGTextAnchor, (@{
|
||||
@"end": @(kRNSVGTextAnchorEnd)
|
||||
}), kRNSVGTextAnchorAuto, intValue)
|
||||
|
||||
RCT_ENUM_CONVERTER(RNSVGUnits, (@{
|
||||
@"objectBoundingBox": @(kRNSVGUnitsObjectBoundingBox),
|
||||
@"userSpaceOnUse": @(kRNSVGUnitsUserSpaceOnUse),
|
||||
}), kRNSVGUnitsObjectBoundingBox, intValue)
|
||||
|
||||
+ (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json
|
||||
{
|
||||
NSArray *arr = [self NSNumberArray:json];
|
||||
@@ -66,7 +70,7 @@ RCT_ENUM_CONVERTER(RNSVGTextAnchor, (@{
|
||||
// We should memoize colors but look ups may be just as expensive.
|
||||
return [[RNSVGSolidColorBrush alloc] initWithArray:arr];
|
||||
case 1: // brush
|
||||
return [[RNSVGBaseBrush alloc] initWithArray:arr];
|
||||
return [[RNSVGPainterBrush alloc] initWithArray:arr];
|
||||
default:
|
||||
RCTLogError(@"Unknown brush type: %zd", type);
|
||||
return nil;
|
||||
@@ -112,8 +116,8 @@ RCT_ENUM_CONVERTER(RNSVGTextAnchor, (@{
|
||||
RNSVGCGFloatArray colorsAndOffsets = [self RNSVGCGFloatArray:arr];
|
||||
size_t stops = colorsAndOffsets.count / 5;
|
||||
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
|
||||
|
||||
|
||||
|
||||
|
||||
CGGradientRef gradient = CGGradientCreateWithColorComponents(
|
||||
rgb,
|
||||
colorsAndOffsets.array,
|
||||
|
||||
@@ -20,7 +20,7 @@ static NSRegularExpression* percentageRegExp;
|
||||
+ (CGFloat)stringToFloat:(NSString *)string relative:(CGFloat)relative offset:(CGFloat)offset
|
||||
{
|
||||
if (![self isPercentage:string]) {
|
||||
return [string floatValue];
|
||||
return [string floatValue] + offset;
|
||||
} else {
|
||||
return [self percentageToFloat:string relative:relative offset:offset];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Horcrux.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
typedef CF_ENUM(int32_t, RNSVGUnits) {
|
||||
kRNSVGUnitsObjectBoundingBox,
|
||||
kRNSVGUnitsUserSpaceOnUse
|
||||
};
|
||||
@@ -23,5 +23,7 @@ RCT_EXPORT_VIEW_PROPERTY(y1, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(x2, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(y2, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(gradient, NSArray<NSNumber *>)
|
||||
RCT_EXPORT_VIEW_PROPERTY(gradientUnits, RNSVGUnits)
|
||||
RCT_EXPORT_VIEW_PROPERTY(gradientTransform, CGAffineTransform)
|
||||
|
||||
@end
|
||||
|
||||
@@ -25,5 +25,7 @@ RCT_EXPORT_VIEW_PROPERTY(ry, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(cx, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(cy, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(gradient, NSArray<NSNumber *>)
|
||||
RCT_EXPORT_VIEW_PROPERTY(gradientUnits, RNSVGUnits)
|
||||
RCT_EXPORT_VIEW_PROPERTY(gradientTransform, CGAffineTransform)
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user