mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-02 06:35:04 +00:00
feat: get currentColor from caller instead of parent (#2521)
# Summary Fixes #2520 When an element uses `currentColor`, it should look for color in its caller, not in its parent. Example: ```svg <Svg width="100" height="100" viewBox="0 0 100 100" color="red"> <Defs color="blue"> <G color="green"> <Rect id="a" x="0" y="0" width="50" height="50" fill="currentColor"/> </G> </Defs> <G color="pink"> <Use href="#a"/> <!-- #1 --> </G> <Use href="#a" transform="translate(25 25)"/> <!-- #2 --> <G color="green"> <Use href="#a" transform="translate(50 50)"/> <!-- #3 --> </G> </Svg> ``` * `#1` should be **pink** * `#2` should be **red** * `#3` should be **green**  ## Test Plan Example app -> test -> Test2520 ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | MacOS | ✅ | | Android | ✅ |
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#import "RNSVGUIKit.h"
|
||||
|
||||
@implementation RNSVGView {
|
||||
NSColor *_tintColor;
|
||||
}
|
||||
|
||||
- (CGPoint)center
|
||||
@@ -20,29 +19,6 @@
|
||||
self.frame = CGRectMake(xOrigin, yOrigin, frameRect.size.width, frameRect.size.height);
|
||||
}
|
||||
|
||||
- (NSColor *)tintColor
|
||||
{
|
||||
if (_tintColor != nil) {
|
||||
return _tintColor;
|
||||
}
|
||||
|
||||
// To mimic iOS's tintColor, we crawl up the view hierarchy until either:
|
||||
// (a) we find a valid color
|
||||
// (b) we reach a view that isn't an RNSVGView
|
||||
NSView *parentView = [self superview];
|
||||
if ([parentView isKindOfClass:[RNSVGView class]]) {
|
||||
return [(RNSVGView *)parentView tintColor];
|
||||
} else {
|
||||
return [NSColor controlAccentColor];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTintColor:(NSColor *)tintColor
|
||||
{
|
||||
_tintColor = tintColor;
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSImage (RNSVGMacOSExtensions)
|
||||
|
||||
Reference in New Issue
Block a user