Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/react-native/React/Fabric/Utils/RCTRadialGradient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ + (CALayer *)gradientLayerWithSize:(CGSize)size gradient:(const RadialGradient &
bool isCircle = (gradient.shape == RadialGradientShape::Circle);
auto [radiusX, radiusY] =
GetRadialGradientRadius(isCircle, gradient.size, centerPoint.x, centerPoint.y, size.width, size.height);
const auto gradientLineLength = std::max(radiusX, radiusY);
auto colorStops = [RCTGradientUtils getFixedColorStops:gradient.colorStops gradientLineLength:gradientLineLength];
// Length stops resolve against radiusX: the gradient line starts at the center and "extends
// toward the right". https://drafts.csswg.org/css-images-3/#radial-color-stops
auto colorStops = [RCTGradientUtils getFixedColorStops:gradient.colorStops gradientLineLength:radiusX];
// Unlike negative stops, stops past the ending shape stay visible outside it, so the radius grows to fit them.
const Float radiusScale = colorStops.empty() ? 1 : std::max<Float>(colorStops.back().position.value_or(1), 1);
colorStops = [RCTGradientUtils clipColorStops:colorStops end:radiusScale];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ internal class RadialGradient(

val (radiusX, radiusY) = calculateRadius(centerX, centerY, width, height)

val fixedStops = ColorStopUtils.getFixedColorStops(colorStops, max(radiusX, radiusY))
// Length stops resolve against radiusX: the gradient line starts at the center and "extends
// toward the right". https://drafts.csswg.org/css-images-3/#radial-color-stops
val fixedStops = ColorStopUtils.getFixedColorStops(colorStops, radiusX)
// Unlike negative stops, stops past the ending shape stay visible outside it, so the radius
// grows to fit them.
val radiusScale = max(fixedStops.lastOrNull()?.position ?: 1f, 1f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,25 @@ exports.examples = [
);
},
},
{
title: 'Length color stops on a tall ellipse',
description:
'Length stops are measured along the horizontal radius: red reaches 40px right and 120px down.',
name: 'length-color-stops-tall-ellipse',
render(): React.Node {
return (
<GradientBox
testID="radial-gradient-length-color-stops-tall-ellipse"
style={{
backgroundImage:
'radial-gradient(ellipse 50px 150px at center, red 40px, blue 40px)',
width: 100,
height: 300,
}}
/>
);
},
},
{
title: 'Color stops outside 0–100%',
name: 'out-of-range-color-stops',
Expand Down
Loading