@@ -77,7 +77,6 @@ fun LiquidButton(
7777 shape : Shape = Capsule (),
7878 content : @Composable RowScope .() -> Unit ,
7979) {
80- val glassSettings = rememberLiquidGlassSettings()
8180 val reducedMotion = AppMotion .shouldReduceMotion()
8281 val animatePress = enabled && ! reducedMotion
8382 val interactionSource = remember { MutableInteractionSource () }
@@ -86,9 +85,6 @@ fun LiquidButton(
8685 remember(animationScope) {
8786 InteractiveHighlight (animationScope = animationScope)
8887 }
89- val rememberedHighlight = remember(glassSettings) { glassSettings.highlight(Highlight .Default ) }
90- val rememberedShadow = remember { Shadow (radius = 6 .dp) }
91- val rememberedInnerShadow = remember { InnerShadow (radius = 2 .dp, color = Color .White .copy(alpha = 0.18f )) }
9288 // Read animated state in the layer phase, not composition. The same controller survives
9389 // SDR/HDR renderer changes, so pressing/dragging a button never changes its interaction model.
9490 //
@@ -120,67 +116,13 @@ fun LiquidButton(
120116 translationY = verticalRoom * tanh(0.12f * offset.y / maxOffset)
121117 }
122118 }
123- val glassModifier =
124- if (backdrop != null ) {
125- Modifier .drawBackdrop(
126- backdrop = backdrop,
127- shape = { shape },
128- effects = {
129- liquidGlassEffects(
130- glassSettings,
131- 8 .dp.toPx(),
132- 14 .dp.toPx(),
133- 24 .dp.toPx(),
134- vibrant = true ,
135- refractionEnabled = ! reducedMotion,
136- )
137- },
138- highlight = { rememberedHighlight },
139- shadow = { rememberedShadow },
140- innerShadow = { rememberedInnerShadow },
141- layerBlock = if (animatePress) pressTransform else null ,
142- onDrawSurface = {
143- // Keep the tint inside the animated outline, including during active-state morphs.
144- val outline = shape.createOutline(size, layoutDirection, this )
145- if (tint.isSpecified) {
146- drawOutline(outline, tint, blendMode = BlendMode .Hue )
147- drawOutline(outline, glassSettings.surfaceColor(tint.copy(alpha = 0.75f )))
148- }
149- if (surfaceColor.isSpecified) {
150- drawOutline(outline, glassSettings.surfaceColor(surfaceColor))
151- }
152- },
153- )
154- } else {
155- val baseColor = when {
156- surfaceColor.isSpecified -> surfaceColor
157- tint.isSpecified -> tint
158- else -> MaterialTheme .colorScheme.surfaceContainerHigh
159- }
160- // Thickens toward opaque above the default background level; fading below it is backgroundAlpha's job.
161- val fillLevel = maxOf(LocalPlayerButtonsOpacity .current, PlayerButtonAlpha .DEFAULT_BACKGROUND_LEVEL )
162- val fill = Brush .verticalGradient(
163- 0f to baseColor.copy(alpha = PlayerButtonAlpha .background(0.68f , fillLevel)),
164- 0.45f to baseColor.copy(alpha = PlayerButtonAlpha .background(0.42f , fillLevel)),
165- 1f to baseColor.copy(alpha = PlayerButtonAlpha .background(0.58f , fillLevel)),
166- )
167- val rim = Brush .linearGradient(
168- listOf (
169- Color .White .copy(alpha = (0.43f * glassSettings.highlightStrength).coerceIn(0f , 1f )),
170- Color .White .copy(alpha = (0.10f * glassSettings.highlightStrength).coerceIn(0f , 1f )),
171- baseColor.copy(alpha = (0.30f * glassSettings.highlightStrength).coerceIn(0f , 1f )),
172- ),
173- )
174- Modifier
175- .graphicsLayer(pressTransform)
176- .outsideShadow(shape, radius = 6 .dp)
177- .clip(shape)
178- .background(fill, shape)
179- .then(
180- if (glassSettings.highlightWidth > 0f ) Modifier .border(1 .dp * glassSettings.highlightWidth, rim, shape)
181- else Modifier ,
182- )
183- }
119+ val glassModifier = Modifier .liquidControlBackground(
120+ backdrop = backdrop,
121+ shape = shape,
122+ surfaceColor = surfaceColor,
123+ tint = tint,
124+ transform = pressTransform.takeIf { animatePress },
125+ )
184126
185127 val interactionModifier =
186128 Modifier
@@ -239,5 +181,79 @@ fun LiquidButton(
239181 content = content,
240182 )
241183 }
184+
185+ /* * The button's optical surface without any size, focus, or pointer behavior. */
186+ @Composable
187+ internal fun Modifier.liquidControlBackground (
188+ backdrop : Backdrop ? ,
189+ shape : Shape ,
190+ surfaceColor : Color ,
191+ tint : Color = Color .Unspecified ,
192+ transform : (GraphicsLayerScope .() -> Unit )? = null,
193+ ): Modifier {
194+ val settings = rememberLiquidGlassSettings()
195+ if (backdrop != null ) {
196+ val reducedMotion = AppMotion .shouldReduceMotion()
197+ val highlight = remember(settings) { settings.highlight(Highlight .Default ) }
198+ val shadow = remember { Shadow (radius = 6 .dp) }
199+ val innerShadow = remember { InnerShadow (radius = 2 .dp, color = Color .White .copy(alpha = 0.18f )) }
200+ return drawBackdrop(
201+ backdrop = backdrop,
202+ shape = { shape },
203+ effects = {
204+ liquidGlassEffects(
205+ settings,
206+ 8 .dp.toPx(),
207+ 14 .dp.toPx(),
208+ 24 .dp.toPx(),
209+ vibrant = true ,
210+ refractionEnabled = ! reducedMotion,
211+ )
212+ },
213+ highlight = { highlight },
214+ shadow = { shadow },
215+ innerShadow = { innerShadow },
216+ layerBlock = transform,
217+ onDrawSurface = {
218+ val outline = shape.createOutline(size, layoutDirection, this )
219+ if (tint.isSpecified) {
220+ drawOutline(outline, tint, blendMode = BlendMode .Hue )
221+ drawOutline(outline, settings.surfaceColor(tint.copy(alpha = 0.75f )))
222+ }
223+ if (surfaceColor.isSpecified) {
224+ drawOutline(outline, settings.surfaceColor(surfaceColor))
225+ }
226+ },
227+ )
228+ }
229+
230+ // A native video surface cannot be sampled; keep the same frosted fallback as the buttons.
231+ val baseColor = when {
232+ surfaceColor.isSpecified -> surfaceColor
233+ tint.isSpecified -> tint
234+ else -> MaterialTheme .colorScheme.surfaceContainerHigh
235+ }
236+ val level = LocalPlayerButtonsOpacity .current
237+ val fill = Brush .verticalGradient(
238+ 0f to baseColor.copy(alpha = PlayerButtonAlpha .glassTint(0.68f , level)),
239+ 0.45f to baseColor.copy(alpha = PlayerButtonAlpha .glassTint(0.42f , level)),
240+ 1f to baseColor.copy(alpha = PlayerButtonAlpha .glassTint(0.58f , level)),
241+ )
242+ val rim = Brush .linearGradient(
243+ listOf (
244+ Color .White .copy(alpha = (0.43f * settings.highlightStrength).coerceIn(0f , 1f )),
245+ Color .White .copy(alpha = (0.10f * settings.highlightStrength).coerceIn(0f , 1f )),
246+ baseColor.copy(alpha = (0.30f * settings.highlightStrength).coerceIn(0f , 1f )),
247+ ),
248+ )
249+ return (if (transform == null ) this else graphicsLayer(transform))
250+ .outsideShadow(shape, radius = 6 .dp)
251+ .clip(shape)
252+ .background(fill, shape)
253+ .then(
254+ if (settings.highlightWidth > 0f ) Modifier .border(1 .dp * settings.highlightWidth, rim, shape)
255+ else Modifier ,
256+ )
257+ }
242258 }
243259}
0 commit comments