-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
feat: linear gradient android #45433
Changes from 1 commit
7f84c01
19a21d3
f7ac2c7
1b50d8a
b75d4af
d79e1d3
d38772c
f382d98
6ffd05d
1d6f728
1ee4743
9cf5c15
badf935
d4e1436
6c0fe54
3df8f0e
98c6cf6
0c4e20a
62aa6b3
cfa017f
7531702
0cc8e89
8b43b07
b944b8f
c29529f
085262c
6592715
1cb92de
2557da0
f3c5aa3
28034d4
2f1bf9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ const TO_BOTTOM_START_END_POINTS = { | |
end: {x: 0.5, y: 1}, | ||
}; | ||
|
||
export type BackgroundPrimitive = { | ||
export type BackgroundImagePrimitive = { | ||
type: 'linearGradient', | ||
start: {x: number, y: number}, | ||
end: {x: number, y: number}, | ||
|
@@ -36,14 +36,14 @@ export type BackgroundPrimitive = { | |
}>, | ||
}; | ||
|
||
export default function processBackground( | ||
background: $ReadOnlyArray<BackgroundPrimitive> | string, | ||
): $ReadOnlyArray<BackgroundPrimitive> { | ||
if (typeof background === 'string') { | ||
const parsedBackground = parseCSSLinearGradient(background); | ||
return parsedBackground; | ||
} else if (Array.isArray(background)) { | ||
const parsedBackground = background.map(bg => { | ||
export default function processBackgroundImage( | ||
backgroundImage: $ReadOnlyArray<BackgroundImagePrimitive> | 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 you add handling for nullish input? Recently hit us somewhere else. |
||
): $ReadOnlyArray<BackgroundImagePrimitive> { | ||
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. The output has some more guarantees that the input doesn't. E.g. output of processor |
||
if (typeof backgroundImage === 'string') { | ||
const parsedBackgroundImage = parseCSSLinearGradient(backgroundImage); | ||
return parsedBackgroundImage; | ||
} else if (Array.isArray(backgroundImage)) { | ||
const parsedBackgroundImage = backgroundImage.map(bg => { | ||
return { | ||
type: bg.type, | ||
start: bg.start, | ||
|
@@ -57,15 +57,15 @@ export default function processBackground( | |
}), | ||
}; | ||
}); | ||
return parsedBackground; | ||
return parsedBackgroundImage; | ||
} | ||
|
||
return []; | ||
} | ||
|
||
function parseCSSLinearGradient( | ||
cssString: 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. Does this handle case insensitivity correctly? 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. Good catch. It didn't, fixed and added testcases. |
||
): $ReadOnlyArray<BackgroundPrimitive> { | ||
): $ReadOnlyArray<BackgroundImagePrimitive> { | ||
const gradients = []; | ||
let match; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,12 +89,12 @@ public void setTVPreferredFocus(ReactViewGroup view, boolean hasTVPreferredFocus | |
} | ||
} | ||
|
||
@ReactProp(name = ViewProps.BACKGROUND) | ||
public void setBackground(ReactViewGroup view, @Nullable ReadableArray background) { | ||
if (background != null && background.size() > 0) { | ||
CSSGradient[] cssGradients = new CSSGradient[background.size()]; | ||
for (int i = 0; i < background.size(); i++) { | ||
ReadableMap gradientMap = background.getMap(i); | ||
@ReactProp(name = ViewProps.BACKGROUND_IMAGE) | ||
public void setBackgroundImage(ReactViewGroup view, @Nullable ReadableArray backgroundImage) { | ||
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. After this lands, this change will intersect a bit with another one, where I have been refactoring to be able to eventually apply background styles as part of BaseViewManager. bbcca54 This also enables the infra for 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. It is kind of similar to iOS view layers. Exciting! |
||
if (backgroundImage != null && backgroundImage.size() > 0) { | ||
CSSGradient[] cssGradients = new CSSGradient[backgroundImage.size()]; | ||
for (int i = 0; i < backgroundImage.size(); i++) { | ||
ReadableMap gradientMap = backgroundImage.getMap(i); | ||
cssGradients[i] = new CSSGradient(gradientMap); | ||
} | ||
view.setGradients(cssGradients); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,13 +166,13 @@ BaseViewProps::BaseViewProps( | |
"experimental_filter", | ||
sourceProps.filter, | ||
{})), | ||
background( | ||
CoreFeatures::enablePropIteratorSetter ? sourceProps.background | ||
backgroundImage( | ||
CoreFeatures::enablePropIteratorSetter ? sourceProps.backgroundImage | ||
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. Please also add to the area around
|
||
: convertRawProp( | ||
context, | ||
rawProps, | ||
"background", | ||
sourceProps.background, | ||
"experimental_backgroundImage", | ||
sourceProps.backgroundImage, | ||
{})), | ||
mixBlendMode( | ||
CoreFeatures::enablePropIteratorSetter | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ void ViewShadowNode::initialize() noexcept { | |
viewProps.importantForAccessibility != ImportantForAccessibility::Auto || | ||
viewProps.removeClippedSubviews || viewProps.cursor != Cursor::Auto || | ||
!viewProps.filter.empty() || !viewProps.mixBlendMode.empty() || | ||
!viewProps.background.empty() || | ||
!viewProps.backgroundImage.empty() || | ||
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. This is not the only prop guilty of this, but I think this one should go in |
||
HostPlatformViewTraitsInitializer::formsStackingContext(viewProps); | ||
|
||
bool formsView = formsStackingContext || | ||
|
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.
Related to comment below about keeping this off of BaseViewManager, if we start with just
<View>
, could we keep local to that view manager and viewconfig?