From 64e8ef9d6b1f9587de9e0b8064e684793c1723ea Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Mon, 18 May 2026 12:20:24 -0700 Subject: [PATCH] Fix infinite recomposition in `Text.foregroundStyle(LinearGradient())` Fixes https://github.com/skiptools/skip-ui/issues/437 --- Sources/SkipUI/SkipUI/Graphics/Gradient.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/SkipUI/SkipUI/Graphics/Gradient.swift b/Sources/SkipUI/SkipUI/Graphics/Gradient.swift index f50a467b..bc955897 100644 --- a/Sources/SkipUI/SkipUI/Graphics/Gradient.swift +++ b/Sources/SkipUI/SkipUI/Graphics/Gradient.swift @@ -141,7 +141,9 @@ public struct LinearGradient : ShapeStyle, Renderable { @Composable override func asBrush(opacity: Double, animationContext: ComposeContext?) -> Brush? { let stops = gradient.colorStops(opacity: opacity) - return LinearGradientShaderBrush(colorStops: stops, startPoint: startPoint, endPoint: endPoint) + return remember(gradient, startPoint, endPoint, opacity) { + LinearGradientShaderBrush(colorStops: stops, startPoint: startPoint, endPoint: endPoint) + } } private struct LinearGradientShaderBrush: ShaderBrush { @@ -207,7 +209,9 @@ public struct EllipticalGradient : ShapeStyle, Renderable { @Composable override func asBrush(opacity: Double, animationContext: ComposeContext?) -> Brush? { let stops = gradient.colorStops(opacity: opacity) - return RadialGradientShaderBrush(colorStops: stops, center: center, startFraction: startFraction, endFraction: endFraction) + return remember(gradient, center, startFraction, endFraction, opacity) { + RadialGradientShaderBrush(colorStops: stops, center: center, startFraction: startFraction, endFraction: endFraction) + } } private struct RadialGradientShaderBrush: ShaderBrush { @@ -275,7 +279,9 @@ public struct RadialGradient : ShapeStyle, Renderable { let start = with(density) { startRadius.dp.toPx() } let end = with(density) { endRadius.dp.toPx() } let stops = gradient.colorStops(opacity: opacity) - return RadialGradientShaderBrush(colorStops: stops, center: center, startRadius: start, endRadius: end) + return remember(gradient, center, start, end, opacity) { + RadialGradientShaderBrush(colorStops: stops, center: center, startRadius: start, endRadius: end) + } } private struct RadialGradientShaderBrush: ShaderBrush {