-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement support for context-fill and context-stroke color
- Loading branch information
Showing
8 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) 2015-present, react-native-community. | ||
* 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 "RNSVGBrush.h" | ||
|
||
@interface RNSVGContextBrush : RNSVGBrush | ||
|
||
- (instancetype)initFill; | ||
- (instancetype)initStroke; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Copyright (c) 2015-present, react-native-community. | ||
* 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 "RNSVGContextBrush.h" | ||
#import "RNSVGRenderable.h" | ||
#import "RNSVGNode.h" | ||
|
||
#import "RCTConvert+RNSVG.h" | ||
#import <React/RCTLog.h> | ||
|
||
@implementation RNSVGContextBrush | ||
{ | ||
BOOL _isStroke; | ||
} | ||
|
||
- (instancetype)initFill | ||
{ | ||
if ((self = [super initWithArray:nil])) { | ||
_isStroke = NO; | ||
} | ||
return self; | ||
} | ||
|
||
- (instancetype)initStroke | ||
{ | ||
if ((self = [super initWithArray:nil])) { | ||
_isStroke = YES; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
} | ||
|
||
- (BOOL)applyFillColor:(CGContextRef)context opacity:(CGFloat)opacity | ||
{ | ||
RNSVGRenderable *element = RNSVGRenderable.contextElement; | ||
if (!element) { | ||
return NO; | ||
} | ||
|
||
RNSVGBrush *brush = _isStroke ? element.stroke : element.fill; | ||
|
||
BOOL fillColor; | ||
|
||
if (brush.class == RNSVGBrush.class) { | ||
CGContextSetFillColorWithColor(context, [element.tintColor CGColor]); | ||
fillColor = YES; | ||
} else { | ||
fillColor = [brush applyFillColor:context opacity:opacity]; | ||
} | ||
|
||
return fillColor; | ||
} | ||
|
||
|
||
|
||
- (BOOL)applyStrokeColor:(CGContextRef)context opacity:(CGFloat)opacity | ||
{ | ||
RNSVGRenderable *element = RNSVGRenderable.contextElement; | ||
if (!element) { | ||
return NO; | ||
} | ||
|
||
RNSVGBrush *brush = _isStroke ? element.stroke : element.fill; | ||
|
||
BOOL strokeColor; | ||
|
||
if (brush.class == RNSVGBrush.class) { | ||
CGContextSetStrokeColorWithColor(context, [element.tintColor CGColor]); | ||
strokeColor = YES; | ||
} else { | ||
strokeColor = [brush applyStrokeColor:context opacity:opacity]; | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters