-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support PlatformColor #1561
Support PlatformColor #1561
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,48 +13,49 @@ | |
|
||
@implementation RNSVGSolidColorBrush | ||
{ | ||
CGColorRef _color; | ||
UIColor *_color; | ||
} | ||
|
||
- (instancetype)initWithArray:(NSArray<RNSVGLength *> *)array | ||
{ | ||
if ((self = [super initWithArray:array])) { | ||
_color = CGColorRetain([RCTConvert RNSVGCGColor:array offset:1]); | ||
_color = [RCTConvert RNSVGUIColor:array offset:1]; | ||
} | ||
return self; | ||
} | ||
|
||
- (instancetype)initWithNumber:(NSNumber *)number | ||
{ | ||
if ((self = [super init])) { | ||
_color = CGColorRetain([RCTConvert CGColor:number]); | ||
_color = [RCTConvert UIColor:number]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
CGColorRelease(_color); | ||
_color = nil; | ||
} | ||
|
||
- (CGColorRef)getColorWithOpacity:(CGFloat)opacity | ||
{ | ||
return CGColorCreateCopyWithAlpha(_color, opacity * CGColorGetAlpha(_color)); | ||
CGColorRef baseColor = _color.CGColor; | ||
CGColorRef color = CGColorCreateCopyWithAlpha(baseColor, opacity * CGColorGetAlpha(baseColor)); | ||
CGColorRelease(baseColor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not release it since it will release There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure about that? Why would releasing _baseColor affect _color? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, now I see, good catch 👍 |
||
return color; | ||
} | ||
|
||
- (BOOL)applyFillColor:(CGContextRef)context opacity:(CGFloat)opacity | ||
{ | ||
CGColorRef color = CGColorCreateCopyWithAlpha(_color, opacity * CGColorGetAlpha(_color)); | ||
CGColorRef color = [self getColorWithOpacity:opacity]; | ||
CGContextSetFillColorWithColor(context, color); | ||
CGColorRelease(color); | ||
return YES; | ||
} | ||
|
||
- (BOOL)applyStrokeColor:(CGContextRef)context opacity:(CGFloat)opacity | ||
{ | ||
CGColorRef color = CGColorCreateCopyWithAlpha(_color, opacity * CGColorGetAlpha(_color)); | ||
CGColorRef color = [self getColorWithOpacity:opacity]; | ||
CGContextSetStrokeColorWithColor(context, color); | ||
CGColorRelease(color); | ||
return YES; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as React from 'react'; | ||
import * as ReactNative from 'react-native'; | ||
import { GestureResponderEvent } from 'react-native'; | ||
import { GestureResponderEvent, OpaqueColorValue } from 'react-native'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this just be "ColorValue"? |
||
|
||
// Common props | ||
export type NumberProp = string | number; | ||
|
@@ -101,7 +101,7 @@ export type rgbaArray = ReadonlyArray<number>; | |
// int32ARGBColor = 0xaarrggbb | ||
export type int32ARGBColor = number; | ||
|
||
export type Color = int32ARGBColor | rgbaArray | string; | ||
export type Color = int32ARGBColor | rgbaArray | OpaqueColorValue | string; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we just replace the "Color" type altogether with "ColorValue" from react native? It should represent the same set of types of colors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not the same, from the type it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the impression that But also, I thought the idea of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can find the definition here: export type ColorValue = string | OpaqueColorValue; So it's not the same, and it can't be replaced as the way this library deals with colors is quite custom. I'm not the author of this library, but i guess it's partly due to color inheritance. If it was not dealing with colors in a custom way then this PR wouldn't be necessary. |
||
export interface FillProps { | ||
fill?: Color; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,16 @@ export default function extractBrush(color?: Color) { | |
return int32ARGBColor; | ||
} | ||
|
||
// iOS PlatformColor | ||
if ('semantic' in color) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think here we should also add a check for if |
||
return [0, color]; | ||
} | ||
|
||
// Android PlatformColor | ||
if ('resource_paths' in color) { | ||
return [0, color]; | ||
} | ||
Comment on lines
+43
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least on iOS, "semantic" isn't enough, because a color might be a DynamicColor instead. Could we instead do something like a type check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surviving in react-native, or surviving in this repo? I don't think it's going anywhere as long as PlatformColor exists. We also have a react-native-macos equivalent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant in |
||
|
||
console.warn(`"${color}" is not a valid color or brush`); | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should use
RNSVGColor
so it compiles onmacOS
.