From c52f12fa41c8286d5d58860df6bf1e01568683d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nishan=20=28o=5E=E2=96=BD=5Eo=29?= Date: Fri, 20 Nov 2026 10:00:49 +0530 Subject: [PATCH] Resolve radial gradient length color stops against the horizontal radius Length color stops in an elliptical radial gradient were resolved against max(radiusX, radiusY), while the ellipse is drawn with radiusX as its horizontal radius. On an ellipse taller than wide, every length stop landed closer to the center than in browsers. CSS Images 3 places radial color stops on a gradient line that starts at the center and "extends toward the right", so length stops resolve against radiusX: https://drafts.csswg.org/css-images-3/#radial-color-stops Fixes #59968. --- .../React/Fabric/Utils/RCTRadialGradient.mm | 5 +++-- .../react/uimanager/style/RadialGradient.kt | 4 +++- .../RadialGradient/RadialGradientExample.js | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) 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',