diff --git a/packages/react-native/React/Fabric/Utils/RCTRadialGradient.mm b/packages/react-native/React/Fabric/Utils/RCTRadialGradient.mm index 2080cc27e376..8c544f26eba4 100644 --- a/packages/react-native/React/Fabric/Utils/RCTRadialGradient.mm +++ b/packages/react-native/React/Fabric/Utils/RCTRadialGradient.mm @@ -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(colorStops.back().position.value_or(1), 1); colorStops = [RCTGradientUtils clipColorStops:colorStops end:radiusScale]; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/RadialGradient.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/RadialGradient.kt index bae71f4e032f..a8bc15c32ce2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/RadialGradient.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/style/RadialGradient.kt @@ -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) diff --git a/packages/rn-tester/js/examples/RadialGradient/RadialGradientExample.js b/packages/rn-tester/js/examples/RadialGradient/RadialGradientExample.js index 5fedc19207a4..7dc7a8054ba4 100644 --- a/packages/rn-tester/js/examples/RadialGradient/RadialGradientExample.js +++ b/packages/rn-tester/js/examples/RadialGradient/RadialGradientExample.js @@ -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 ( + + ); + }, + }, { title: 'Color stops outside 0–100%', name: 'out-of-range-color-stops',