Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Make the whole app out of the bar's glass

Lelonioc52e5f906e64
diff --git a/app/src/main/java/dev/lelonio/square/SquareApplication.kt b/app/src/main/java/dev/lelonio/square/SquareApplication.kt
index 9b4ad32..fe57e5e 100644
--- a/app/src/main/java/dev/lelonio/square/SquareApplication.kt
+++ b/app/src/main/java/dev/lelonio/square/SquareApplication.kt
@@ -70,6 +70,11 @@ class SquareApplication : Application() {
dev.lelonio.square.data.EffectQualityStore(this)
}
+ /** What the glass is made of, and how much of it the phone has to pay for. */
+ val glass: dev.lelonio.square.data.GlassStore by lazy {
+ dev.lelonio.square.data.GlassStore(this)
+ }
+
/** How long one track dissolves into the next. */
val crossfade: dev.lelonio.square.data.CrossfadeStore by lazy {
dev.lelonio.square.data.CrossfadeStore(this)
diff --git a/app/src/main/java/dev/lelonio/square/data/GlassStore.kt b/app/src/main/java/dev/lelonio/square/data/GlassStore.kt
new file mode 100644
index 0000000..65a0e72
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/data/GlassStore.kt
@@ -0,0 +1,222 @@
+package dev.lelonio.square.data
+
+import android.content.Context
+import androidx.annotation.StringRes
+import dev.lelonio.square.R
+import dev.lelonio.square.ui.glass.GlassEffectConfig
+import dev.lelonio.square.ui.glass.GlassStyle
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+
+/**
+ * What the glass costs, as three answers rather than eight sliders.
+ *
+ * Every glass surface in this app records the screen behind it and runs a chain
+ * of shaders over the recording — a saturation pass, a blur, and a lens that
+ * bends the edges. That is the look, and it is also the single most expensive
+ * thing the interface does: on the bottom bar alone it happens on every frame
+ * the bar is moving. Whether it is worth it depends on the phone, and the phone
+ * is the one thing this project cannot test on.
+ *
+ * So the profile is the setting most people should ever touch, and the numbers
+ * below it are for whoever wants them. The order is deliberate: the cheapest
+ * option first, because someone opening this page is usually here because
+ * something felt slow.
+ */
+enum class GlassProfile(
+ val key: String,
+ @StringRes val label: Int,
+ @StringRes val note: Int,
+) {
+ /**
+ * No capture at all: a tinted film over the content, and nothing sampled.
+ *
+ * Not a degraded blur — a different material, and the one this app already
+ * falls back to on phones that cannot run the shaders. Costs about as much
+ * as drawing a rectangle, because that is what it is.
+ */
+ Performance("performance", R.string.glass_performance, R.string.glass_performance_note),
+
+ /** The app's own look: what everything here was designed against. */
+ Balanced("balanced", R.string.glass_balanced, R.string.glass_balanced_note),
+
+ /**
+ * Deeper frost, stronger refraction, and the dispersion at the edges.
+ *
+ * The parts that read as real glass in a still image and are the first to
+ * cost frames on a phone with anything else going on.
+ */
+ Quality("quality", R.string.glass_quality, R.string.glass_quality_note);
+
+ /** The material this profile means, before any of the sliders. */
+ fun config(): GlassEffectConfig = when (this) {
+ Performance -> GlassEffectConfig(
+ style = GlassStyle.TRANSPARENT,
+ surfaceOpacity = 0.55f,
+ )
+
+ Balanced -> GlassEffectConfig()
+
+ Quality -> GlassEffectConfig(
+ vibrancy = 1.4f,
+ blurRadius = 4f,
+ lensHeight = 0.5f,
+ lensAmount = 0.8f,
+ chromaticAberration = true,
+ )
+ }
+}
+
+/**
+ * The glass, as the listener has it.
+ *
+ * A profile, plus whatever they have moved since choosing it. Overrides are
+ * stored separately from the profile rather than flattened into it, so picking a
+ * profile again is a way back: it clears them.
+ */
+class GlassStore(context: Context) {
+
+ private val prefs = context.applicationContext
+ .getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
+
+ private val _profile = MutableStateFlow(
+ GlassProfile.entries.firstOrNull { it.key == prefs.getString(KEY_PROFILE, null) }
+ ?: GlassProfile.Balanced,
+ )
+ val profile: StateFlow<GlassProfile> = _profile.asStateFlow()
+
+ private val _config = MutableStateFlow(read())
+ val config: StateFlow<GlassEffectConfig> = _config.asStateFlow()
+
+ fun setProfile(profile: GlassProfile) {
+ if (profile == _profile.value) return
+ _profile.value = profile
+ // The profile is the answer, so choosing one drops the tuning that was
+ // sitting on top of the last: a screen where the profile says "fastest"
+ // and the sliders say otherwise is a screen that is lying.
+ prefs.edit()
+ .clear()
+ .putString(KEY_PROFILE, profile.key)
+ .apply()
+ _config.value = read()
+ _barFolds.value = prefs.getBoolean(KEY_BAR_FOLDS, true)
+ }
+
+ fun setVibrancy(value: Float) = putFloat(KEY_VIBRANCY, value)
+
+ fun setBlur(value: Float) = putFloat(KEY_BLUR, value)
+
+ fun setLensHeight(value: Float) = putFloat(KEY_LENS_HEIGHT, value)
+
+ fun setLensAmount(value: Float) = putFloat(KEY_LENS_AMOUNT, value)
+
+ fun setSurfaceOpacity(value: Float) = putFloat(KEY_FILM, value)
+
+ fun setHighlightOpacity(value: Float) = putFloat(KEY_RIM, value)
+
+ fun setChromaticAberration(value: Boolean) = putBoolean(KEY_DISPERSION, value)
+
+ fun setDepthEffect(value: Boolean) = putBoolean(KEY_DEPTH, value)
+
+ fun setPlayerEnabled(value: Boolean) = putBoolean(KEY_PLAYER, value)
+
+ fun setMiniPlayerEnabled(value: Boolean) = putBoolean(KEY_MINI_PLAYER, value)
+
+ fun setNavBarEnabled(value: Boolean) = putBoolean(KEY_NAV_BAR, value)
+
+ /** How strongly the selected tab is washed; see [read]. */
+ fun setPuckOpacity(value: Float) = putFloat(KEY_PUCK, value)
+
+ /**
+ * Whether the bottom bar folds away as you scroll.
+ *
+ * Kept here rather than with the other UI preferences because it is the same
+ * decision as the rest of this file: the fold is the app's most expensive
+ * animation — a shared element travelling, a gooey layer, and glass whose
+ * bounds change on every frame of it — and switching it off is the largest
+ * single thing a phone that struggles can be given back.
+ */
+ fun setBarFolds(value: Boolean) = putBoolean(KEY_BAR_FOLDS, value)
+
+ private val _barFolds = MutableStateFlow(prefs.getBoolean(KEY_BAR_FOLDS, true))
+ val barFolds: StateFlow<Boolean> = _barFolds.asStateFlow()
+
+ /** Back to the profile as it comes, with nothing moved. */
+ fun reset() {
+ prefs.edit()
+ .clear()
+ .putString(KEY_PROFILE, _profile.value.key)
+ .apply()
+ _config.value = read()
+ _barFolds.value = prefs.getBoolean(KEY_BAR_FOLDS, true)
+ }
+
+ /** True while any of the numbers differ from the chosen profile's own. */
+ val customised: Boolean
+ get() = prefs.all.keys.any { it != KEY_PROFILE }
+
+ private fun putFloat(key: String, value: Float) {
+ prefs.edit().putFloat(key, value).apply()
+ _config.value = read()
+ }
+
+ private fun putBoolean(key: String, value: Boolean) {
+ prefs.edit().putBoolean(key, value).apply()
+ _config.value = read()
+ _barFolds.value = prefs.getBoolean(KEY_BAR_FOLDS, true)
+ }
+
+ /**
+ * The profile's material with the stored overrides laid over it.
+ *
+ * Read in full on every change rather than patched, because the profile can
+ * change underneath and a patched copy would carry the old one's numbers.
+ */
+ private fun read(): GlassEffectConfig {
+ val base = _profile.value.config()
+ return base.copy(
+ vibrancy = prefs.getFloat(KEY_VIBRANCY, base.vibrancy),
+ blurRadius = prefs.getFloat(KEY_BLUR, base.blurRadius),
+ lensHeight = prefs.getFloat(KEY_LENS_HEIGHT, base.lensHeight),
+ lensAmount = prefs.getFloat(KEY_LENS_AMOUNT, base.lensAmount),
+ surfaceOpacity = prefs.getFloat(KEY_FILM, base.surfaceOpacity),
+ highlightOpacity = prefs.getFloat(KEY_RIM, base.highlightOpacity),
+ chromaticAberration = prefs.getBoolean(KEY_DISPERSION, base.chromaticAberration),
+ depthEffect = prefs.getBoolean(KEY_DEPTH, base.depthEffect),
+ playerEnabled = prefs.getBoolean(KEY_PLAYER, base.playerEnabled),
+ miniPlayerEnabled = prefs.getBoolean(KEY_MINI_PLAYER, base.miniPlayerEnabled),
+ navBarEnabled = prefs.getBoolean(KEY_NAV_BAR, base.navBarEnabled),
+ // Square has one appearance, and it is dark glass over artwork. The
+ // library's own default asks the Material scheme whether it is light
+ // or dark and washes the selection puck accordingly, which here
+ // answered "light" and put a solid white slab under the chosen tab.
+ // A wash of light instead — but a wash you can see: at the 0.12 this
+ // started on, over artwork with anything bright in it, the selected
+ // tab was a guess.
+ puckColor = androidx.compose.ui.graphics.Color.White,
+ puckOpacity = prefs.getFloat(KEY_PUCK, DEFAULT_PUCK_OPACITY),
+ )
+ }
+
+ private companion object {
+ const val FILE_NAME = "square_glass"
+ const val KEY_PROFILE = "profile"
+ const val KEY_VIBRANCY = "vibrancy"
+ const val KEY_BLUR = "blur"
+ const val KEY_LENS_HEIGHT = "lens_height"
+ const val KEY_LENS_AMOUNT = "lens_amount"
+ const val KEY_FILM = "film"
+ const val KEY_RIM = "rim"
+ const val KEY_DISPERSION = "dispersion"
+ const val KEY_DEPTH = "depth"
+ const val KEY_PLAYER = "player"
+ const val KEY_MINI_PLAYER = "mini_player"
+ const val KEY_NAV_BAR = "nav_bar"
+ const val KEY_BAR_FOLDS = "bar_folds"
+ const val KEY_PUCK = "puck"
+
+ /** Enough to read as a lit tab over a bright cover, short of a slab. */
+ const val DEFAULT_PUCK_OPACITY = 0.26f
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/SessionNotice.kt b/app/src/main/java/dev/lelonio/square/ui/SessionNotice.kt
index b37ef59..3235e9c 100644
--- a/app/src/main/java/dev/lelonio/square/ui/SessionNotice.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/SessionNotice.kt
@@ -19,7 +19,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.R
import dev.lelonio.square.ui.glass.pressable
import dev.lelonio.square.ui.player.GlassSurface
diff --git a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
index f9eec61..7a68e6a 100644
--- a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
@@ -39,12 +39,32 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.snapshotFlow
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import dev.lelonio.square.ui.components.FriendsPanel
import dev.lelonio.square.ui.components.SharedTrackCard
+import androidx.compose.foundation.gestures.awaitEachGesture
+import androidx.compose.foundation.gestures.awaitFirstDown
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.foundation.layout.imePadding
+import androidx.compose.foundation.text.BasicTextField
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.input.nestedscroll.nestedScroll
+import androidx.compose.ui.text.style.TextOverflow
+import com.adamglin.phosphoricons.fill.XCircle
+import dev.lelonio.square.ui.glass.floatingtabbar.FloatingTabBar
+import dev.lelonio.square.ui.glass.floatingtabbar.FloatingTabBarDefaults
+import dev.lelonio.square.ui.glass.floatingtabbar.rememberFloatingTabBarScrollConnection
+import androidx.compose.ui.unit.sp
+import dev.lelonio.square.ui.glass.liquidGlass
+import dev.lelonio.square.ui.glass.pressable
+import androidx.compose.ui.platform.LocalConfiguration
+import androidx.compose.foundation.gestures.draggable
+import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
@@ -74,9 +94,9 @@ import androidx.compose.ui.platform.LocalContext
import coil.compose.AsyncImage
import coil.request.ImageRequest
import dev.lelonio.square.ui.components.BlurTransformation
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.backdrops.layerBackdrop
-import com.kyant.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
import dev.lelonio.square.R
import dev.lelonio.square.data.CanvasClip
import dev.lelonio.square.data.Catalog
@@ -113,6 +133,7 @@ import dev.lelonio.square.data.RemoteConnect
import dev.lelonio.square.ui.player.asPlaybackState
import dev.lelonio.square.ui.player.rememberRemotePositionMs
import kotlinx.coroutines.Dispatchers
+import dev.lelonio.square.ui.player.FloatingMiniPlayer
import dev.lelonio.square.ui.player.MiniPlayer
import dev.lelonio.square.ui.player.PlaybackState
import dev.lelonio.square.ui.player.MiniPlayerHeight
@@ -538,12 +559,62 @@ fun SquareApp(
// an opaque page over the backdrop — so the colour has to be provided
// here, or every Text that does not set one explicitly stays black on
// the darkened artwork.
- CompositionLocalProvider(LocalContentColor provides Ink) {
+ // What glass is, once, for everything made of it.
+ //
+ // This used to be provided around the bottom bar alone, because the bar
+ // was the only thing asking. Every other surface then quietly used the
+ // library's built-in defaults, which is how the settings below could
+ // move a slider and change nothing outside the bar.
+ val glassStore = remember(context) {
+ (context.applicationContext as dev.lelonio.square.SquareApplication).glass
+ }
+ val glassConfig by glassStore.config.collectAsStateWithLifecycle()
+
+ // What folds the bar, and what tells the glass the page is moving. Built
+ // here rather than beside the bar because both of those are read at the
+ // top of the app: the glass configuration is provided from this scope.
+ val tabBarScroll = rememberFloatingTabBarScrollConnection()
+ // Held as a lambda so a scroll starting or stopping costs no
+ // recomposition of the app: the surfaces ask during draw.
+ val pageMoving = remember(tabBarScroll) { { tabBarScroll.scrolling } }
+
+ CompositionLocalProvider(
+ LocalContentColor provides Ink,
+ dev.lelonio.square.ui.glass.LocalGlassEffectConfig provides glassConfig,
+ dev.lelonio.square.ui.glass.LocalGlassFrozen provides pageMoving,
+ ) {
Box(Modifier.fillMaxSize()) {
val navController = rememberNavController()
val currentEntry by navController.currentBackStackEntryAsState()
val route = currentEntry?.destination?.route
+ // Which tab the bar shows as the current one.
+ //
+ // Not the route: a playlist, an album and an artist are pages
+ // pushed over a tab rather than tabs of their own, and asking the
+ // bar to select a key it has no tab for left it with nothing
+ // selected — you opened an album from the library and the library
+ // stopped being where you were. A page opened from a tab belongs
+ // to it until you choose another one, which is also what makes
+ // the back arrow's destination legible before you press it.
+ // Only the two that have one: search is a circle beside the tabs
+ // and grows into the field rather than being somewhere you are,
+ // so it is the bar's search mode that shows it, not a selection.
+ // Naming it here instead left a page opened from a search result
+ // with the search key selected and no tab to put it on — nothing
+ // lit again, by a different route.
+ var activeTab by rememberSaveable { mutableStateOf(Routes.HOME) }
+ LaunchedEffect(route) {
+ if (route == Routes.HOME || route == Routes.LIBRARY) {
+ activeTab = route
+ }
+ }
+
+ val focus = androidx.compose.ui.platform.LocalFocusManager.current
+ // Read here as well as at the bar: what the page does about the
+ // keyboard depends on it, and the bar is built much further down.
+ val searching = route == Routes.SEARCH
+
// A link from outside.
//
// A song is offered rather than started. Whoever sent it may
@@ -671,7 +742,8 @@ fun SquareApp(
.then(
if (barsVisible) Modifier.layerBackdrop(pageBackdrop)
else Modifier,
- ),
+ )
+ ,
) {
Box(
Modifier
@@ -681,6 +753,26 @@ fun SquareApp(
AppBackdrop(playback.artworkUrl)
}
+ Box(
+ Modifier
+ .nestedScroll(tabBarScroll)
+ // Touching the page puts the keyboard away.
+ //
+ // The field is in the bar at the bottom of the screen
+ // and the keyboard is under it, so the results are the
+ // only thing left to touch — and touching a result
+ // while the keyboard stays up is the moment the
+ // listener has finished typing. Nothing is consumed
+ // here: the tap goes on to whatever it landed on, and
+ // this only takes the focus with it.
+ .pointerInput(searching) {
+ if (!searching) return@pointerInput
+ awaitEachGesture {
+ awaitFirstDown(requireUnconsumed = false)
+ focus.clearFocus()
+ }
+ },
+ ) {
NavHost(navController, startDestination = Routes.HOME) {
composable(Routes.HOME) {
HomeScreen(
@@ -729,7 +821,6 @@ fun SquareApp(
webApi = webApi,
contentPadding = listPadding,
nowPlayingUri = playback.mediaId,
- onQueryChange = viewModel::onSearchQuery,
onClientIdChange = viewModel::onWebApiClientIdChange,
onConnectWebApi = { viewModel.connectWebApi() },
onPlayTrack = { tracks, index ->
@@ -868,6 +959,7 @@ fun SquareApp(
)
},
onToggleFollow = viewModel::toggleFollowArtist,
+ onToggleSaved = viewModel::toggleSaved,
onShare = {
val uri = playlist.uri ?: return@PlaylistScreen
context.startActivity(
@@ -897,17 +989,7 @@ fun SquareApp(
}
}
- // Out here for the same reason as the bars below: it refracts
- // `pageBackdrop`, so it cannot be drawn inside it.
- SessionExpiredNotice(
- visible = webApi.expired && !webApi.connecting,
- backdrop = pageBackdrop,
- onReconnect = viewModel::connectWebApi,
- onDismiss = viewModel::dismissWebApiExpiry,
- modifier = Modifier
- .align(Alignment.TopCenter)
- .padding(top = statusBar + 8.dp),
- )
+ }
// Out here for the same reason as the bars below: it refracts
// `pageBackdrop`, so it cannot be drawn inside it.
@@ -931,6 +1013,11 @@ fun SquareApp(
Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
+ // The bar is where you type now, so it has to be above
+ // the keyboard: the search field lived on the page until
+ // a moment ago, where the keyboard covering the bottom of
+ // the screen cost nothing.
+ .imePadding()
// Hidden as the player takes over, and out of the way
// before it covers it: a tab bar under a full-screen
// player still swallows the taps meant for the
@@ -940,31 +1027,114 @@ fun SquareApp(
}
.onSizeChanged { barHeight = with(density) { it.height.toDp() } },
) {
- BottomBar(
- route = route,
- bottomInset = navBar,
- backdrop = pageBackdrop,
- onSelect = navController::switchTab,
+ // The material comes from the settings now, provided once at
+ // the top of the app; what is still local here is which
+ // backdrop the bar's surfaces sample when they are not handed
+ // one, and that has to stay local — a pane drawn inside the
+ // layer it samples recurses on the render thread until the
+ // process dies.
+ androidx.compose.runtime.CompositionLocalProvider(
+ dev.lelonio.square.ui.glass.LocalAppBackdrop provides pageBackdrop,
+ ) {
+ // One pane of glass, given to both the bar and the pill
+ // above it — which is how the reference does it: the tab bar
+ // component paints no background of its own, the caller
+ // hands it the material.
+ // Where the glass is allowed to be, from the settings. Off
+ // is not "no surface" — a transparent bar swallows the taps
+ // meant for the page under it and reads as nothing at all —
+ // but the film, which is the same thing a phone without the
+ // hardware blur gets.
+ val flat = dev.lelonio.square.ui.glass.GlassStyle.TRANSPARENT
+ val barConfig = if (glassConfig.navBarEnabled) {
+ glassConfig
+ } else {
+ glassConfig.copy(style = flat)
+ }
+ val pillConfig = if (glassConfig.miniPlayerEnabled) {
+ glassConfig
+ } else {
+ glassConfig.copy(style = flat)
+ }
+ val barGlass = Modifier.liquidGlass(
+ config = barConfig,
+ shape = androidx.compose.foundation.shape.RoundedCornerShape(percent = 50),
+ highlightAlpha = 0.3f,
+ // Held still while the bar morphs. Its bounds animate
+ // across the whole fold, and without this every frame
+ // re-records the screen and runs the blur and the lens
+ // over it again — which is most of what made the
+ // animation crawl.
+ frozen = dev.lelonio.square.ui.glass.floatingtabbar
+ .LocalTabBarBackdropFrozen.current,
)
- }
+ // The same pane, on the pill above it, unless the settings
+ // have singled that one out.
+ val pillGlass = if (glassConfig.miniPlayerEnabled == glassConfig.navBarEnabled) {
+ barGlass
+ } else {
+ Modifier.liquidGlass(
+ config = pillConfig,
+ shape = androidx.compose.foundation.shape.RoundedCornerShape(percent = 50),
+ highlightAlpha = 0.3f,
+ frozen = dev.lelonio.square.ui.glass.floatingtabbar
+ .LocalTabBarBackdropFrozen.current,
+ )
+ }
- if (playback.hasItem && chrome > 0.01f) {
- Box(Modifier.fillMaxSize().graphicsLayer { alpha = chrome }) {
- NowPlayingSheet(
- progress = expand,
- // The measured bar already carries the navigation
- // inset; the gap is what keeps the two from touching.
- bottomInset = barHeight + 6.dp,
- background = { AppBackdrop(playback.artworkUrl) },
- collapsedContent = {
- MiniPlayer(
+ // How far the player has to travel, for the pull that opens
+ // it. Read once here rather than per frame of the drag.
+ val playerTravelPx = with(density) {
+ (LocalConfiguration.current.screenHeightDp.dp - MiniPlayerHeight).toPx()
+ }
+ val accessory: (@Composable androidx.compose.animation.SharedTransitionScope.(
+ Modifier,
+ androidx.compose.animation.AnimatedVisibilityScope,
+ ) -> Unit)? = if (playback.hasItem) {
+ { accessoryModifier, _ ->
+ FloatingMiniPlayer(
state = playback,
- remoteDevice = remote?.deviceName,
- progress = {
- progressOf(positionMs.value, playback.durationMs)
+ positionMs = positionMs,
+ modifier = accessoryModifier
+ .fillMaxWidth()
+ .then(pillGlass)
+ // Up to open the player, as it always was.
+ // The pill's own drag detector locks to the
+ // horizontal after the touch slop, so a
+ // vertical pull never reached it and the
+ // gesture landed on nothing — the sheet's
+ // collapsed half, which used to carry this,
+ // is empty now that what is playing lives in
+ // the bar.
+ .draggable(
+ state = rememberDraggableState { delta ->
+ scope.launch {
+ val travel = playerTravelPx
+ if (travel > 0f) {
+ expand.snapTo(
+ (expand.value - delta / travel)
+ .coerceIn(0f, 1f),
+ )
+ }
+ }
+ },
+ orientation = androidx.compose.foundation.gestures.Orientation.Vertical,
+ onDragStopped = { velocity ->
+ scope.launch {
+ val target = when {
+ velocity < -800f -> 1f
+ velocity > 800f -> 0f
+ expand.value > 0.4f -> 1f
+ else -> 0f
+ }
+ expand.animateTo(target, expandSpec)
+ }
+ },
+ ),
+ inline = tabBarScroll.isInline,
+ onClick = {
+ scope.launch { expand.animateTo(1f, expandSpec) }
},
- backdrop = pageBackdrop,
- onExpand = { scope.launch { expand.animateTo(1f, expandSpec) } },
onTogglePlay = {
if (remote != null) {
val playing = remote?.playing == true
@@ -980,9 +1150,167 @@ fun SquareApp(
if (remote != null) onRemote(RemoteConnect::next)
else player?.seekToNextMediaItem()
},
+ onPrevious = {
+ if (remote != null) onRemote(RemoteConnect::previous)
+ else player?.seekToPreviousMediaItem()
+ },
+ onSeek = { positionMillis -> player?.seekTo(positionMillis) },
)
+ }
+ } else {
+ null
+ }
+
+ // Before anything is drawn for real; see GlassWarmUp.
+ dev.lelonio.square.ui.glass.GlassWarmUp(pageBackdrop)
+ // Two tabs and a circle beside them: the capsule takes what
+ // is left of the row once the circle has its 80dp, and never
+ // more than the 88dp a tab is designed for. Without this the
+ // bar stretched to the screen and the tabs floated in it.
+ // Measured off the reference, at its own density: a tab is
+ // 88dp wide, the row is inset 16 while folded and 26 while
+ // open, and everything is spaced by 8. Two tabs make a
+ // narrower capsule than its three do, and the row centres
+ // itself — which is the point of measuring the parts rather
+ // than the whole.
+ val barMargin = if (tabBarScroll.isInline) 16.dp else 26.dp
+
+ // Searching opens the bar and keeps it open.
+ //
+ // The field is in the bar, so arriving at search with the bar
+ // already folded left the search page with nowhere to type
+ // and no sign that unfolding the bar was what you had to do.
+ // And once open it stays: it used to fold on the way down the
+ // results and come back on the way up, taking the field with
+ // it each time and bringing the keyboard back up on every
+ // scroll.
+ // And the same lock serves the setting: a bar told not to
+ // fold is a bar whose scrolling is not allowed to change it.
+ val barFolds by glassStore.barFolds.collectAsStateWithLifecycle()
+ LaunchedEffect(searching, barFolds) {
+ tabBarScroll.locked = searching || !barFolds
+ if (searching || !barFolds) tabBarScroll.expand()
+ }
+
+ FloatingTabBar(
+ // Always the tab the page belongs to, search included.
+ //
+ // Naming the search circle here instead left the search
+ // bar with no tab beside it: the bar keeps one tab in
+ // search mode — the one you came from, so you can go
+ // back by tapping it — and it finds it by matching this
+ // key against the regular tabs. A key belonging to none
+ // of them matched nothing and the tab disappeared,
+ // leaving the back gesture as the only way out.
+ selectedTabKey = activeTab,
+ scrollConnection = tabBarScroll,
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(horizontal = barMargin)
+ .padding(bottom = navBar + 8.dp),
+ // The glass is the caller's to apply, and it is what the
+ // bar is made of: transparent colours underneath, and
+ // every surface sampling the page through this.
+ tabBarContentModifier = barGlass,
+ colors = FloatingTabBarDefaults.colors(
+ backgroundColor = Color.Transparent,
+ accessoryBackgroundColor = Color.Transparent,
+ ),
+ sizes = FloatingTabBarDefaults.sizes(
+ tabBarContentPadding = PaddingValues(4.dp),
+ tabExpandedContentPadding = PaddingValues(vertical = 6.dp, horizontal = 6.dp),
+ tabInlineContentPadding = PaddingValues(8.dp),
+ // The reference's capsule is 272dp wide whatever
+ // is in it: three tabs at 88 there, two at 132
+ // here. Keeping the tab width instead would have
+ // made this app's bar visibly shorter than the one
+ // it is copying — and the accessory above it, which
+ // matches the row, shorter with it.
+ tabWidth = (272.dp - 8.dp) / 2,
+ ),
+ inlineAccessory = accessory,
+ expandedAccessory = accessory,
+ backdrop = pageBackdrop,
+ accentColor = Ink,
+ searchMode = searching,
+ searchBarContent = if (searching) {
+ { fieldModifier ->
+ BarSearchField(
+ query = search.query,
+ onQuery = viewModel::onSearchQuery,
+ modifier = fieldModifier,
+ )
+ }
+ } else {
+ null
},
+ ) {
+ tab(
+ key = Routes.HOME,
+ title = { Text(stringResource(R.string.home), fontSize = 10.sp) },
+ icon = {
+ Icon(
+ if (activeTab == Routes.HOME) PhosphorIcons.Fill.House
+ else PhosphorIcons.Regular.House,
+ contentDescription = stringResource(R.string.home),
+ tint = Ink,
+ modifier = Modifier.size(30.dp),
+ )
+ },
+ onClick = { navController.switchTab(Routes.HOME) },
+ )
+ tab(
+ key = Routes.LIBRARY,
+ title = { Text(stringResource(R.string.library), fontSize = 10.sp) },
+ icon = {
+ Icon(
+ if (activeTab == Routes.LIBRARY) PhosphorIcons.Fill.MusicNotes
+ else PhosphorIcons.Regular.MusicNotes,
+ contentDescription = stringResource(R.string.library),
+ tint = Ink,
+ modifier = Modifier.size(30.dp),
+ )
+ },
+ onClick = { navController.switchTab(Routes.LIBRARY) },
+ )
+ // Search is a standalone circle rather than a third tab,
+ // which is what lets it grow into the field: you go there
+ // to do something and come back, and the bar treats it as
+ // that kind of destination.
+ standaloneTab(
+ key = Routes.SEARCH,
+ icon = {
+ Icon(
+ PhosphorIcons.Regular.MagnifyingGlass,
+ contentDescription = stringResource(R.string.search),
+ tint = Ink,
+ modifier = Modifier.size(26.dp),
+ )
+ },
+ onClick = {
+ if (searching) navController.switchTab(Routes.HOME)
+ else navController.switchTab(Routes.SEARCH)
+ },
+ )
+ }
+ }
+ }
+
+ if (playback.hasItem && chrome > 0.01f) {
+ Box(Modifier.fillMaxSize().graphicsLayer { alpha = chrome }) {
+ NowPlayingSheet(
+ progress = expand,
+ background = { AppBackdrop(playback.artworkUrl) },
expandedContent = {
+ // The player is the largest glass surface in the app by
+ // a wide margin, so the settings' switch for it is the
+ // one that buys the most. Off leaves the film every
+ // pane falls back to, not a hole.
+ androidx.compose.runtime.CompositionLocalProvider(
+ dev.lelonio.square.ui.player.LocalGlassEnabled provides
+ (glassConfig.playerEnabled &&
+ dev.lelonio.square.ui.player.LocalGlassEnabled.current),
+ ) {
PlayerScreen(
state = playback,
positionMs = positionMs,
@@ -1135,6 +1463,7 @@ fun SquareApp(
videoOn = videoOn,
videoPlayer = player,
)
+ }
},
)
}
@@ -1601,10 +1930,8 @@ private fun BottomBar(
modifier = Modifier.size(64.dp),
contentHeight = 64.dp,
contentPadding = 0.dp,
- blurRadius = 8.dp,
// The same film the capsule beside it uses, or the round button
// reads as clearer glass than the bar it sits next to.
- surfaceColor = GlassFilm,
) {
Icon(
imageVector = if (searching) PhosphorIcons.Fill.MagnifyingGlass else PhosphorIcons.Regular.MagnifyingGlass,
@@ -1807,3 +2134,65 @@ private fun savedPlaybackSeed(context: android.content.Context): PlaybackState?
isBuffering = true,
)
}
+
+/**
+ * The search field, living in the bar.
+ *
+ * The circle the listener tapped grows into this, so it is focused as it
+ * arrives: whoever pressed the magnifier wants to type. The cross clears the
+ * field and appears only once there is something to clear.
+ */
+@Composable
+private fun BarSearchField(
+ query: String,
+ onQuery: (String) -> Unit,
+ modifier: Modifier = Modifier,
+) {
+ val focus = remember { FocusRequester() }
+ LaunchedEffect(Unit) { runCatching { focus.requestFocus() } }
+
+ Row(
+ modifier.padding(horizontal = 16.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Icon(
+ PhosphorIcons.Regular.MagnifyingGlass,
+ contentDescription = null,
+ tint = Ink.copy(alpha = 0.7f),
+ modifier = Modifier.size(20.dp),
+ )
+ BasicTextField(
+ value = query,
+ onValueChange = onQuery,
+ singleLine = true,
+ textStyle = MaterialTheme.typography.bodyLarge.copy(color = Ink),
+ cursorBrush = androidx.compose.ui.graphics.SolidColor(Ink),
+ modifier = Modifier
+ .weight(1f)
+ .padding(start = 12.dp)
+ .focusRequester(focus),
+ decorationBox = { field ->
+ if (query.isEmpty()) {
+ Text(
+ stringResource(R.string.search_placeholder),
+ style = MaterialTheme.typography.bodyLarge,
+ color = Ink.copy(alpha = 0.5f),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ }
+ field()
+ },
+ )
+ if (query.isNotEmpty()) {
+ Icon(
+ PhosphorIcons.Fill.XCircle,
+ contentDescription = stringResource(R.string.clear),
+ tint = Ink.copy(alpha = 0.55f),
+ modifier = Modifier
+ .size(22.dp)
+ .pressable(onClick = { onQuery("") }, pressedScale = 0.9f),
+ )
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/FriendsPanel.kt b/app/src/main/java/dev/lelonio/square/ui/components/FriendsPanel.kt
index 85d7e9c..390b238 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/FriendsPanel.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/FriendsPanel.kt
@@ -32,9 +32,9 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
import dev.lelonio.square.R
import dev.lelonio.square.data.FriendListen
import dev.lelonio.square.ui.glass.pressable
@@ -90,7 +90,7 @@ fun BoxScope.FriendsPanel(
backdrop = backdrop,
shape = shape,
surfaceColor = Color.White.copy(alpha = 0.08f),
- blurRadius = 46.dp,
+ blurScale = 23.0f,
modifier = Modifier
.padding(horizontal = 22.dp)
.fillMaxWidth()
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/GlassMenu.kt b/app/src/main/java/dev/lelonio/square/ui/components/GlassMenu.kt
index 5a1b198..722a91b 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/GlassMenu.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/GlassMenu.kt
@@ -13,8 +13,8 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import dev.lelonio.square.ui.player.GlassSurface
import dev.lelonio.square.ui.theme.softShadow
-import com.kyant.backdrop.Backdrop
-import com.kyant.shapes.Capsule
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.shapes.ContinuousCapsule
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.height
@@ -187,7 +187,7 @@ fun BoxScope.GlassIconMenu(
.align(Alignment.TopStart)
.offset { anchor },
) {
- val shape = Capsule()
+ val shape = ContinuousCapsule()
GlassSurface(
backdrop = backdrop,
shape = shape,
@@ -285,7 +285,7 @@ fun BoxScope.GlassChoiceMenu(
// them showing through its own labels — legibility beats keeping
// every surface the same film.
surfaceColor = ChoiceFilm,
- blurRadius = 30.dp,
+ blurScale = 15.0f,
modifier = Modifier
.width(CHOICE_MENU_WIDTH)
.clip(shape)
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/SharedTrackCard.kt b/app/src/main/java/dev/lelonio/square/ui/components/SharedTrackCard.kt
index e372d68..83a72f8 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/SharedTrackCard.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/SharedTrackCard.kt
@@ -42,9 +42,9 @@ import com.adamglin.phosphoricons.Fill
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.fill.Play
import com.adamglin.phosphoricons.regular.Plus
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
import dev.lelonio.square.R
import dev.lelonio.square.data.CatalogTrack
import dev.lelonio.square.ui.glass.pressable
@@ -108,7 +108,7 @@ fun BoxScope.SharedTrackCard(
backdrop = backdrop,
shape = shape,
surfaceColor = Color.White.copy(alpha = 0.07f),
- blurRadius = 46.dp,
+ blurScale = 23.0f,
modifier = Modifier
.padding(horizontal = 26.dp)
.fillMaxWidth()
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/TrackSheet.kt b/app/src/main/java/dev/lelonio/square/ui/components/TrackSheet.kt
index 65892e0..9699977 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/TrackSheet.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/TrackSheet.kt
@@ -29,9 +29,9 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
import dev.lelonio.square.ui.player.GlassSurface
import dev.lelonio.square.ui.theme.softShadow
@@ -101,7 +101,7 @@ fun BoxScope.TrackSheet(
// *unblurred* layer, so at the usual 8dp the rows underneath came
// through sharper inside the sheet than outside it — the one thing
// that reads as a mistake rather than as a material.
- blurRadius = 46.dp,
+ blurScale = 23.0f,
modifier = Modifier
.padding(horizontal = 28.dp)
.fillMaxWidth()
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.kt b/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.kt
new file mode 100644
index 0000000..ff28d3b
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.kt
@@ -0,0 +1,583 @@
+/**
+ * Convx Project (C) 2026
+ * Licensed under GPL-3.0 | See git history for contributors
+ */
+
+package dev.lelonio.square.ui.glass
+
+import android.app.ActivityManager
+import android.os.Build
+import androidx.compose.foundation.shape.CornerBasedShape
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Stable
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.ui.draw.clip
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.staticCompositionLocalOf
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.isSpecified
+import androidx.compose.ui.graphics.lerp
+import androidx.compose.ui.graphics.luminance
+import dev.lelonio.square.ui.glass.backdrop.BackdropEffectScope
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.unit.dp
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.isRenderEffectSupported
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.colorControls
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.highlight.HighlightStyle
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+
+/**
+ * User-configurable parameters of the liquid glass effect, sourced from DataStore
+ * preferences in the settings and distributed through
+ * [LocalGlassEffectConfig].
+ */
+@Stable
+data class GlassEffectConfig(
+ val globalEnabled: Boolean = true,
+ val vibrancy: Float = 1.2f,
+ /** Blur in dp applied to glass pills. User requested 2dp for landscape fix. */
+ val blurRadius: Float = 2f,
+ /** 0..1, mapped to 0..[LENS_MAX_DP] dp of lens refraction height. 0.4 = 40%. */
+ val lensHeight: Float = 0.4f,
+ /** 0..1, mapped to 0..[LENS_MAX_DP] dp of lens refraction amount. 0.6 = 60%. */
+ val lensAmount: Float = 0.6f,
+ val chromaticAberration: Boolean = false,
+ val depthEffect: Boolean = false,
+ /** [Color.Unspecified] means adaptive: dark grey on dark. */
+ val surfaceTintColor: Color = Color(0xFF1A1A1A),
+ /** Specular rim ("pluck") colour. [Color.Unspecified] keeps the default white. */
+ val highlightColor: Color = Color.Unspecified,
+ /** Specular rim opacity, 0..1. */
+ val highlightOpacity: Float = EdgeHighlightAlpha,
+ /** Which rendering style every glass surface uses. */
+ val style: GlassStyle = GlassStyle.LIQUID,
+ /** Wash painted over the nav bar's selection puck. [Color.Unspecified] adapts
+ * to the theme: a dark wash on dark, a light one on light. */
+ val puckColor: Color = Color.Unspecified,
+ /** Puck wash opacity at rest. It eases toward clear while pressed. */
+ val puckOpacity: Float = 0.8f,
+ val surfaceOpacity: Float = 0.5f,
+ val textColor: Color = Color.White,
+ val playerEnabled: Boolean = true,
+ val miniPlayerEnabled: Boolean = true,
+ val navBarEnabled: Boolean = true,
+ /** Tablet side panel — split from [navBarEnabled] so it can differ from the
+ * phone bottom bar's glass setting instead of always mirroring it. */
+ val sidePanelEnabled: Boolean = true,
+ /** Side panel gets its own effect tuning (unlike the other components,
+ * which all share [vibrancy]/[blurRadius]/[lensHeight]/[lensAmount]) —
+ * defaults match those shared values so it looks identical until
+ * explicitly customized. */
+ val sidePanelVibrancy: Float = 1.2f,
+ val sidePanelBlurRadius: Float = 2f,
+ val sidePanelLensHeight: Float = 0.4f,
+ val sidePanelLensAmount: Float = 0.6f,
+ val sidePanelColor: Color = Color.Unspecified,
+ val sidePanelSurfaceOpacity: Float = 0.5f,
+ val sidePanelTextColor: Color = Color.White,
+) {
+ /** A copy of this config with the shared effect fields swapped for the
+ * side panel's own — pass this to Modifier.liquidGlass for the side
+ * panel instead of the raw config, since liquidGlass always reads the
+ * shared fields generically. */
+ fun forSidePanel(): GlassEffectConfig = copy(
+ vibrancy = sidePanelVibrancy,
+ blurRadius = sidePanelBlurRadius,
+ lensHeight = sidePanelLensHeight,
+ lensAmount = sidePanelLensAmount,
+ surfaceTintColor = sidePanelColor,
+ surfaceOpacity = sidePanelSurfaceOpacity,
+ textColor = sidePanelTextColor,
+ )
+ /**
+ * Whether the glass effect should be rendered for [component], taking the master
+ * switch and the per-component switch into account.
+ */
+ fun isEnabledFor(component: GlassComponent): Boolean =
+ globalEnabled && when (component) {
+ GlassComponent.PLAYER -> playerEnabled
+ GlassComponent.MINI_PLAYER -> miniPlayerEnabled
+ GlassComponent.NAV_BAR -> navBarEnabled
+ GlassComponent.SIDE_PANEL -> sidePanelEnabled
+ }
+
+ /**
+ * True when at least one surface would render glass. Used to decide whether
+ * capturing the app backdrop is worth anything at all — with every component
+ * off, nothing samples it and recording it is pure cost.
+ */
+ val anyComponentEnabled: Boolean
+ get() = globalEnabled &&
+ (playerEnabled || miniPlayerEnabled || navBarEnabled || sidePanelEnabled)
+}
+
+/** UI surfaces that can individually opt in or out of the liquid glass effect. */
+/**
+ * How a glass surface is rendered.
+ *
+ * The full liquid treatment costs a screen capture plus a RenderEffect chain per
+ * surface. The cheaper styles exist both as a performance escape hatch and as a
+ * look in their own right — and because with glass off entirely the chrome fell
+ * back to an opaque fill, which reads as a black blob over content.
+ */
+enum class GlassStyle {
+ /** Blur + saturation + lens refraction + specular rim. The default. */
+ LIQUID,
+
+ /** Blur and saturation only: no lens, no rim, no chromatic aberration.
+ * Still captures the backdrop, so it is frosted, just not refractive. */
+ BLUR,
+
+ /** No capture at all — a translucent tinted fill at the configured opacity.
+ * Cheapest by a wide margin: nothing is sampled, nothing is blurred. */
+ TRANSPARENT,
+}
+
+/**
+ * True when [Modifier.liquidGlass] should take its cheap translucent-tint path
+ * (no backdrop capture, no RenderEffect) instead of the full liquid treatment:
+ * either the user explicitly chose [GlassStyle.TRANSPARENT], or the platform
+ * can't do the real blur at all ([renderEffectSupported] false, below Android
+ * 12). The unsupported-platform case used to fall through to a hardcoded
+ * opaque-black surface instead — the "solid black instead of any
+ * transparency" bug reported on older/low-end devices. Pulled out as a plain
+ * function so the fallback decision is unit-testable without a Composition.
+ */
+fun shouldUseTranslucentGlassFallback(style: GlassStyle, renderEffectSupported: Boolean): Boolean =
+ style == GlassStyle.TRANSPARENT || !renderEffectSupported
+
+enum class GlassComponent {
+ PLAYER,
+ MINI_PLAYER,
+ NAV_BAR,
+ SIDE_PANEL,
+}
+
+/**
+ * Maximum lens refraction in dp when the 0..1 preference sliders are at 1. The
+ * defaults (0.5) land on the 24dp height/amount used by the library author's
+ * Apple-matched LiquidBottomTabs recipe.
+ */
+internal const val LENS_MAX_DP = 48f
+
+/**
+ * The full screen player uses a much heavier blur than the glass pills, matching
+ * Apple Music where the now playing background is a deep-blurred material while
+ * only the small controls are clear liquid glass.
+ */
+internal const val PLAYER_BLUR_MULTIPLIER = 4f
+
+/**
+ * Lowest resolution fraction glass surfaces are rendered at (heavy blur hides it).
+ *
+ * Measured empirically: flattening this across all surfaces and pushing it to
+ * 0.05 was tried and reverted. Two findings worth not re-deriving. First, the
+ * scale is only safe in proportion to the blur — pixel-sized effect params are
+ * pre-multiplied by it, so at 0.05 the default 2dp blur collapsed to ~0.3px on a
+ * 3x screen and the 20x upscale had nothing smoothing it, which reads as
+ * pixelation, not frost. Second, applying it at zero blur softens surfaces whose
+ * whole look is clear content, for no gain: the surfaces where compression
+ * actually pays (the full screen player, 12x the nav bar's area at 4x the blur)
+ * already reach this floor through the ramp.
+ *
+ * Keep the ramp in [glassResolutionScale] rather than a flat value.
+ */
+internal const val MIN_GLASS_RESOLUTION_SCALE = 0.30f
+
+/** Blur radius (dp) at or above which the minimum resolution scale is safe to use. */
+internal const val FULL_QUALITY_BLUR_DP = 8f
+
+/**
+ * Resolution fraction at which a glass surface records and processes its backdrop.
+ * Blur masks the upscaling, so the more blur, the lower the resolution can go: at
+ * [FULL_QUALITY_BLUR_DP]+ dp of blur the surface renders at
+ * [MIN_GLASS_RESOLUTION_SCALE]; with no blur it stays at full resolution so the
+ * clear glass center remains crisp.
+ */
+fun glassResolutionScale(blurRadiusDp: Float): Float {
+ val t = (blurRadiusDp / FULL_QUALITY_BLUR_DP).coerceIn(0f, 1f)
+ return 1f - t * (1f - MIN_GLASS_RESOLUTION_SCALE)
+}
+
+/**
+ * The backdrop blur pipeline requires [android.graphics.RenderEffect] on a
+ * [android.graphics.RenderNode], which is available from Android 12 (API 31).
+ */
+fun isGlassSupported(sdkInt: Int = Build.VERSION.SDK_INT): Boolean = sdkInt >= Build.VERSION_CODES.S
+
+/**
+ * Devices Android flags as low-RAM ([ActivityManager.isLowRamDevice]) can't push the
+ * RenderEffect/RuntimeShader chain (blur + lens + vibrancy, several offscreen layers
+ * per glass surface) without dropped frames, so glass is skipped there in favor of the
+ * flat fallback color every glass call site already has for [isGlassSupported] == false.
+ */
+@Composable
+fun isLowRamDevice(): Boolean {
+ val context = LocalContext.current
+ return remember {
+ context.getSystemService(ActivityManager::class.java)?.isLowRamDevice ?: false
+ }
+}
+
+/** Combines the API-level check with the low-RAM device check; use this to gate glass. */
+@Composable
+fun isGlassAllowed(): Boolean = isGlassSupported() && !isLowRamDevice()
+
+/**
+ * Maps the user-facing vibrancy preference (0..2, default 1) to a saturation multiplier.
+ * A value of 1 matches the library's built-in vibrancy effect (saturation x1.5), 0 leaves
+ * colors untouched and 2 doubles the saturation.
+ */
+fun glassSaturation(vibrancy: Float): Float = 1f + 0.5f * vibrancy.coerceIn(0f, 2f)
+
+/**
+ * A content colour guaranteed to read against the glass it sits on.
+ *
+ * Picking purely from the app theme is not enough: what a glass pill actually
+ * shows is the content behind it, tinted by [tint] at [opacity]. A dark tint at
+ * high opacity is dark even in light mode, and a light tint is light even in
+ * dark mode — so theme-derived text goes invisible at exactly the settings a
+ * user is most likely to reach for. This composites the same two layers the
+ * surface draws and picks from the result.
+ *
+ * @param behind the colour behind the glass — the theme surface, or the screen's
+ * artwork tint where one is known.
+ * @param tint the glass surface tint; [Color.Unspecified] means untinted.
+ * @param opacity how strongly [tint] covers [behind], matching surfaceOpacity.
+ */
+fun glassContentColorFor(behind: Color, tint: Color, opacity: Float): Color {
+ val effective = if (tint.isSpecified) {
+ lerp(behind, tint, opacity.coerceIn(0f, 1f))
+ } else {
+ behind
+ }
+ // Same targets the rest of the app uses for on-surface text, so glass chrome
+ // matches ordinary content rather than being its own special case.
+ return if (effective.luminance() > 0.5f) Color(0xFF1A1A1A) else Color.White
+}
+
+/**
+ * Apple's floating pills have a thin, subtle specular line along the top edge — a
+ * hint of light, not a bold ring. The library's [Highlight.Default] (0.5dp, white @
+ * 0.5 alpha) reads as near-invisible at typical density, but a wide bright rim
+ * overshoots in the other direction, so this lands narrower and dimmer than that.
+ */
+private val EdgeHighlightWidth = 0.8f.dp
+private const val EdgeHighlightAlpha = 0.55f
+
+/**
+ * Real Liquid Glass isn't a highlight painted on at a fixed angle: Apple describes
+ * the material as dynamically bending and shaping light "in real time, every single
+ * frame," and community shader recreations implement this as one or more soft light
+ * sources drifting across the surface over time (e.g. animated via sin/cos of the
+ * frame clock). A perfectly static 45° rim reads as flat and synthetic by
+ * comparison, so the highlight's light angle slowly drifts instead of sitting still.
+ */
+private const val HighlightAngleMin = 25f
+private const val HighlightAngleMax = 65f
+private const val HighlightDriftMillis = 7000
+
+/** Midpoint of the [HighlightAngleMin]..[HighlightAngleMax] sweep — see the use site. */
+private const val HighlightAngleFrozen = (HighlightAngleMin + HighlightAngleMax) / 2f
+
+val LocalGlassEffectConfig = staticCompositionLocalOf { GlassEffectConfig() }
+
+/**
+ * While this returns true, every glass surface in scope holds the last thing it
+ * sampled instead of recording the screen again.
+ *
+ * Provided app-wide from the page's scroll state. A surface's capture is only
+ * worth taking when what is behind it has settled: during a scroll it is a
+ * full-screen recording plus a blur and a lens, per surface, per frame, for a
+ * refraction nobody can read while the page is flying past underneath.
+ */
+val LocalGlassFrozen = staticCompositionLocalOf<() -> Boolean> { { false } }
+
+/** The backdrop content (app UI) that glass surfaces sample from. */
+val LocalAppBackdrop = staticCompositionLocalOf<Backdrop> { error("No AppBackdrop provided") }
+
+/**
+ * When set, glass surfaces in scope pool one recorded+effect-processed layer
+ * per bucket this returns instead of a single reused layer — see
+ * `drawBackdrop`'s `loopBucket` parameter. Meant for surfaces sampling a
+ * backdrop whose source loops (a looping canvas video): a bucket's visual
+ * output is identical every repeat, so it only needs computing once, ever.
+ * Null (default) keeps every surface's existing single-layer behavior.
+ */
+val LocalBackdropLoopBucket = staticCompositionLocalOf<(() -> Int)?> { null }
+
+/**
+ * Whether the Apple Music-styled UI (iOS 26/27 liquid glass look, SF-style tab icons,
+ * denser glass) is active. Read by [com.convx.music.ui.screens.Screens] consumers to pick
+ * between the classic and iOS icon sets.
+ */
+val LocalAppleMusicUi = staticCompositionLocalOf { false }
+
+/**
+ * Renders this composable as a liquid glass surface sampling [LocalAppBackdrop].
+ *
+ * Applies the configured vibrancy, blur and lens refraction effects, then draws the
+ * surface tint (theme-adaptive unless the user picked a color). Effects whose
+ * parameters make them a no-op are skipped entirely to keep the RenderEffect chain
+ * as short as possible, and the backdrop is processed at [glassResolutionScale] of
+ * the surface resolution. Returns the receiver unchanged on devices without
+ * RenderEffect support.
+ *
+ * [applyEdgeEffects] controls the edge treatment that makes small pills read as
+ * physical glass: lens refraction, the specular highlight rim and the drop shadow.
+ * It should be false for large surfaces such as the full screen player, where the
+ * rim renders as a stray band of light.
+ *
+ * [blurRadiusDp] overrides the configured blur; the full screen player passes a
+ * heavier value ([PLAYER_BLUR_MULTIPLIER]x) than the clear glass pills.
+ *
+ * [shape] is restricted to [CornerBasedShape] because the backdrop lens effect throws
+ * [UnsupportedOperationException] for any other shape type.
+ */
+@Composable
+fun Modifier.liquidGlass(
+ config: GlassEffectConfig,
+ shape: CornerBasedShape = RoundedCornerShape(0.dp),
+ applyEdgeEffects: Boolean = true,
+ blurRadiusDp: Float = config.blurRadius,
+ // The nav bar and mini player want a dimmer specular rim than the default.
+ highlightAlpha: Float = EdgeHighlightAlpha,
+ // Fraction of the surface resolution the backdrop is recorded at. Defaults to
+ // [glassResolutionScale] for the blur radius (cheap, and the blur masks the
+ // upscaling) — pass 1f for a crisp full-resolution backdrop, e.g. the small
+ // glass buttons whose whole look is clear content, not heavy frost.
+ backdropScale: Float = glassResolutionScale(blurRadiusDp),
+ // Forwarded to drawBackdrop: while this returns true the surface holds its
+ // last capture instead of re-recording the screen. Used by the floating tab
+ // bar for the frames of its inline/expanded/search transition, where the
+ // bar's bounds animate and would otherwise force a full-screen re-capture
+ // plus effect chain on every frame.
+ frozen: () -> Boolean = LocalGlassFrozen.current,
+ // Forwarded to drawBackdrop: see LocalBackdropLoopBucket's doc. Defaults to
+ // whatever's provided in composition, so player control pills over a
+ // looping video pick this up without every call site naming it explicitly.
+ loopBucket: (() -> Int)? = LocalBackdropLoopBucket.current,
+ // LOCAL CHANGE: what this samples, for surfaces that hold their own.
+ // Upstream always reads [LocalAppBackdrop] because everything glassy there
+ // is app chrome over the page. Here the player is a sheet with a backdrop of
+ // its own — the artwork behind it, not the page under that — and its panes
+ // still have to be made of the same material as the bar. Null keeps the
+ // upstream behaviour, and is read after the guard above so a call outside
+ // any provider is only a problem when it actually needs one.
+ ownBackdrop: Backdrop? = null,
+ // LOCAL CHANGE: the two things a surface still owns after the material is
+ // shared. [layerBlock] is how a control moves — the press squash and the
+ // pull towards the finger the catalog's own buttons have — and [onDrawTint]
+ // is a colour of its own drawn over the shared film, for a control that is
+ // active rather than merely present. Neither says anything about what the
+ // glass IS, which is the part that now has one answer.
+ layerBlock: (GraphicsLayerScope.() -> Unit)? = null,
+ onDrawTint: (DrawScope.() -> Unit)? = null,
+): Modifier {
+ if (!isGlassAllowed()) return this
+ val backdrop = ownBackdrop ?: LocalAppBackdrop.current
+ val density = LocalDensity.current
+ val resolutionScale = backdropScale.coerceIn(0.05f, 1f)
+ // A surface that names its own condition (the tab bar, mid-fold) still
+ // obeys the app-wide one: either reason to hold the last capture is enough.
+ val appFrozen = LocalGlassFrozen.current
+ val heldStill: () -> Boolean = remember(frozen, appFrozen) {
+ if (frozen === appFrozen) frozen else ({ frozen() || appFrozen() })
+ }
+ // Pixel-sized effect parameters operate on the backdrop layer at its recorded
+ // resolution, so they are pre-multiplied by the resolution scale to keep the
+ // same visual size.
+ val blurPx = with(density) { blurRadiusDp.dp.toPx() } * resolutionScale
+ val saturation = glassSaturation(config.vibrancy)
+ val lensHeightPx = with(density) { (config.lensHeight * LENS_MAX_DP).dp.toPx() } * resolutionScale
+ val lensAmountPx = with(density) { (config.lensAmount * LENS_MAX_DP).dp.toPx() } * resolutionScale
+ // Apple's Liquid Glass is a bright, reflective material: even in dark mode it
+ // reads as a distinctly lighter "frosted" surface, not a near-black rectangle
+ // that blends into an OLED-black background. Honor an explicit user color,
+ // otherwise use a proper adaptive glass gray rather than matching the theme
+ // surface color 1:1 (which made the bar invisible over pure-black content).
+ val surfaceTintColor = if (config.surfaceTintColor.isSpecified) {
+ config.surfaceTintColor
+ } else if (MaterialTheme.colorScheme.surface.luminance() > 0.5f) {
+ Color(0xFFFAFAFA)
+ } else {
+ Color(0xFF4A4A4E)
+ }
+
+ // Translucent style short-circuits everything below: no backdrop is sampled and
+ // no RenderEffect runs, so there is nothing to configure. Content behind shows
+ // through the tint directly, which is the point — the alternative when glass is
+ // off is an opaque fill, and that reads as a black blob sitting on the content.
+ //
+ // Also taken when the platform can't do the real blur (below API 31):
+ // this used to fall through to a hardcoded opaque-black surface instead
+ // (reasoning: unblurred sharp content behind a translucent tint "reads as
+ // broken, not glass"), which is exactly the "solid black instead of any
+ // transparency" bug reported on older/low-end devices. This same
+ // translucent-tint path is already the app's own answer to "can't do a
+ // real blur, need something cheap that still respects the user's tint
+ // and opacity settings" — so route the unsupported case here too instead
+ // of a separate hardcoded fallback.
+ if (shouldUseTranslucentGlassFallback(config.style, isRenderEffectSupported())) {
+ // The film and the rim, which is what a pane of this app's glass looks
+ // like once you take the refraction away. Without the rim a flat surface
+ // beside a real one reads as a hole rather than as the same material:
+ // the edge light is most of what says "glass" at a glance, and it costs
+ // a stroked outline.
+ val flatRim = (highlightAlpha * (config.highlightOpacity / EdgeHighlightAlpha))
+ .coerceIn(0f, 1f)
+ val flatRimColor =
+ if (config.highlightColor.isSpecified) config.highlightColor else Color.White
+ return this
+ .clip(shape)
+ .background(surfaceTintColor.copy(alpha = config.surfaceOpacity.coerceIn(0f, 1f)))
+ .border(EdgeHighlightWidth, flatRimColor.copy(alpha = flatRim), shape)
+ }
+
+ // ponytail: frozen mid-sweep. The drift described at [HighlightAngleMin] was a
+ // rememberInfiniteTransition, and because glass surfaces (the nav bar above all)
+ // are on screen permanently, it re-emitted every frame forever — a measured
+ // ~45fps of full-screen capture plus three blur passes and ~400mA, at idle,
+ // with nothing on screen moving. Slowing the tween does NOT help: an infinite
+ // transition emits per frame regardless of duration.
+ //
+ // The original note here blamed LayerBackdropModifier recording the screen
+ // unconditionally, and proposed gating that. That was a misdiagnosis. The
+ // consumer side was already gated (DrawBackdropNode re-records only on a
+ // backdrop version/offset/size change). The real path was surfaceDirty: the
+ // angle was read during COMPOSITION, so every frame rebuilt this function's
+ // lambdas, made the drawBackdrop element unequal, and update() set
+ // surfaceDirty unconditionally — forcing a full re-capture. Both halves of
+ // that are now fixed (the lambdas below are remembered; update() only dirties
+ // the capture when capture params change).
+ //
+ // Remaining upgrade path, now much smaller: hold the angle as a State and read
+ // it INSIDE the highlight lambda, which HighlightNode already supports (its
+ // highlight param is a lambda and it sets shouldAutoInvalidate = false). The
+ // animation then invalidates only that node's draw — no recomposition, no
+ // element churn, no re-capture. Worth measuring before/after rather than
+ // assuming, since the numbers above were measured and these are not.
+ val animatedHighlightAngle = HighlightAngleFrozen
+
+ // Every lambda below is remembered on exactly the values it reads. Freshly
+ // allocated lambdas make the drawBackdrop element unequal, which runs its
+ // update() — and an `effects` change there invalidates the captured backdrop,
+ // costing a full re-sample plus saturation/blur/lens. Since glass sits on
+ // permanently-visible chrome, that turned any unrelated recomposition of the
+ // nav bar into a whole-screen re-capture. Stable identities let the element
+ // compare equal and skip the work entirely.
+ val shapeBlock: () -> Shape = remember(shape) { { shape } }
+
+ // BLUR keeps the frosted capture but drops the refraction and the rim, which
+ // are the parts that read as "liquid". Cheaper too: the lens is the most
+ // expensive link in the effect chain.
+ val plainBlur = config.style == GlassStyle.BLUR
+
+ val effectsBlock: BackdropEffectScope.() -> Unit = remember(
+ saturation,
+ blurPx,
+ applyEdgeEffects,
+ plainBlur,
+ lensHeightPx,
+ lensAmountPx,
+ config.depthEffect,
+ config.chromaticAberration,
+ ) {
+ {
+ if (saturation != 1f) {
+ colorControls(saturation = saturation)
+ }
+ if (blurPx > 0f) {
+ blur(blurPx)
+ }
+ if (!plainBlur &&
+ applyEdgeEffects &&
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
+ (lensHeightPx > 0f || lensAmountPx > 0f)
+ ) {
+ lens(
+ refractionHeight = lensHeightPx,
+ refractionAmount = lensAmountPx,
+ depthEffect = config.depthEffect,
+ chromaticAberration = config.chromaticAberration,
+ )
+ }
+ }
+ }
+
+ // The rim's own colour, independent of the surface tint: on a tinted pill a
+ // white rim is what reads as "lit glass", but a coloured one is the difference
+ // between chrome and neon, so it is worth exposing rather than assuming.
+ val rimColor = if (config.highlightColor.isSpecified) config.highlightColor else Color.White
+ // Call sites pass a per-component alpha (the nav bar wants a dimmer rim than a
+ // button). Scale the user's setting by it rather than replacing it, so both the
+ // per-component tuning and the preference still mean something.
+ val rimAlpha = (highlightAlpha * (config.highlightOpacity / EdgeHighlightAlpha)).coerceIn(0f, 1f)
+
+ val highlightBlock: (() -> Highlight?)? = remember(applyEdgeEffects, plainBlur, rimColor, rimAlpha, animatedHighlightAngle) {
+ if (applyEdgeEffects && !plainBlur) {
+ {
+ Highlight(
+ width = EdgeHighlightWidth,
+ style = HighlightStyle.Default(
+ color = rimColor.copy(alpha = rimAlpha),
+ angle = animatedHighlightAngle,
+ ),
+ )
+ }
+ } else {
+ null
+ }
+ }
+
+ val shadowBlock: (() -> Shadow?)? = remember(applyEdgeEffects) {
+ if (applyEdgeEffects) ({ Shadow.Default }) else null
+ }
+
+ // RenderEffect is guaranteed supported past this point — the unsupported
+ // case already returned the translucent-tint fallback above.
+ val surfaceBlock: DrawScope.() -> Unit = remember(surfaceTintColor, config.surfaceOpacity, onDrawTint) {
+ {
+ if (config.surfaceOpacity > 0f) {
+ drawRect(
+ color = surfaceTintColor.copy(alpha = config.surfaceOpacity),
+ size = size,
+ )
+ }
+ onDrawTint?.invoke(this)
+ }
+ }
+
+ return drawBackdrop(
+ backdrop = backdrop,
+ shape = shapeBlock,
+ effects = effectsBlock,
+ highlight = highlightBlock,
+ shadow = shadowBlock,
+ onDrawSurface = surfaceBlock,
+ layerBlock = layerBlock,
+ // These three were computed here and then not passed on, which quietly
+ // undid what they are for: every surface recorded the whole screen at
+ // full resolution — while the effect parameters had already been
+ // pre-multiplied for a smaller one, so the blur and the lens were also
+ // rendering at a fraction of their intended size — and the tab bar's
+ // `frozen`, the thing that stops the bar re-capturing the screen on
+ // every frame of its fold, was accepted and dropped.
+ backdropScale = resolutionScale,
+ frozen = heldStill,
+ loopBucket = loopBucket,
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/GlassWarmUp.kt b/app/src/main/java/dev/lelonio/square/ui/glass/GlassWarmUp.kt
new file mode 100644
index 0000000..e666e34
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/GlassWarmUp.kt
@@ -0,0 +1,65 @@
+package dev.lelonio.square.ui.glass
+
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.size
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.withFrameNanos
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.unit.dp
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.effects.vibrancy
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import dev.lelonio.square.ui.glass.shapes.ContinuousCapsule
+
+/**
+ * Compiles the glass shaders before anybody sees them.
+ *
+ * The first fold of the bar stuttered and every one after it was smooth, which
+ * is the signature of a shader compiled on the frame it is first needed: the
+ * lens, its chromatic aberration and the blur are RuntimeShaders, and the first
+ * draw of each pays for the compile. This draws a pane one pixel across with the
+ * same effects, once, while the app is starting — where a few dropped frames are
+ * already expected and nobody is watching a control move.
+ *
+ * And a pane one pixel across is one white pixel, which is exactly what it
+ * looked like: a dot on the left edge of the bar, riding up and down with it as
+ * it folded. So it is drawn at a hundredth of its opacity, which is enough for
+ * the shaders to be compiled for real and not enough for anyone to see, and it
+ * stops being composed once the first frames it exists for have gone by.
+ */
+@Composable
+fun GlassWarmUp(backdrop: dev.lelonio.square.ui.glass.backdrop.Backdrop) {
+ var needed by remember { mutableStateOf(true) }
+ if (!needed) return
+ LaunchedEffect(Unit) {
+ // Two frames: one to record the draw, one to be sure it reached the GPU.
+ withFrameNanos {}
+ withFrameNanos {}
+ needed = false
+ }
+ Box(
+ Modifier
+ .size(1.dp)
+ .graphicsLayer { alpha = 0.01f }
+ .drawBackdrop(
+ backdrop = backdrop,
+ shape = { ContinuousCapsule() },
+ effects = {
+ vibrancy()
+ blur(8f.dp.toPx())
+ lens(10f.dp.toPx(), 14f.dp.toPx(), chromaticAberration = true)
+ },
+ highlight = { Highlight.Default },
+ shadow = { Shadow() },
+ ),
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/InteractiveHighlight.kt b/app/src/main/java/dev/lelonio/square/ui/glass/InteractiveHighlight.kt
index 31b8db7..2492fea 100644
--- a/app/src/main/java/dev/lelonio/square/ui/glass/InteractiveHighlight.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/InteractiveHighlight.kt
@@ -23,9 +23,9 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ShaderBrush
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.util.fastCoerceIn
-import com.kyant.backdrop.RuntimeShader
-import com.kyant.backdrop.asComposeShader
-import com.kyant.backdrop.isRuntimeShaderSupported
+import dev.lelonio.square.ui.glass.backdrop.RuntimeShader
+import dev.lelonio.square.ui.glass.backdrop.asComposeShader
+import dev.lelonio.square.ui.glass.backdrop.isRuntimeShaderSupported
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidBottomTab.kt b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidBottomTab.kt
index 9cf1cc1..a1a09eb 100644
--- a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidBottomTab.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidBottomTab.kt
@@ -24,7 +24,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
-import com.kyant.shapes.Capsule
+import dev.lelonio.square.ui.glass.shapes.ContinuousCapsule
internal val LocalLiquidBottomTabScale =
staticCompositionLocalOf { { 1f } }
@@ -38,7 +38,7 @@ fun RowScope.LiquidBottomTab(
val scale = LocalLiquidBottomTabScale.current
Column(
modifier
- .clip(Capsule())
+ .clip(ContinuousCapsule())
.clickable(
interactionSource = null,
indication = null,
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidBottomTabs.kt b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidBottomTabs.kt
index 29faab7..fd99979 100644
--- a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidBottomTabs.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidBottomTabs.kt
@@ -49,18 +49,18 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastCoerceIn
import androidx.compose.ui.util.fastRoundToInt
import androidx.compose.ui.util.lerp
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.backdrops.layerBackdrop
-import com.kyant.backdrop.backdrops.rememberCombinedBackdrop
-import com.kyant.backdrop.backdrops.rememberLayerBackdrop
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.backdrop.effects.blur
-import com.kyant.backdrop.effects.lens
-import com.kyant.backdrop.effects.vibrancy
-import com.kyant.backdrop.highlight.Highlight
-import com.kyant.backdrop.shadow.InnerShadow
-import com.kyant.backdrop.shadow.Shadow
-import com.kyant.shapes.Capsule
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.effects.vibrancy
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import dev.lelonio.square.ui.glass.shapes.ContinuousCapsule
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.launch
@@ -202,21 +202,23 @@ fun LiquidBottomTabs(
.graphicsLayer {
translationX = panelOffset
}
- .drawBackdrop(
- backdrop = backdrop,
- shape = { Capsule() },
- effects = {
- vibrancy()
- blur(8f.dp.toPx())
- lens(lensDepth.toPx(), lensDepth.toPx())
- },
+ // LOCAL CHANGE: the shell is made of the app's glass, like every
+ // other pane. The puck below keeps its own recipe on purpose —
+ // what it does is press-driven, a bend and a rim that only exist
+ // while a finger is on it, which is not a material.
+ .liquidGlass(
+ config = LocalGlassEffectConfig.current,
+ shape = ContinuousCapsule(),
+ // Follows the setting like everything else; the shell of a
+ // panel switcher is not a different material from the bar.
+ blurRadiusDp = LocalGlassEffectConfig.current.blurRadius,
+ ownBackdrop = backdrop,
layerBlock = {
val progress = dampedDragAnimation.pressProgress
val scale = lerp(1f, 1f + 16f.dp.toPx() / size.width, progress)
scaleX = scale
scaleY = scale
},
- onDrawSurface = { drawRect(containerColor) }
)
.then(interactiveHighlight.modifier)
.height(height)
@@ -241,7 +243,7 @@ fun LiquidBottomTabs(
}
.drawBackdrop(
backdrop = backdrop,
- shape = { Capsule() },
+ shape = { ContinuousCapsule() },
effects = {
val progress = dampedDragAnimation.pressProgress
vibrancy()
@@ -286,7 +288,7 @@ fun LiquidBottomTabs(
.then(dampedDragAnimation.modifier)
.drawBackdrop(
backdrop = rememberCombinedBackdrop(backdrop, tabsBackdrop),
- shape = { Capsule() },
+ shape = { ContinuousCapsule() },
effects = {
val progress = dampedDragAnimation.pressProgress
lens(
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidButton.kt b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidButton.kt
index 27c6270..1d80baa 100644
--- a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidButton.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidButton.kt
@@ -30,12 +30,8 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastCoerceAtMost
import androidx.compose.ui.util.lerp
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.backdrop.effects.blur
-import com.kyant.backdrop.effects.lens
-import com.kyant.backdrop.effects.vibrancy
-import com.kyant.shapes.Capsule
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.shapes.ContinuousCapsule
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.cos
@@ -49,6 +45,14 @@ fun LiquidButton(
modifier: Modifier = Modifier,
isInteractive: Boolean = true,
tint: Color = Color.Unspecified,
+ /**
+ * A wash of this control's own, over the shared film.
+ *
+ * No longer the material — that comes from the glass configuration, like
+ * everywhere else — but still what a chip is lit with while it is the chosen
+ * one. Dropping it entirely made the filter rows in search and the library
+ * read as five identical buttons.
+ */
surfaceColor: Color = Color.Unspecified,
// LOCAL CHANGE: upstream pins the height at 48dp and the horizontal padding
// at 16dp, which silently overrode any size the caller asked for — a 62dp
@@ -56,11 +60,23 @@ fun LiquidButton(
// are parameters now, with the upstream values as defaults.
contentHeight: Dp = 48f.dp,
contentPadding: Dp = 16f.dp,
- // LOCAL CHANGE: upstream frosts these by 2dp, which is nearly clear. Next to
- // LiquidBottomTabs — 8dp — the two read as different materials: the bar looks
- // frosted and the buttons look like bare refraction. A parameter rather than
- // a new default so the upstream value is still what you get by not asking.
- blurRadius: Dp = 2f.dp,
+ // LOCAL CHANGE: how thick this button is, as a multiple of the app's own
+ // frost rather than a number of dp. Upstream pins it at 2dp and this app
+ // pinned various call sites at 8, which is how the player's controls ended
+ // up ignoring the frost setting entirely: a button on a fixed 8 beside a bar
+ // on a configurable 2 is a different material no matter where the slider is.
+ blurScale: Float = 1f,
+ /**
+ * Draws the material without sampling anything behind it.
+ *
+ * For the buttons that live in a scrolling page rather than in the chrome.
+ * A pane that moves with the content re-photographs the screen on every
+ * frame of every scroll, and the five filter chips at the top of the home
+ * page cost 8ms a frame between them — for a reflection of a page that is
+ * usually flat colour behind them anyway. The film and the rim are the same,
+ * so they still read as the same glass.
+ */
+ flat: Boolean = false,
content: @Composable RowScope.() -> Unit
) {
val animationScope = rememberCoroutineScope()
@@ -71,16 +87,30 @@ fun LiquidButton(
)
}
+ // LOCAL CHANGE: the material is the app's, not this file's. Upstream picks
+ // its own vibrancy, blur and lens here, which is right for a catalog of one
+ // component and wrong in an app where the bottom bar is the reference: next
+ // to it these buttons read as a thinner, harder glass. What stays is
+ // everything that makes this a button rather than a pane — the press squash
+ // below, the pull towards the finger, the tint of an active control.
+ val configured = LocalGlassEffectConfig.current
+ val config = if (flat) configured.copy(style = GlassStyle.TRANSPARENT) else configured
Row(
modifier
- .drawBackdrop(
- backdrop = backdrop,
- shape = { Capsule() },
- effects = {
- vibrancy()
- blur(blurRadius.toPx())
- lens(12f.dp.toPx(), 24f.dp.toPx())
- },
+ .liquidGlass(
+ config = config,
+ shape = ContinuousCapsule(),
+ blurRadiusDp = (config.blurRadius * blurScale).coerceAtLeast(0f),
+ // LOCAL CHANGE: buttons sample the screen at a fraction of their
+ // own resolution. There are a lot of them — five filter chips at
+ // the top of the home page alone — and each one is a capture plus
+ // a shader chain per frame: measured at 8ms a frame together.
+ // They are small, filmed and rounded, which is exactly where the
+ // upscaling does not show.
+ backdropScale = 0.4f,
+ // The bar's rim, so a button beside it is cut from the same pane.
+ highlightAlpha = dev.lelonio.square.ui.player.BarHighlightAlpha,
+ ownBackdrop = backdrop,
layerBlock = if (isInteractive) {
{
val width = size.width
@@ -109,15 +139,21 @@ fun LiquidButton(
} else {
null
},
- onDrawSurface = {
- if (tint.isSpecified) {
- drawRect(tint, blendMode = BlendMode.Hue)
- drawRect(tint.copy(alpha = 0.75f))
- }
- if (surfaceColor.isSpecified) {
- drawRect(surfaceColor)
+ // The shared film is drawn first; these are only what this
+ // particular control adds to it.
+ onDrawTint = if (tint.isSpecified || surfaceColor.isSpecified) {
+ {
+ if (tint.isSpecified) {
+ drawRect(tint, blendMode = BlendMode.Hue)
+ drawRect(tint.copy(alpha = 0.75f))
+ }
+ if (surfaceColor.isSpecified) {
+ drawRect(surfaceColor)
+ }
}
- }
+ } else {
+ null
+ },
)
.clickable(
interactionSource = null,
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidSlider.kt b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidSlider.kt
index cbf675d..ece8e44 100644
--- a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidSlider.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidSlider.kt
@@ -44,18 +44,18 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastCoerceIn
import androidx.compose.ui.util.fastRoundToInt
import androidx.compose.ui.util.lerp
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.backdrops.layerBackdrop
-import com.kyant.backdrop.backdrops.rememberBackdrop
-import com.kyant.backdrop.backdrops.rememberCombinedBackdrop
-import com.kyant.backdrop.backdrops.rememberLayerBackdrop
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.backdrop.effects.blur
-import com.kyant.backdrop.effects.lens
-import com.kyant.backdrop.highlight.Highlight
-import com.kyant.backdrop.shadow.InnerShadow
-import com.kyant.backdrop.shadow.Shadow
-import com.kyant.shapes.Capsule
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import dev.lelonio.square.ui.glass.shapes.ContinuousCapsule
import kotlinx.coroutines.flow.collectLatest
@Composable
@@ -144,6 +144,12 @@ fun LiquidSlider(
.matchParentSize()
.pointerInput(animationScope, trackWidth) {
fun seekTo(x: Float) {
+ // Nothing to divide by before the track has been
+ // measured, and the answer if you try is an enormous
+ // number that clamps to the end of the range — a value
+ // the user never asked for, written to wherever this
+ // slider stores itself.
+ if (trackWidth <= 0) return
val delta =
(valueRange.endInclusive - valueRange.start) * (x / trackWidth)
val target =
@@ -186,7 +192,7 @@ fun LiquidSlider(
Box(Modifier.layerBackdrop(trackBackdrop)) {
Box(
Modifier
- .clip(Capsule())
+ .clip(ContinuousCapsule())
.background(trackColor)
.pointerInput(animationScope) {
detectTapGestures { position ->
@@ -205,7 +211,7 @@ fun LiquidSlider(
Box(
Modifier
- .clip(Capsule())
+ .clip(ContinuousCapsule())
.background(accentColor)
.height(6f.dp)
.layout { measurable, constraints ->
@@ -238,7 +244,7 @@ fun LiquidSlider(
}
}
),
- shape = { Capsule() },
+ shape = { ContinuousCapsule() },
effects = {
val progress = dampedDragAnimation.pressProgress
blur(8f.dp.toPx() * (1f - progress))
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidToggle.kt b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidToggle.kt
index b0c0456..93ccb93 100644
--- a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidToggle.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidToggle.kt
@@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.isSpecified
import androidx.compose.ui.graphics.drawscope.scale
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.lerp
@@ -39,18 +40,18 @@ import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastCoerceIn
import androidx.compose.ui.util.lerp
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.backdrops.layerBackdrop
-import com.kyant.backdrop.backdrops.rememberBackdrop
-import com.kyant.backdrop.backdrops.rememberCombinedBackdrop
-import com.kyant.backdrop.backdrops.rememberLayerBackdrop
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.backdrop.effects.blur
-import com.kyant.backdrop.effects.lens
-import com.kyant.backdrop.highlight.Highlight
-import com.kyant.backdrop.shadow.InnerShadow
-import com.kyant.backdrop.shadow.Shadow
-import com.kyant.shapes.Capsule
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import dev.lelonio.square.ui.glass.shapes.ContinuousCapsule
import kotlinx.coroutines.flow.collectLatest
@Composable
@@ -58,12 +59,21 @@ fun LiquidToggle(
selected: () -> Boolean,
onSelect: (Boolean) -> Unit,
backdrop: Backdrop,
- modifier: Modifier = Modifier
+ modifier: Modifier = Modifier,
+ // LOCAL CHANGE: upstream is iOS, so its switches are iOS green. This app is
+ // tinted from whatever is playing, and a green switch in a page washed with
+ // the cover's colour is the one control that came from somewhere else.
+ // Unspecified keeps the upstream green.
+ accent: Color = Color.Unspecified
) {
val isLightTheme = !isSystemInDarkTheme()
- val accentColor =
- if (isLightTheme) Color(0xFF34C759)
- else Color(0xFF30D158)
+ val accentColor = if (accent.isSpecified) {
+ accent
+ } else if (isLightTheme) {
+ Color(0xFF34C759)
+ } else {
+ Color(0xFF30D158)
+ }
val trackColor =
if (isLightTheme) Color(0xFF787878).copy(0.2f)
else Color(0xFF787880).copy(0.36f)
@@ -130,7 +140,7 @@ fun LiquidToggle(
Box(
Modifier
.layerBackdrop(trackBackdrop)
- .clip(Capsule())
+ .clip(ContinuousCapsule())
.drawBehind {
val fraction = dampedDragAnimation.value
drawRect(lerp(trackColor, accentColor, fraction))
@@ -163,7 +173,7 @@ fun LiquidToggle(
}
}
),
- shape = { Capsule() },
+ shape = { ContinuousCapsule() },
effects = {
val progress = dampedDragAnimation.pressProgress
blur(8f.dp.toPx() * (1f - progress))
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/WaveformSeekBar.kt b/app/src/main/java/dev/lelonio/square/ui/glass/WaveformSeekBar.kt
new file mode 100644
index 0000000..ff9f3cc
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/WaveformSeekBar.kt
@@ -0,0 +1,187 @@
+/**
+ * Convx Project (C) 2026
+ * Licensed under GPL-3.0 | See git history for contributors
+ */
+
+package dev.lelonio.square.ui.glass
+
+import androidx.compose.foundation.Canvas
+import androidx.compose.foundation.gestures.detectHorizontalDragGestures
+import androidx.compose.foundation.gestures.detectTapGestures
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.State
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableFloatStateOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.withFrameMillis
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.drawWithContent
+import androidx.compose.ui.geometry.CornerRadius
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.CompositingStrategy
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.media3.common.Player
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.isActive
+import kotlin.math.floor
+import kotlin.random.Random
+
+/**
+ * Deterministic pseudo-waveform: [count] bar heights in 0..1, stable for a given
+ * [seed] (e.g. a song's mediaId hash) so every play of the same song draws the
+ * same shape. Not real amplitude data — a synthetic SoundCloud-style envelope.
+ */
+fun waveformBars(seed: Int, count: Int): FloatArray {
+ val rnd = Random(seed)
+ var prev = 0.5f
+ return FloatArray(count) {
+ // Random-walk so neighbouring bars relate (reads like audio, not white noise).
+ prev = (prev + (rnd.nextFloat() - 0.5f) * 0.6f).coerceIn(0.12f, 1f)
+ prev
+ }
+}
+
+/**
+ * A scrolling waveform that stays centered on the current playback position.
+ * Shows only a fixed [visibleBars] window — bars scroll as the song plays.
+ * Both edges fade out progressively via a horizontal alpha mask, so bars
+ * dissolve into the background instead of popping in and out.
+ * Bars are rounded pill shape.
+ */
+@Composable
+fun ScrollingWaveformSeekBar(
+ progress: () -> Float,
+ onSeek: (Float) -> Unit,
+ playedColor: Color,
+ trackColor: Color,
+ modifier: Modifier = Modifier,
+ totalBars: Int = 80,
+ visibleBars: Int = 18,
+ seed: Int = 0,
+ edgeFade: Float = 0.22f,
+) {
+ val heights = remember(seed, totalBars) { waveformBars(seed, totalBars) }
+ var dragOffset by remember { mutableStateOf<Float?>(null) }
+
+ Canvas(
+ modifier = modifier
+ // Offscreen layer + DstIn gradient = progressive fade on both sides.
+ .graphicsLayer { compositingStrategy = CompositingStrategy.Offscreen }
+ .drawWithContent {
+ drawContent()
+ drawRect(
+ brush = Brush.horizontalGradient(
+ 0f to Color.Transparent,
+ edgeFade to Color.Black,
+ 1f - edgeFade to Color.Black,
+ 1f to Color.Transparent,
+ ),
+ blendMode = BlendMode.DstIn,
+ )
+ }
+ .pointerInput(Unit) {
+ detectTapGestures { o ->
+ val frac = (o.x / size.width).coerceIn(0f, 1f)
+ val shift = (frac - 0.5f) * visibleBars / totalBars
+ onSeek(((dragOffset ?: progress()) + shift).coerceIn(0f, 1f))
+ }
+ }
+ .pointerInput(Unit) {
+ detectHorizontalDragGestures(
+ onDragStart = { o ->
+ val frac = (o.x / size.width).coerceIn(0f, 1f)
+ dragOffset = ((dragOffset ?: progress()) + (frac - 0.5f) * visibleBars / totalBars).coerceIn(0f, 1f)
+ },
+ onDragEnd = { dragOffset?.let(onSeek); dragOffset = null },
+ onDragCancel = { dragOffset = null },
+ ) { change, _ ->
+ val delta = -change.previousPosition.x + change.position.x
+ val shiftPerPx = visibleBars.toFloat() / totalBars / size.width
+ dragOffset = ((dragOffset ?: progress()) + delta * shiftPerPx).coerceIn(0f, 1f)
+ }
+ }
+ ) {
+ val n = heights.size
+ if (n == 0 || size.width <= 0f || size.height <= 0f) return@Canvas
+
+ val currentProgress = (dragOffset ?: progress()).coerceIn(0f, 1f)
+ val midY = size.height / 2f
+ val minH = size.height * 0.15f
+
+ // One fixed-width slot per visible bar. Bars are positioned from a
+ // FRACTIONAL first index, so the window glides continuously instead of
+ // jumping a whole bar at a time — that snapping is what read as lag.
+ val slot = size.width / visibleBars
+ val barWidth = slot * 0.55f
+ val centerBar = currentProgress * (n - 1)
+ val firstBar = centerBar - visibleBars / 2f
+ val startIndex = floor(firstBar).toInt()
+
+ for (i in startIndex..(startIndex + visibleBars + 1)) {
+ if (i < 0 || i >= n) continue
+
+ val x = (i - firstBar) * slot + slot / 2f
+ if (x < -slot || x > size.width + slot) continue
+
+ val h = (heights[i] * size.height * 0.9f).coerceAtLeast(minH)
+ val color = if (i <= centerBar) playedColor else trackColor
+
+ drawRoundRect(
+ color = color,
+ topLeft = Offset(x - barWidth / 2f, midY - h / 2f),
+ size = Size(barWidth, h),
+ cornerRadius = CornerRadius(barWidth / 2f),
+ )
+ }
+ }
+}
+
+/**
+ * Playback position as a 0..1 fraction. While playing it refreshes once per frame
+ * straight off the player's clock — polling on a timer makes the waveform advance in
+ * visible steps; this keeps it gliding. Backed by a float state, so callers that read
+ * it inside a draw lambda repaint without recomposing.
+ *
+ * While paused it drops to a slow poll. withFrameMillis keeps Compose's frame clock
+ * running for as long as it is awaited, so leaving the per-frame loop on while paused
+ * kept the whole app rendering at display rate with nothing on screen changing — and
+ * anything sampling a backdrop (the floating tab bar) then re-recorded the screen on
+ * every one of those ticks. The slow poll still tracks a scrub made while paused;
+ * writing an unchanged float doesn't invalidate, so it costs nothing when idle.
+ */
+@Composable
+fun rememberPlaybackFraction(player: Player, isPlaying: Boolean): State<Float> {
+ val fraction = remember { mutableFloatStateOf(0f) }
+ LaunchedEffect(player, isPlaying) {
+ fun sample() {
+ val duration = player.duration
+ fraction.floatValue = if (duration > 0L) {
+ (player.currentPosition.toFloat() / duration).coerceIn(0f, 1f)
+ } else {
+ 0f
+ }
+ }
+ if (isPlaying) {
+ while (isActive) {
+ withFrameMillis { sample() }
+ }
+ } else {
+ while (isActive) {
+ sample()
+ delay(PausedPollIntervalMs)
+ }
+ }
+ }
+ return fraction
+}
+
+/** Slow enough to keep the app idle, fast enough that a scrub while paused tracks. */
+private const val PausedPollIntervalMs = 250L
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/Backdrop.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/Backdrop.kt
new file mode 100644
index 0000000..15ae9fe
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/Backdrop.kt
@@ -0,0 +1,26 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop
+
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+
+interface Backdrop {
+
+ val isCoordinatesDependent: Boolean
+
+ fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)? = null
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/BackdropEffectScope.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/BackdropEffectScope.kt
new file mode 100644
index 0000000..681652a
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/BackdropEffectScope.kt
@@ -0,0 +1,86 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop
+
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.RenderEffect
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.LayoutDirection
+
+sealed interface BackdropEffectScope : Density, RuntimeShaderCache {
+
+ val size: Size
+
+ val layoutDirection: LayoutDirection
+
+ val shape: Shape
+
+ var padding: Float
+
+ var renderEffect: RenderEffect?
+}
+
+internal abstract class BackdropEffectScopeImpl : BackdropEffectScope, RuntimeShaderCache {
+
+ override var density: Float = 1f
+ override var fontScale: Float = 1f
+ override var size: Size = Size.Unspecified
+ override var layoutDirection: LayoutDirection = LayoutDirection.Ltr
+ override var padding: Float = 0f
+ override var renderEffect: RenderEffect? = null
+
+ private val runtimeShaderCache = RuntimeShaderCacheImpl()
+
+ override fun obtainRuntimeShader(key: String, string: String): RuntimeShader {
+ return runtimeShaderCache.obtainRuntimeShader(key, string)
+ }
+
+ // Vendored change: [contentScale] reports the size the effects actually operate
+ // on when the backdrop layer is recorded at a reduced resolution, so shader
+ // geometry (e.g. the lens size uniform) matches the layer's pixel grid.
+ fun update(scope: DrawScope, contentScale: Float = 1f): Boolean {
+ val newDensity = scope.density
+ val newFontScale = scope.fontScale
+ val newSize = if (contentScale != 1f) scope.size * contentScale else scope.size
+ val newLayoutDirection = scope.layoutDirection
+
+ val changed = newDensity != density ||
+ newFontScale != fontScale ||
+ newSize != size ||
+ newLayoutDirection != layoutDirection
+
+ if (changed) {
+ density = newDensity
+ fontScale = newFontScale
+ size = newSize
+ layoutDirection = newLayoutDirection
+ }
+
+ return changed
+ }
+
+ fun apply(effects: BackdropEffectScope.() -> Unit) {
+ padding = 0f
+ renderEffect = null
+ effects()
+ }
+
+ fun reset() {
+ density = 1f
+ fontScale = 1f
+ size = Size.Unspecified
+ layoutDirection = LayoutDirection.Ltr
+ padding = 0f
+ renderEffect = null
+ runtimeShaderCache.clear()
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/DrawBackdropModifier.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/DrawBackdropModifier.kt
new file mode 100644
index 0000000..323bae0
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/DrawBackdropModifier.kt
@@ -0,0 +1,664 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop
+
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableFloatStateOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.neverEqualPolicy
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.geometry.Rect
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.drawscope.scale
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.graphics.layer.GraphicsLayer
+import androidx.compose.ui.graphics.layer.drawLayer
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.layout.Measurable
+import androidx.compose.ui.layout.MeasureResult
+import androidx.compose.ui.layout.MeasureScope
+import androidx.compose.ui.node.DrawModifierNode
+import androidx.compose.ui.node.GlobalPositionAwareModifierNode
+import androidx.compose.ui.node.LayoutModifierNode
+import androidx.compose.ui.node.ModifierNodeElement
+import androidx.compose.ui.node.ObserverModifierNode
+import androidx.compose.ui.node.observeReads
+import androidx.compose.ui.node.requireGraphicsContext
+import androidx.compose.ui.platform.InspectorInfo
+import androidx.compose.ui.unit.Constraints
+import androidx.compose.ui.unit.IntOffset
+import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.unit.toSize
+import dev.lelonio.square.ui.glass.backdrop.backdrops.LayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.highlight.HighlightElement
+import dev.lelonio.square.ui.glass.backdrop.internal.ShapeProvider
+import dev.lelonio.square.ui.glass.backdrop.internal.recordLayer
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadowElement
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.ShadowElement
+
+private val DefaultHighlight = { Highlight.Default }
+private val DefaultShadow = { Shadow.Default }
+private val DefaultOnDrawBackdrop: DrawScope.(DrawScope.() -> Unit) -> Unit = { it() }
+private val NeverFrozen: () -> Boolean = { false }
+
+/** Defensive cap on a loop-bucket pool's size — see [DrawBackdropNode.drawBucketedLayer]. */
+private const val LoopPoolMaxSize = 64
+
+fun Modifier.drawPlainBackdrop(
+ backdrop: Backdrop,
+ shape: () -> Shape,
+ effects: BackdropEffectScope.() -> Unit,
+ layerBlock: (GraphicsLayerScope.() -> Unit)? = null,
+ exportedBackdrop: LayerBackdrop? = null,
+ onDrawBehind: (DrawScope.() -> Unit)? = null,
+ onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
+ onDrawSurface: (DrawScope.() -> Unit)? = null,
+ onDrawFront: (DrawScope.() -> Unit)? = null,
+ // Vendored addition: same meaning as [drawBackdrop]'s parameter of the same
+ // name — record the backdrop at this fraction of the surface resolution so
+ // the RenderEffect chain processes far fewer pixels. Callers must
+ // pre-multiply pixel-sized effect parameters (blur radius) by the same
+ // factor; the blur hides the upscaling. 1f keeps full resolution.
+ backdropScale: Float = 1f,
+ // While this returns true the surface reuses its last recorded backdrop
+ // instead of re-capturing the source. Meant for the frames of a transition
+ // that animates the surface's size or position: those change every frame, so
+ // the size/offset checks below force a fresh full-screen capture (plus the
+ // whole effect chain) on every one of them. Measured on the search
+ // transition: 9 frames at a 250-450ms median with the nav bar's glass on,
+ // versus 77 frames at 42ms with it off. The bar is moving and heavily
+ // blurred for those ~300ms, so reusing the previous capture is not visible.
+ frozen: () -> Boolean = NeverFrozen
+): Modifier {
+ val shapeProvider = ShapeProvider(shape)
+ return this
+ .then(
+ if (layerBlock != null) {
+ Modifier.graphicsLayer(layerBlock)
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ DrawBackdropElement(
+ backdrop = backdrop,
+ shapeProvider = shapeProvider,
+ effects = effects,
+ layerBlock = layerBlock,
+ exportedBackdrop = exportedBackdrop,
+ onDrawBehind = onDrawBehind,
+ onDrawBackdrop = onDrawBackdrop,
+ onDrawSurface = onDrawSurface,
+ onDrawFront = onDrawFront,
+ backdropScale = backdropScale.coerceIn(0.05f, 1f),
+ frozen = frozen,
+ loopBucket = null
+ )
+ )
+}
+
+fun Modifier.drawBackdrop(
+ backdrop: Backdrop,
+ shape: () -> Shape,
+ effects: BackdropEffectScope.() -> Unit,
+ highlight: (() -> Highlight?)? = DefaultHighlight,
+ shadow: (() -> Shadow?)? = DefaultShadow,
+ innerShadow: (() -> InnerShadow?)? = null,
+ layerBlock: (GraphicsLayerScope.() -> Unit)? = null,
+ exportedBackdrop: LayerBackdrop? = null,
+ onDrawBehind: (DrawScope.() -> Unit)? = null,
+ onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
+ onDrawSurface: (DrawScope.() -> Unit)? = null,
+ onDrawFront: (DrawScope.() -> Unit)? = null,
+ // Vendored addition: records the backdrop into a layer at this fraction of the
+ // surface resolution and draws it scaled back up, so the RenderEffect chain
+ // processes far fewer pixels. Pixel-sized effect parameters (blur radius, lens
+ // refraction) must be pre-multiplied by the same factor by the caller; the blur
+ // hides the upscaling. 1f keeps the original full resolution behavior.
+ backdropScale: Float = 1f,
+ // While this returns true the surface reuses its last recorded backdrop
+ // instead of re-capturing the source. Meant for the frames of a transition
+ // that animates the surface's size or position: those change every frame, so
+ // the size/offset checks below force a fresh full-screen capture (plus the
+ // whole effect chain) on every one of them. Measured on the search
+ // transition: 9 frames at a 250-450ms median with the nav bar's glass on,
+ // versus 77 frames at 42ms with it off. The bar is moving and heavily
+ // blurred for those ~300ms, so reusing the previous capture is not visible.
+ frozen: () -> Boolean = NeverFrozen,
+ // When set, this surface caches one recorded+effect-processed layer PER
+ // bucket returned here instead of a single reused layer, and replays a
+ // bucket's cached layer on repeat instead of re-recording. Meant for a
+ // backdrop whose source loops (e.g. a looping canvas video): the visual
+ // output at a given position in the loop is identical every repeat, so the
+ // whole capture + blur/lens chain only needs to run once per bucket, ever,
+ // instead of on every frame of every loop. Null (default) keeps the single-
+ // layer behavior unchanged.
+ loopBucket: (() -> Int)? = null
+): Modifier {
+ val shapeProvider = ShapeProvider(shape)
+ return this
+ .then(
+ if (layerBlock != null) {
+ Modifier.graphicsLayer(layerBlock)
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ if (innerShadow != null) {
+ InnerShadowElement(
+ shapeProvider = shapeProvider,
+ shadow = innerShadow
+ )
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ if (shadow != null) {
+ ShadowElement(
+ shapeProvider = shapeProvider,
+ shadow = shadow
+ )
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ if (highlight != null) {
+ HighlightElement(
+ shapeProvider = shapeProvider,
+ highlight = highlight
+ )
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ DrawBackdropElement(
+ backdrop = backdrop,
+ shapeProvider = shapeProvider,
+ effects = effects,
+ layerBlock = layerBlock,
+ exportedBackdrop = exportedBackdrop,
+ onDrawBehind = onDrawBehind,
+ onDrawBackdrop = onDrawBackdrop,
+ onDrawSurface = onDrawSurface,
+ onDrawFront = onDrawFront,
+ backdropScale = backdropScale.coerceIn(0.05f, 1f),
+ frozen = frozen,
+ loopBucket = loopBucket
+ )
+ )
+}
+
+private class DrawBackdropElement(
+ val backdrop: Backdrop,
+ val shapeProvider: ShapeProvider,
+ val effects: BackdropEffectScope.() -> Unit,
+ val layerBlock: (GraphicsLayerScope.() -> Unit)?,
+ val exportedBackdrop: LayerBackdrop?,
+ val onDrawBehind: (DrawScope.() -> Unit)?,
+ val onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
+ val onDrawSurface: (DrawScope.() -> Unit)?,
+ val onDrawFront: (DrawScope.() -> Unit)?,
+ val backdropScale: Float,
+ val frozen: () -> Boolean,
+ val loopBucket: (() -> Int)?
+) : ModifierNodeElement<DrawBackdropNode>() {
+
+ override fun create(): DrawBackdropNode {
+ return DrawBackdropNode(
+ backdrop = backdrop,
+ shapeProvider = shapeProvider,
+ effects = effects,
+ layerBlock = layerBlock,
+ exportedBackdrop = exportedBackdrop,
+ onDrawBehind = onDrawBehind,
+ onDrawBackdrop = onDrawBackdrop,
+ onDrawSurface = onDrawSurface,
+ onDrawFront = onDrawFront,
+ backdropScale = backdropScale,
+ frozen = frozen,
+ loopBucket = loopBucket
+ )
+ }
+
+ override fun update(node: DrawBackdropNode) {
+ // Only the parameters that feed the CAPTURE invalidate it. onDrawBehind/
+ // Surface/Front (and with them the highlight rim, shadow and tint) are
+ // painted over an already-captured layer, so a change there needs a
+ // repaint, not a re-record. Conflating the two meant any recomposition
+ // reaching a glass call site — every one of which allocates fresh
+ // lambdas — re-sampled the screen and re-ran saturation/blur/lens.
+ val captureChanged =
+ node.backdrop !== backdrop ||
+ node.shapeProvider !== shapeProvider ||
+ node.effects !== effects ||
+ node.layerBlock !== layerBlock ||
+ node.onDrawBackdrop !== onDrawBackdrop ||
+ node.backdropScale != backdropScale
+
+ node.backdrop = backdrop
+ node.shapeProvider = shapeProvider
+ node.effects = effects
+ node.layerBlock = layerBlock
+ if (node.exportedBackdrop != exportedBackdrop) {
+ node.exportedBackdrop?.layerCoordinates = null
+ node.exportedBackdrop = exportedBackdrop
+ }
+ node.onDrawBehind = onDrawBehind
+ node.onDrawBackdrop = onDrawBackdrop
+ node.onDrawSurface = onDrawSurface
+ node.onDrawFront = onDrawFront
+ node.backdropScale = backdropScale
+ node.frozen = frozen
+ if (node.loopBucket !== loopBucket) {
+ // A different bucket function (or losing/gaining one) invalidates
+ // whatever's pooled — the old buckets no longer mean anything under
+ // the new function's numbering, or looping stopped/started. Force
+ // surfaceDirty too: switching TO null must not let the single-layer
+ // path's stale recordedBackdropVersion/size fields (last touched
+ // before bucketing started, or never) accidentally read as "still
+ // valid" and skip drawing into the never-yet-recorded graphicsLayer.
+ node.loopBucket = loopBucket
+ node.surfaceDirty = true
+ }
+ if (captureChanged) {
+ node.surfaceDirty = true
+ node.clearLoopPool()
+ }
+ // Always: the overlay repaints even when the capture is reused.
+ node.invalidateDrawCache()
+ }
+
+ override fun InspectorInfo.inspectableProperties() {
+ name = "drawBackdrop"
+ properties["backdrop"] = backdrop
+ properties["shapeProvider"] = shapeProvider
+ properties["effects"] = effects
+ properties["layerBlock"] = layerBlock
+ properties["exportedBackdrop"] = exportedBackdrop
+ properties["onDrawBehind"] = onDrawBehind
+ properties["onDrawBackdrop"] = onDrawBackdrop
+ properties["onDrawSurface"] = onDrawSurface
+ properties["onDrawFront"] = onDrawFront
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is DrawBackdropElement) return false
+
+ if (backdrop != other.backdrop) return false
+ if (shapeProvider != other.shapeProvider) return false
+ if (effects != other.effects) return false
+ if (layerBlock != other.layerBlock) return false
+ if (exportedBackdrop != other.exportedBackdrop) return false
+ if (onDrawBehind != other.onDrawBehind) return false
+ if (onDrawBackdrop != other.onDrawBackdrop) return false
+ if (onDrawSurface != other.onDrawSurface) return false
+ if (onDrawFront != other.onDrawFront) return false
+ if (backdropScale != other.backdropScale) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ var result = backdrop.hashCode()
+ result = 31 * result + shapeProvider.hashCode()
+ result = 31 * result + effects.hashCode()
+ result = 31 * result + (layerBlock?.hashCode() ?: 0)
+ result = 31 * result + (exportedBackdrop?.hashCode() ?: 0)
+ result = 31 * result + (onDrawBehind?.hashCode() ?: 0)
+ result = 31 * result + onDrawBackdrop.hashCode()
+ result = 31 * result + (onDrawSurface?.hashCode() ?: 0)
+ result = 31 * result + (onDrawFront?.hashCode() ?: 0)
+ result = 31 * result + backdropScale.hashCode()
+ return result
+ }
+}
+
+private class DrawBackdropNode(
+ var backdrop: Backdrop,
+ var shapeProvider: ShapeProvider,
+ var effects: BackdropEffectScope.() -> Unit,
+ var layerBlock: (GraphicsLayerScope.() -> Unit)?,
+ var exportedBackdrop: LayerBackdrop?,
+ var onDrawBehind: (DrawScope.() -> Unit)?,
+ var onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
+ var onDrawSurface: (DrawScope.() -> Unit)?,
+ var onDrawFront: (DrawScope.() -> Unit)?,
+ var backdropScale: Float,
+ var frozen: () -> Boolean,
+ var loopBucket: (() -> Int)?
+) : LayoutModifierNode, DrawModifierNode, GlobalPositionAwareModifierNode, ObserverModifierNode, Modifier.Node() {
+
+ private val effectScope =
+ object : BackdropEffectScopeImpl() {
+
+ override val shape: Shape get() = shapeProvider.innerShape
+ }
+
+ private var graphicsLayer: GraphicsLayer? = null
+
+ // Only allocated when loopBucket is non-null. One recorded+effect-processed
+ // layer per bucket, reused forever once present — see drawBucketedLayer.
+ // Capped defensively; an evicted bucket simply re-records next visit.
+ private var loopPool: HashMap<Int, GraphicsLayer>? = null
+
+ internal fun clearLoopPool() {
+ val pool = loopPool ?: return
+ val graphicsContext = requireGraphicsContext()
+ pool.values.forEach { graphicsContext.releaseGraphicsLayer(it) }
+ pool.clear()
+ }
+
+ private val layoutLayerBlock: GraphicsLayerScope.() -> Unit = {
+ clip = true
+ shape = shapeProvider.shape
+ compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen
+ }
+
+ private var layoutCoordinates: LayoutCoordinates? by mutableStateOf(null, neverEqualPolicy())
+
+ private var padding by mutableFloatStateOf(0f)
+
+ // True whenever the surface's own state changed in a way that invalidates the
+ // previously recorded backdrop layer (element update, effect retune, first
+ // attach). When false, draw() reuses the last record unless the source content
+ // version, size or offset moved — so surface-local redraws (e.g. a glass rim
+ // highlight animation) no longer re-record the whole backdrop source per frame.
+ internal var surfaceDirty = true
+
+ private var recordedBackdropVersion: Int? = null
+ private var recordedBackdropOffset: Offset? = null
+ private var recordedBackdropSize: IntSize = IntSize.Zero
+
+ private fun currentBackdropVersion(): Int? = (backdrop as? LayerBackdrop)?.contentVersion
+
+ /** True if [rect] falls entirely inside a region [backdrop] declared static
+ * this generation — see [LayerBackdrop.isFullyStatic]. */
+ private fun isFullyStatic(rect: Rect): Boolean =
+ (backdrop as? LayerBackdrop)?.isFullyStatic(rect) == true
+
+ /** Position of this surface within the backdrop source's coordinate space. */
+ private fun currentBackdropOffset(): Offset? {
+ val source = backdrop as? LayerBackdrop ?: return null
+ val sourceCoordinates = source.layerCoordinates ?: return null
+ val selfCoordinates = layoutCoordinates ?: return null
+ return try {
+ sourceCoordinates.localPositionOf(selfCoordinates)
+ } catch (_: Exception) {
+ null
+ }
+ }
+
+ private val recordBackdropBlock: (DrawScope.() -> Unit) = {
+ val canvas = drawContext.canvas
+ val padding = padding
+ val scale = backdropScale
+
+ if (padding != 0f) {
+ canvas.translate(padding, padding)
+ }
+ // Vendored addition: draw the backdrop content downscaled so the recorded
+ // layer (and therefore the RenderEffect chain) covers fewer pixels.
+ if (scale != 1f) {
+ canvas.scale(scale, scale)
+ }
+ onDrawBackdrop {
+ with(backdrop) {
+ drawBackdrop(
+ density = effectScope,
+ coordinates = layoutCoordinates,
+ layerBlock = layerBlock
+ )
+ }
+ }
+ if (scale != 1f) {
+ canvas.scale(1f / scale, 1f / scale)
+ }
+ if (padding != 0f) {
+ canvas.translate(-padding, -padding)
+ }
+ }
+
+ /**
+ * Loop-bucket path: one recorded+effect-processed layer per bucket, computed
+ * once and reused forever after (unlike the single-layer path below, this
+ * never re-records an existing bucket just because the source's contentVersion
+ * bumped — a looping backdrop's pixels at a given bucket are the same every
+ * repeat by definition). Geometry changes (this surface itself moving or
+ * resizing) invalidate every pooled bucket, since they were all captured at
+ * the old size/offset.
+ */
+ private fun DrawScope.drawBucketedLayer(bucket: Int): Boolean {
+ val padding = padding
+ val scale = backdropScale
+ val recordSize = IntSize(
+ ((size.width * scale).toInt() + padding.toInt() * 2).coerceAtLeast(1),
+ ((size.height * scale).toInt() + padding.toInt() * 2).coerceAtLeast(1)
+ )
+ val offset = currentBackdropOffset()
+ val geometryChanged = surfaceDirty ||
+ offset != recordedBackdropOffset ||
+ recordSize != recordedBackdropSize
+ if (geometryChanged) {
+ clearLoopPool()
+ }
+ recordedBackdropOffset = offset
+ recordedBackdropSize = recordSize
+
+ val pool = loopPool ?: HashMap<Int, GraphicsLayer>().also { loopPool = it }
+ var recorded = false
+ val layer = pool.getOrPut(bucket) {
+ recorded = true
+ val newLayer = requireGraphicsContext().createGraphicsLayer()
+ recordLayer(this@DrawBackdropNode, newLayer, size = recordSize, block = recordBackdropBlock)
+ newLayer.renderEffect = effectScope.renderEffect
+ newLayer
+ }
+ if (pool.size > LoopPoolMaxSize) {
+ val staleKey = pool.keys.first { it != bucket }
+ pool.remove(staleKey)?.let { requireGraphicsContext().releaseGraphicsLayer(it) }
+ }
+
+ layer.topLeft =
+ if (padding != 0f) IntOffset(-padding.toInt(), -padding.toInt())
+ else IntOffset.Zero
+ if (scale != 1f) {
+ scale(1f / scale, pivot = Offset.Zero) {
+ drawLayer(layer)
+ }
+ } else {
+ drawLayer(layer)
+ }
+ return recorded
+ }
+
+ private val drawBackdropLayer: DrawScope.() -> Boolean = drawBackdropLayer@{
+ val bucket = loopBucket?.invoke()
+ if (bucket != null) {
+ return@drawBackdropLayer drawBucketedLayer(bucket)
+ }
+ val layer = graphicsLayer
+ if (layer != null) {
+ val padding = padding
+ val scale = backdropScale
+ val recordSize = IntSize(
+ ((size.width * scale).toInt() + padding.toInt() * 2).coerceAtLeast(1),
+ ((size.height * scale).toInt() + padding.toInt() * 2).coerceAtLeast(1)
+ )
+ val version = currentBackdropVersion()
+ val offset = currentBackdropOffset()
+
+ // Re-record only when the source pixels changed (version bump from the
+ // source's own node) or this surface's size/position moved. Non-layer
+ // backdrops have no version, so `version == null` keeps them recording
+ // every draw, matching the original behavior.
+ // Once frozen, hold the last capture. Only skip when there IS one —
+ // a surface frozen before it ever recorded would otherwise draw an
+ // empty layer.
+ val hasRecording = recordedBackdropSize != IntSize.Zero
+ val geometryChanged = surfaceDirty ||
+ offset != recordedBackdropOffset ||
+ recordSize != recordedBackdropSize
+ val versionChanged = version == null || version != recordedBackdropVersion
+ // A version bump with nothing of ours moved only needs a re-record if
+ // the changed pixels could be ours. If our whole capture rect falls
+ // inside a region declared static THIS generation (backdropStaticRegion),
+ // the bump is provably from elsewhere — reuse the capture. Undeclared or
+ // partially-covered rects fail safe to the original always-record path.
+ val versionChangeIsElsewhere = versionChanged && !geometryChanged &&
+ offset != null && isFullyStatic(Rect(offset, recordSize.toSize()))
+ // Frozen holds the last capture — but only while this surface is
+ // where it was when it took it. A pane that has moved and kept its
+ // old recording is reflecting somewhere else on the screen: the mini
+ // player sliding as the bar folds showed the page from the position
+ // it used to be in, not the one under it.
+ val needsRecord = if (frozen() && hasRecording && !geometryChanged) {
+ false
+ } else {
+ (geometryChanged || versionChanged) && !versionChangeIsElsewhere
+ }
+ if (needsRecord) {
+ recordLayer(
+ this@DrawBackdropNode,
+ layer,
+ size = recordSize,
+ block = recordBackdropBlock
+ )
+ recordedBackdropVersion = version
+ recordedBackdropOffset = offset
+ recordedBackdropSize = recordSize
+ }
+
+ layer.topLeft =
+ if (padding != 0f) IntOffset(-padding.toInt(), -padding.toInt())
+ else IntOffset.Zero
+ if (scale != 1f) {
+ // Vendored addition: stretch the low resolution layer back over the
+ // full surface; the blur in the effect chain masks the upscaling.
+ scale(1f / scale, pivot = Offset.Zero) {
+ drawLayer(layer)
+ }
+ } else {
+ drawLayer(layer)
+ }
+ needsRecord
+ } else {
+ false
+ }
+ }
+
+ override fun MeasureScope.measure(
+ measurable: Measurable,
+ constraints: Constraints
+ ): MeasureResult {
+ val placeable = measurable.measure(constraints)
+ return layout(placeable.width, placeable.height) {
+ placeable.placeWithLayer(IntOffset.Zero, layerBlock = layoutLayerBlock)
+ }
+ }
+
+ override fun ContentDrawScope.draw() {
+ if (effectScope.update(this, backdropScale)) {
+ updateEffects()
+ }
+
+ onDrawBehind?.invoke(this)
+ val contentRecorded = drawBackdropLayer()
+ onDrawSurface?.invoke(this)
+ drawContent()
+ onDrawFront?.invoke(this)
+
+ exportedBackdrop?.graphicsLayer?.let { layer ->
+ if (surfaceDirty || contentRecorded) {
+ recordLayer(this@DrawBackdropNode, layer) {
+ onDrawBehind?.invoke(this)
+ drawBackdropLayer()
+ onDrawSurface?.invoke(this)
+ onDrawFront?.invoke(this)
+ }
+ }
+ }
+ surfaceDirty = false
+ }
+
+ override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
+ if (coordinates.isAttached) {
+ if (backdrop.isCoordinatesDependent) {
+ layoutCoordinates = coordinates
+ } else {
+ if (layoutCoordinates != null) {
+ layoutCoordinates = null
+ }
+ }
+ exportedBackdrop?.layerCoordinates = coordinates
+ }
+ }
+
+ override fun onObservedReadsChanged() {
+ surfaceDirty = true
+ invalidateDrawCache()
+ }
+
+ fun invalidateDrawCache() {
+ observeEffects()
+ }
+
+ private fun observeEffects() {
+ observeReads { updateEffects() }
+ }
+
+ private fun updateEffects() {
+ if (!isRenderEffectSupported()) return
+
+ effectScope.apply(effects)
+ graphicsLayer?.renderEffect = effectScope.renderEffect
+ val newPadding = effectScope.padding
+ if (newPadding != padding) {
+ padding = newPadding
+ surfaceDirty = true
+ }
+ }
+
+ override fun onAttach() {
+ val graphicsContext = requireGraphicsContext()
+ graphicsLayer = graphicsContext.createGraphicsLayer()
+
+ surfaceDirty = true
+ observeEffects()
+ }
+
+ override fun onDetach() {
+ val graphicsContext = requireGraphicsContext()
+ graphicsLayer?.let { layer ->
+ graphicsContext.releaseGraphicsLayer(layer)
+ graphicsLayer = null
+ }
+ clearLoopPool()
+
+ effectScope.reset()
+ layoutCoordinates = null
+ exportedBackdrop?.layerCoordinates = null
+ recordedBackdropVersion = null
+ recordedBackdropOffset = null
+ recordedBackdropSize = IntSize.Zero
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/Platform.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/Platform.kt
new file mode 100644
index 0000000..e5d7daa
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/Platform.kt
@@ -0,0 +1,19 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop
+
+import android.os.Build
+import androidx.annotation.ChecksSdkIntAtLeast
+
+@ChecksSdkIntAtLeast(Build.VERSION_CODES.S)
+fun isRenderEffectSupported(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
+
+@ChecksSdkIntAtLeast(Build.VERSION_CODES.TIRAMISU)
+fun isRuntimeShaderSupported(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/RuntimeShader.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/RuntimeShader.kt
new file mode 100644
index 0000000..1a0227d
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/RuntimeShader.kt
@@ -0,0 +1,96 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop
+
+import android.os.Build
+import androidx.annotation.RequiresApi
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.Shader
+import androidx.compose.ui.graphics.toArgb
+import org.intellij.lang.annotations.Language
+
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
+fun RuntimeShader(@Language("AGSL") shaderString: String): RuntimeShader {
+ val shader = android.graphics.RuntimeShader(shaderString)
+ return AndroidRuntimeShader(shader)
+}
+
+fun RuntimeShader.asComposeShader(): Shader {
+ return this.asAndroidRuntimeShader()
+}
+
+fun RuntimeShader.asAndroidRuntimeShader(): android.graphics.RuntimeShader {
+ return (this as AndroidRuntimeShader).shader
+}
+
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
+internal class AndroidRuntimeShader(val shader: android.graphics.RuntimeShader) : RuntimeShader {
+
+ override fun setFloatUniform(name: String, value: Float) {
+ shader.setFloatUniform(name, value)
+ }
+
+ override fun setFloatUniform(name: String, value1: Float, value2: Float) {
+ shader.setFloatUniform(name, value1, value2)
+ }
+
+ override fun setFloatUniform(name: String, value1: Float, value2: Float, value3: Float) {
+ shader.setFloatUniform(name, value1, value2, value3)
+ }
+
+ override fun setFloatUniform(name: String, value1: Float, value2: Float, value3: Float, value4: Float) {
+ shader.setFloatUniform(name, value1, value2, value3, value4)
+ }
+
+ override fun setFloatUniform(name: String, values: FloatArray) {
+ shader.setFloatUniform(name, values)
+ }
+
+ override fun setIntUniform(name: String, value: Int) {
+ shader.setIntUniform(name, value)
+ }
+
+ override fun setIntUniform(name: String, value1: Int, value2: Int) {
+ shader.setIntUniform(name, value1, value2)
+ }
+
+ override fun setIntUniform(name: String, value1: Int, value2: Int, value3: Int) {
+ shader.setIntUniform(name, value1, value2, value3)
+ }
+
+ override fun setIntUniform(name: String, value1: Int, value2: Int, value3: Int, value4: Int) {
+ shader.setIntUniform(name, value1, value2, value3, value4)
+ }
+
+ override fun setIntUniform(name: String, values: IntArray) {
+ shader.setIntUniform(name, values)
+ }
+
+ override fun setColorUniform(name: String, color: Color) {
+ shader.setColorUniform(name, color.toArgb())
+ }
+}
+
+interface RuntimeShader {
+
+ fun setFloatUniform(name: String, value: Float)
+ fun setFloatUniform(name: String, value1: Float, value2: Float)
+ fun setFloatUniform(name: String, value1: Float, value2: Float, value3: Float)
+ fun setFloatUniform(name: String, value1: Float, value2: Float, value3: Float, value4: Float)
+ fun setFloatUniform(name: String, values: FloatArray)
+
+ fun setIntUniform(name: String, value: Int)
+ fun setIntUniform(name: String, value1: Int, value2: Int)
+ fun setIntUniform(name: String, value1: Int, value2: Int, value3: Int)
+ fun setIntUniform(name: String, value1: Int, value2: Int, value3: Int, value4: Int)
+ fun setIntUniform(name: String, values: IntArray)
+
+ fun setColorUniform(name: String, color: Color)
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/RuntimeShaderCache.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/RuntimeShaderCache.kt
new file mode 100644
index 0000000..c1b2b76
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/RuntimeShaderCache.kt
@@ -0,0 +1,30 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop
+
+import org.intellij.lang.annotations.Language
+
+sealed interface RuntimeShaderCache {
+
+ fun obtainRuntimeShader(key: String, @Language("AGSL") string: String): RuntimeShader
+}
+
+internal class RuntimeShaderCacheImpl : RuntimeShaderCache {
+
+ private val runtimeShaders = mutableMapOf<String, RuntimeShader>()
+
+ override fun obtainRuntimeShader(key: String, string: String): RuntimeShader {
+ return runtimeShaders.getOrPut(key) { RuntimeShader(string) }
+ }
+
+ fun clear() {
+ runtimeShaders.clear()
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/Backdrop.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/Backdrop.kt
new file mode 100644
index 0000000..7b040fe
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/Backdrop.kt
@@ -0,0 +1,46 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+
+@Composable
+fun rememberBackdrop(
+ backdrop: Backdrop,
+ onDraw: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit
+): Backdrop {
+ return remember(backdrop, onDraw) {
+ Backdrop(backdrop, onDraw)
+ }
+}
+
+@Immutable
+private class Backdrop(
+ val backdrop: Backdrop,
+ val onDraw: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean = backdrop.isCoordinatesDependent
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ onDraw { with(backdrop) { drawBackdrop(density, coordinates, layerBlock) } }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/BackdropFreeze.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/BackdropFreeze.kt
new file mode 100644
index 0000000..b2d25ca
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/BackdropFreeze.kt
@@ -0,0 +1,55 @@
+/*
+ * Convx Project (C) 2026
+ * Licensed under GPL-3.0 | See git history for contributors
+ */
+package dev.lelonio.square.ui.glass.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
+import androidx.compose.ui.input.nestedscroll.NestedScrollSource
+import androidx.compose.ui.unit.Velocity
+
+private const val BackdropFreezeSafetyNs = 900_000_000L
+
+/**
+ * Scroll-driven freeze for a screen-local [layerBackdrop]. Mirrors MainActivity's
+ * app-level backdrop freeze (the same pattern measured there: 47ms of layer.record
+ * per scroll frame with the freeze off, 1.9ms with it on).
+ *
+ * The clock is a PLAIN array, deliberately not snapshot state: [frozen] runs in the
+ * draw phase, so a snapshot read there registers a draw dependency and every write
+ * re-invalidates the frame (the exact trap documented at MainActivity.kt:1253).
+ *
+ * Attach [connection] to an ancestor of the scrolling list (`.nestedScroll(...)`)
+ * and pass [frozen] to [layerBackdrop]'s `frozen` param.
+ */
+class BackdropFreeze {
+ private val scrollClockNs = longArrayOf(0L)
+
+ val frozen: () -> Boolean = {
+ val started = scrollClockNs[0]
+ // Elapsed check is only a safety net for gestures that never deliver
+ // onPostFling (e.g. cancelled); onPostFling is the normal reset path.
+ started != 0L && System.nanoTime() - started < BackdropFreezeSafetyNs
+ }
+
+ val connection: NestedScrollConnection = object : NestedScrollConnection {
+ override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
+ scrollClockNs[0] = System.nanoTime()
+ return Offset.Zero
+ }
+
+ override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
+ // End of the whole drag+fling sequence. The content settles, then the
+ // screen's chrome redraws and records the fresh capture — no explicit
+ // invalidation needed.
+ scrollClockNs[0] = 0L
+ return Velocity.Zero
+ }
+ }
+}
+
+@Composable
+fun rememberBackdropFreeze(): BackdropFreeze = remember { BackdropFreeze() }
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/BackdropStaticRegion.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/BackdropStaticRegion.kt
new file mode 100644
index 0000000..bc08fed
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/BackdropStaticRegion.kt
@@ -0,0 +1,92 @@
+/*
+ * Convx Project (C) 2026
+ * Licensed under GPL-3.0 | See git history for contributors
+ */
+package dev.lelonio.square.ui.glass.backdrop.backdrops
+
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.geometry.Rect
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.node.DrawModifierNode
+import androidx.compose.ui.node.GlobalPositionAwareModifierNode
+import androidx.compose.ui.node.ModifierNodeElement
+import androidx.compose.ui.platform.InspectorInfo
+import androidx.compose.ui.unit.toSize
+
+/**
+ * Declares this composable's own bounds as provably static for the current
+ * frame: its drawn pixels do not change, so a glass surface sampling [backdrop]
+ * whose capture rect falls entirely inside a declared static region can reuse
+ * its last capture instead of re-recording on a [backdrop] content-version bump
+ * caused by unrelated content elsewhere in the same source subtree (see
+ * [LayerBackdrop.isFullyStatic] and its use in `DrawBackdropNode`).
+ *
+ * Fails safe: an undeclared region, or one only partially covered, is always
+ * treated as changed — today's existing behaviour. A missed declaration costs a
+ * missed optimization, never a stale pixel. Re-declares every frame this draws;
+ * [LayerBackdropNode.draw] clears all declarations at the start of every
+ * generation, so a region that stops being drawn here also stops being trusted.
+ *
+ * Only meaningful when nothing else paints over this composable's bounds within
+ * the same backdrop subtree for the current frame — e.g. a full-bleed background
+ * image with no scrolling content currently drawn on top of it in that screen
+ * area. Wrapping something that shares its rect with changing content elsewhere
+ * silently defeats the guarantee this makes to sampling glass surfaces.
+ */
+fun Modifier.backdropStaticRegion(backdrop: LayerBackdrop): Modifier =
+ this then BackdropStaticRegionElement(backdrop)
+
+private class BackdropStaticRegionElement(
+ val backdrop: LayerBackdrop
+) : ModifierNodeElement<BackdropStaticRegionNode>() {
+
+ override fun create(): BackdropStaticRegionNode = BackdropStaticRegionNode(backdrop)
+
+ override fun update(node: BackdropStaticRegionNode) {
+ node.backdrop = backdrop
+ }
+
+ override fun InspectorInfo.inspectableProperties() {
+ name = "backdropStaticRegion"
+ properties["backdrop"] = backdrop
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is BackdropStaticRegionElement) return false
+ return backdrop == other.backdrop
+ }
+
+ override fun hashCode(): Int = backdrop.hashCode()
+}
+
+private class BackdropStaticRegionNode(
+ var backdrop: LayerBackdrop
+) : DrawModifierNode, GlobalPositionAwareModifierNode, Modifier.Node() {
+
+ private var coordinates: LayoutCoordinates? = null
+
+ override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
+ this.coordinates = coordinates.takeIf { it.isAttached }
+ }
+
+ override fun ContentDrawScope.draw() {
+ val self = coordinates
+ val source = backdrop.layerCoordinates
+ if (self != null && source != null) {
+ try {
+ val topLeft = source.localPositionOf(self)
+ backdrop.staticRegions.add(Rect(topLeft, self.size.toSize()))
+ } catch (_: Exception) {
+ // Position unavailable this frame: simply don't declare. The
+ // fail-safe default (always record) applies as if undeclared.
+ }
+ }
+ drawContent()
+ }
+
+ override fun onDetach() {
+ coordinates = null
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/CanvasBackdrop.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/CanvasBackdrop.kt
new file mode 100644
index 0000000..d2a4952
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/CanvasBackdrop.kt
@@ -0,0 +1,44 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+
+@Composable
+fun rememberCanvasBackdrop(
+ onDraw: DrawScope.() -> Unit
+): Backdrop {
+ return remember(onDraw) {
+ CanvasBackdrop(onDraw)
+ }
+}
+
+@Immutable
+private class CanvasBackdrop(
+ val onDraw: DrawScope.() -> Unit
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean = false
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ onDraw()
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/CombinedBackdrop.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/CombinedBackdrop.kt
new file mode 100644
index 0000000..f9452a3
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/CombinedBackdrop.kt
@@ -0,0 +1,108 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+
+@Composable
+fun rememberCombinedBackdrop(
+ backdrop1: Backdrop,
+ backdrop2: Backdrop
+): Backdrop {
+ return remember(backdrop1, backdrop2) {
+ Combined2Backdrops(backdrop1, backdrop2)
+ }
+}
+
+@Composable
+fun rememberCombinedBackdrop(
+ backdrop1: Backdrop,
+ backdrop2: Backdrop,
+ backdrop3: Backdrop
+): Backdrop {
+ return remember(backdrop1, backdrop2, backdrop3) {
+ Combined3Backdrops(backdrop1, backdrop2, backdrop3)
+ }
+}
+
+@Composable
+fun rememberCombinedBackdrop(vararg backdrops: Backdrop): Backdrop {
+ return remember(*backdrops) {
+ CombinedBackdrops(*backdrops)
+ }
+}
+
+@Immutable
+private class Combined2Backdrops(
+ val backdrop1: Backdrop,
+ val backdrop2: Backdrop
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean =
+ backdrop1.isCoordinatesDependent || backdrop2.isCoordinatesDependent
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ with(backdrop1) { drawBackdrop(density, coordinates, layerBlock) }
+ with(backdrop2) { drawBackdrop(density, coordinates, layerBlock) }
+ }
+}
+
+@Immutable
+private class Combined3Backdrops(
+ val backdrop1: Backdrop,
+ val backdrop2: Backdrop,
+ val backdrop3: Backdrop
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean =
+ backdrop1.isCoordinatesDependent ||
+ backdrop2.isCoordinatesDependent ||
+ backdrop3.isCoordinatesDependent
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ with(backdrop1) { drawBackdrop(density, coordinates, layerBlock) }
+ with(backdrop2) { drawBackdrop(density, coordinates, layerBlock) }
+ with(backdrop3) { drawBackdrop(density, coordinates, layerBlock) }
+ }
+}
+
+@Immutable
+private class CombinedBackdrops(
+ vararg val backdrops: Backdrop
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean =
+ backdrops.any { it.isCoordinatesDependent }
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ backdrops.forEach { backdrop ->
+ with(backdrop) { drawBackdrop(density, coordinates, layerBlock) }
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/EmptyBackdrop.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/EmptyBackdrop.kt
new file mode 100644
index 0000000..069d67c
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/EmptyBackdrop.kt
@@ -0,0 +1,34 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.backdrops
+
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+
+@Stable
+fun emptyBackdrop(): Backdrop = EmptyBackdrop
+
+@Immutable
+private object EmptyBackdrop : Backdrop {
+
+ override val isCoordinatesDependent: Boolean = false
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/LayerBackdrop.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/LayerBackdrop.kt
new file mode 100644
index 0000000..00879d3
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/LayerBackdrop.kt
@@ -0,0 +1,141 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Stable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.geometry.Rect
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.drawscope.withTransform
+import androidx.compose.ui.graphics.layer.GraphicsLayer
+import androidx.compose.ui.graphics.layer.drawLayer
+import androidx.compose.ui.graphics.rememberGraphicsLayer
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.layout.positionInWindow
+import androidx.compose.ui.unit.Density
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.internal.InverseLayerScope
+
+private val DefaultOnDraw: ContentDrawScope.() -> Unit = { drawContent() }
+
+@Composable
+fun rememberLayerBackdrop(
+ graphicsLayer: GraphicsLayer = rememberGraphicsLayer(),
+ onDraw: ContentDrawScope.() -> Unit = DefaultOnDraw
+): LayerBackdrop {
+ return remember(graphicsLayer, onDraw) {
+ LayerBackdrop(graphicsLayer, onDraw)
+ }
+}
+
+@Stable
+class LayerBackdrop internal constructor(
+ val graphicsLayer: GraphicsLayer,
+ internal val onDraw: ContentDrawScope.() -> Unit
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean = true
+
+ internal var layerCoordinates: LayoutCoordinates? by mutableStateOf(null)
+
+ /**
+ * Monotonic counter bumped by [LayerBackdropModifier]'s node each time this
+ * backdrop's content is re-recorded. Glass surfaces read it during their draw
+ * pass to skip re-recording their own layers when the source is static (e.g.
+ * a surface-local animation such as the rim highlight drift), which used to
+ * re-capture the whole screen on every frame.
+ *
+ * Deliberately a plain field, NOT snapshot state. It is written during the
+ * draw phase and read during the draw phase by every sampling glass surface;
+ * as snapshot state that read registered a draw dependency, so the write at
+ * the end of each frame invalidated every surface, which dirtied the root
+ * layer, which re-ran this node's draw and bumped the counter again. That
+ * loop redrew the whole app at the GPU's maximum rate forever, on every
+ * screen, with nothing on screen moving — measured 394 draws in 5s on a
+ * static settings list, with no recomposition, measure or layout in the
+ * trace. Freshness does not depend on the invalidation: a surface's recorded
+ * layer replays this backdrop's RenderNode by reference, so re-recording the
+ * source is picked up without the surface re-recording anything.
+ */
+ internal var contentVersion: Int = 0
+ private set
+
+ /** Called by the recording node after a successful record. */
+ internal fun contentRecorded() {
+ contentVersion++
+ }
+
+ /**
+ * Regions declared static THIS generation by [backdropStaticRegion] children,
+ * in this backdrop's own coordinate space. Plain list, not snapshot state, for
+ * the same draw-phase-write reason as [contentVersion]. Cleared and rebuilt by
+ * [LayerBackdropNode.draw] every time the source re-records, so a stale
+ * declaration from a since-removed or since-changed composable never lingers
+ * past the generation it was made in.
+ */
+ internal val staticRegions = ArrayList<Rect>()
+
+ /**
+ * True if [rect] (in this backdrop's coordinate space) falls entirely inside a
+ * single region declared static this generation. Deliberately checks a single
+ * covering rect rather than the union of several: a target only partly covered
+ * by static declarations is treated as unstable rather than pulled into
+ * region-union math, so a miss only costs a skipped optimization, never a
+ * stale pixel on a sampling glass surface.
+ */
+ internal fun isFullyStatic(rect: Rect): Boolean =
+ staticRegions.any { region ->
+ region.left <= rect.left && region.top <= rect.top &&
+ region.right >= rect.right && region.bottom >= rect.bottom
+ }
+
+ /**
+ * True once the source has been recorded at least once. Freezing before that would
+ * leave sampling surfaces replaying an empty layer.
+ */
+ internal val hasRecording: Boolean get() = contentVersion > 0
+
+ private var inverseLayerScope: InverseLayerScope? = null
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ val coordinates = coordinates ?: return
+ val layerCoordinates = layerCoordinates ?: return
+ withTransform({
+ if (layerBlock != null) {
+ with(obtainInverseLayerScope()) { inverseTransform(density, layerBlock) }
+ }
+ val offset =
+ try {
+ layerCoordinates.localPositionOf(coordinates)
+ } catch (_: Exception) {
+ // TODO: outer transformations lead to wrong position calculation
+ coordinates.positionInWindow() - layerCoordinates.positionInWindow()
+ }
+ translate(-offset.x, -offset.y)
+ }) {
+ drawLayer(graphicsLayer)
+ }
+ }
+
+ private fun obtainInverseLayerScope(): InverseLayerScope {
+ return inverseLayerScope?.apply { reset() }
+ ?: InverseLayerScope().also { inverseLayerScope = it }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/LayerBackdropModifier.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/LayerBackdropModifier.kt
new file mode 100644
index 0000000..873c6fa
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/backdrops/LayerBackdropModifier.kt
@@ -0,0 +1,125 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.backdrops
+
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.graphics.layer.drawLayer
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.node.DrawModifierNode
+import androidx.compose.ui.node.GlobalPositionAwareModifierNode
+import androidx.compose.ui.node.ModifierNodeElement
+import androidx.compose.ui.node.invalidateDraw
+import androidx.compose.ui.platform.InspectorInfo
+import dev.lelonio.square.ui.glass.backdrop.internal.recordLayer
+
+/**
+ * @param frozen while this returns true the source is NOT re-recorded: the content is
+ * drawn straight to the screen on Compose's normal incremental path, and sampling glass
+ * surfaces keep replaying the last capture. Used during scroll, where re-recording the
+ * whole tree every frame is by far the most expensive thing the app does (measured on
+ * Home: 47ms of record with it, 1.9ms without). The screen itself stays live — only the
+ * blur behind the chrome lags, which is invisible against moving content.
+ */
+fun Modifier.layerBackdrop(
+ backdrop: LayerBackdrop,
+ frozen: () -> Boolean = { false }
+): Modifier = this then LayerBackdropElement(backdrop, frozen)
+
+private class LayerBackdropElement(
+ val backdrop: LayerBackdrop,
+ val frozen: () -> Boolean
+) : ModifierNodeElement<LayerBackdropNode>() {
+
+ override fun create(): LayerBackdropNode {
+ return LayerBackdropNode(backdrop, frozen)
+ }
+
+ override fun update(node: LayerBackdropNode) {
+ if (node.backdrop != backdrop) {
+ node.backdrop.layerCoordinates = null
+ node.backdrop = backdrop
+ }
+ node.frozen = frozen
+ node.invalidateDraw()
+ }
+
+ override fun InspectorInfo.inspectableProperties() {
+ name = "layerBackdrop"
+ properties["backdrop"] = backdrop
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is LayerBackdropElement) return false
+
+ if (backdrop != other.backdrop) return false
+ if (frozen != other.frozen) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ return 31 * backdrop.hashCode() + frozen.hashCode()
+ }
+}
+
+private class LayerBackdropNode(
+ var backdrop: LayerBackdrop,
+ var frozen: () -> Boolean
+) : DrawModifierNode, GlobalPositionAwareModifierNode, Modifier.Node() {
+
+ override fun ContentDrawScope.draw() {
+ // Cleared every generation, before children (backdropStaticRegion among
+ // them) redraw and repopulate it below — see LayerBackdrop.staticRegions.
+ backdrop.staticRegions.clear()
+
+ // Record the subtree ONCE, then composite that recording to the screen —
+ // rather than drawing the tree, then walking it a second time to record
+ // it for glass to sample.
+ //
+ // Measured on a Galaxy M34 (120Hz, 8.33ms budget) scrolling Home on v1.4:
+ // frame time was 89ms median with measure+layout at 0.03ms and the GPU at
+ // 4ms, i.e. essentially all of it in display-list recording — 38.6ms
+ // median, 42.9ms p90. Recording cost scales with the number of draw ops in
+ // the tree, not with pixels, so the second traversal was close to a
+ // straight doubling of the frame's dominant cost. (It also explains why
+ // tuning the glass resolution scale changed nothing: that only affects GPU
+ // work, which had headroom to spare.)
+ //
+ // Safe to composite from the layer because the recorded content is what
+ // belongs on screen anyway: the app's onDraw fills an opaque background
+ // before drawContent(), so the layer is opaque and drawing it is
+ // equivalent to having drawn the tree directly.
+ // While frozen, take Compose's ordinary draw path instead. That path reuses
+ // every child RenderNode that did not change; layer.record { drawContent() }
+ // cannot, so it re-issues the whole subtree every frame. Skipping the version
+ // bump is what keeps the glass surfaces on their existing captures.
+ if (frozen() && backdrop.hasRecording) {
+ backdrop.onDraw(this@draw)
+ return
+ }
+ recordLayer(this@LayerBackdropNode, backdrop.graphicsLayer) { backdrop.onDraw(this@draw) }
+ drawLayer(backdrop.graphicsLayer)
+ // Notify sampling glass surfaces that the source pixels changed, so they
+ // re-record their own layers. When the source is static they skip it.
+ backdrop.contentRecorded()
+ }
+
+ override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
+ if (coordinates.isAttached) {
+ backdrop.layerCoordinates = coordinates
+ }
+ }
+
+ override fun onDetach() {
+ backdrop.layerCoordinates = null
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidBottomTab.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidBottomTab.kt
new file mode 100644
index 0000000..15ff790
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidBottomTab.kt
@@ -0,0 +1,62 @@
+/*
+ * Vendored from Kyant0/AndroidLiquidGlass (kmp branch)
+ * https://github.com/Kyant0/AndroidLiquidGlass — Copyright 2025 Kyant0, Apache License 2.0
+ * app/src/commonMain/kotlin/com/kyant/backdrop/catalog/components/LiquidBottomTab.kt
+ *
+ * Not published as a library — ported straight from the catalog demo app that
+ * showcases Kyant0/backdrop, source-only. Package renamed, imports repointed at
+ * this app's vendored dev.lelonio.square.ui.glass.backdrop, and
+ * com.kyant.shapes.Capsule swapped for RoundedCornerShape(percent = 50) (the
+ * lens effect only supports CornerBasedShape here — see GlassEffect.kt).
+ *
+ * Used directly by LiquidBottomTabs.kt — see that file for where it's wired in.
+ */
+package dev.lelonio.square.ui.glass.backdrop.catalog.components
+
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.ColumnScope
+import androidx.compose.foundation.layout.RowScope
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.staticCompositionLocalOf
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.unit.dp
+
+internal val LocalLiquidBottomTabScale =
+ staticCompositionLocalOf { { 1f } }
+
+@Composable
+fun RowScope.LiquidBottomTab(
+ onClick: () -> Unit,
+ modifier: Modifier = Modifier,
+ content: @Composable ColumnScope.() -> Unit
+) {
+ val scale = LocalLiquidBottomTabScale.current
+ Column(
+ modifier
+ .clip(RoundedCornerShape(percent = 50))
+ .clickable(
+ interactionSource = null,
+ indication = null,
+ role = Role.Tab,
+ onClick = onClick
+ )
+ .fillMaxHeight()
+ .weight(1f)
+ .graphicsLayer {
+ val scale = scale()
+ scaleX = scale
+ scaleY = scale
+ },
+ verticalArrangement = Arrangement.spacedBy(2f.dp, Alignment.CenterVertically),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ content = content
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidBottomTabs.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidBottomTabs.kt
new file mode 100644
index 0000000..c8b38db
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidBottomTabs.kt
@@ -0,0 +1,312 @@
+/*
+ * Vendored from Kyant0/AndroidLiquidGlass (kmp branch)
+ * https://github.com/Kyant0/AndroidLiquidGlass — Copyright 2025 Kyant0, Apache License 2.0
+ * app/src/commonMain/kotlin/com/kyant/backdrop/catalog/components/LiquidBottomTabs.kt
+ *
+ * Not published as a library — ported straight from the catalog demo app that
+ * showcases Kyant0/backdrop, source-only. Package renamed, imports repointed at
+ * this app's vendored dev.lelonio.square.ui.glass.backdrop, and
+ * com.kyant.shapes.Capsule swapped for RoundedCornerShape(percent = 50) (the
+ * lens effect only supports CornerBasedShape here — see GlassEffect.kt).
+ *
+ * Used directly by SearchScreen's Explore/Suggestions/Album pill selector.
+ * This app's own FloatingTabBar/FloatingSideBar (selection puck sync between
+ * phone bar and tablet sidebar, InteractiveHighlight, GlassEffectConfig-driven,
+ * shared-element transitions, search-tab morphing) still handles primary nav —
+ * this component is for smaller in-screen segmented pills.
+ */
+package dev.lelonio.square.ui.glass.backdrop.catalog.components
+
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.EaseOut
+import androidx.compose.animation.core.spring
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxWithConstraints
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.RowScope
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.derivedStateOf
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableIntStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.snapshotFlow
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.alpha
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ColorFilter
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.platform.LocalLayoutDirection
+import androidx.compose.ui.semantics.clearAndSetSemantics
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.util.fastCoerceIn
+import androidx.compose.ui.util.fastRoundToInt
+import androidx.compose.ui.util.lerp
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.catalog.utils.DampedDragAnimation
+import dev.lelonio.square.ui.glass.backdrop.catalog.utils.InteractiveHighlight
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.effects.vibrancy
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import kotlinx.coroutines.flow.collectLatest
+import kotlinx.coroutines.flow.drop
+import kotlinx.coroutines.launch
+import kotlin.math.abs
+import kotlin.math.sign
+
+@Composable
+fun LiquidBottomTabs(
+ selectedTabIndex: () -> Int,
+ onTabSelected: (index: Int) -> Unit,
+ backdrop: Backdrop,
+ tabsCount: Int,
+ modifier: Modifier = Modifier,
+ // Nav-bar pill defaults; pass a caller color/height to blend into a
+ // specific screen (e.g. that screen's own hero tint) instead.
+ containerColor: Color? = null,
+ height: Dp = 64.dp,
+ content: @Composable RowScope.() -> Unit
+) {
+ val isLightTheme = !isSystemInDarkTheme()
+ val accentColor =
+ if (isLightTheme) Color(0xFF0088FF)
+ else Color(0xFF0091FF)
+ val resolvedContainerColor = containerColor ?: (
+ if (isLightTheme) Color(0xFFFAFAFA).copy(0.4f)
+ else Color(0xFF121212).copy(0.4f)
+ )
+ val innerHeight = height * 0.875f
+
+ val tabsBackdrop = rememberLayerBackdrop()
+
+ BoxWithConstraints(
+ modifier,
+ contentAlignment = Alignment.CenterStart
+ ) {
+ val density = LocalDensity.current
+ val tabWidth = with(density) {
+ (constraints.maxWidth.toFloat() - 8f.dp.toPx()) / tabsCount
+ }
+
+ val offsetAnimation = remember { Animatable(0f) }
+ val panelOffset by remember(density) {
+ derivedStateOf {
+ val fraction = (offsetAnimation.value / constraints.maxWidth).fastCoerceIn(-1f, 1f)
+ with(density) {
+ 4f.dp.toPx() * fraction.sign * EaseOut.transform(abs(fraction))
+ }
+ }
+ }
+
+ val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
+ val animationScope = rememberCoroutineScope()
+ var currentIndex by remember(selectedTabIndex) {
+ mutableIntStateOf(selectedTabIndex())
+ }
+ val dampedDragAnimation = remember(animationScope) {
+ DampedDragAnimation(
+ animationScope = animationScope,
+ initialValue = selectedTabIndex().toFloat(),
+ valueRange = 0f..(tabsCount - 1).toFloat(),
+ visibilityThreshold = 0.001f,
+ initialScale = 1f,
+ pressedScale = 78f / 56f,
+ onDragStarted = {},
+ onDragStopped = {
+ val targetIndex = targetValue.fastRoundToInt().fastCoerceIn(0, tabsCount - 1)
+ currentIndex = targetIndex
+ animateToValue(targetIndex.toFloat())
+ animationScope.launch {
+ offsetAnimation.animateTo(
+ 0f,
+ spring(1f, 300f, 0.5f)
+ )
+ }
+ },
+ onDrag = { _, dragAmount ->
+ updateValue(
+ (targetValue + dragAmount.x / tabWidth * if (isLtr) 1f else -1f)
+ .fastCoerceIn(0f, (tabsCount - 1).toFloat())
+ )
+ animationScope.launch {
+ offsetAnimation.snapTo(offsetAnimation.value + dragAmount.x)
+ }
+ }
+ )
+ }
+ LaunchedEffect(selectedTabIndex) {
+ snapshotFlow { selectedTabIndex() }
+ .collectLatest { index ->
+ currentIndex = index
+ }
+ }
+ LaunchedEffect(dampedDragAnimation) {
+ snapshotFlow { currentIndex }
+ .drop(1)
+ .collectLatest { index ->
+ dampedDragAnimation.animateToValue(index.toFloat())
+ onTabSelected(index)
+ }
+ }
+
+ val interactiveHighlight = remember(animationScope) {
+ InteractiveHighlight(
+ animationScope = animationScope,
+ position = { size, offset ->
+ Offset(
+ if (isLtr) (dampedDragAnimation.value + 0.5f) * tabWidth + panelOffset
+ else size.width - (dampedDragAnimation.value + 0.5f) * tabWidth + panelOffset,
+ size.height / 2f
+ )
+ }
+ )
+ }
+
+ Row(
+ Modifier
+ .graphicsLayer {
+ translationX = panelOffset
+ }
+ .drawBackdrop(
+ backdrop = backdrop,
+ shape = { RoundedCornerShape(percent = 50) },
+ effects = {
+ vibrancy()
+ blur(8f.dp.toPx())
+ lens(24f.dp.toPx(), 24f.dp.toPx())
+ },
+ layerBlock = {
+ val progress = dampedDragAnimation.pressProgress
+ val scale = lerp(1f, 1f + 16f.dp.toPx() / size.width, progress)
+ scaleX = scale
+ scaleY = scale
+ },
+ onDrawSurface = { drawRect(resolvedContainerColor) }
+ )
+ .then(interactiveHighlight.modifier)
+ .height(height)
+ .fillMaxWidth()
+ .padding(4f.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ content = content
+ )
+
+ CompositionLocalProvider(
+ LocalLiquidBottomTabScale provides {
+ lerp(1f, 1.2f, dampedDragAnimation.pressProgress)
+ }
+ ) {
+ Row(
+ Modifier
+ .clearAndSetSemantics {}
+ .alpha(0f)
+ .layerBackdrop(tabsBackdrop)
+ .graphicsLayer {
+ translationX = panelOffset
+ }
+ .drawBackdrop(
+ backdrop = backdrop,
+ shape = { RoundedCornerShape(percent = 50) },
+ effects = {
+ val progress = dampedDragAnimation.pressProgress
+ vibrancy()
+ blur(8f.dp.toPx())
+ lens(
+ 24f.dp.toPx() * progress,
+ 24f.dp.toPx() * progress
+ )
+ },
+ highlight = {
+ val progress = dampedDragAnimation.pressProgress
+ Highlight.Default.copy(alpha = progress)
+ },
+ onDrawSurface = { drawRect(resolvedContainerColor) }
+ )
+ .then(interactiveHighlight.modifier)
+ .height(innerHeight)
+ .fillMaxWidth()
+ .padding(horizontal = 4f.dp)
+ .graphicsLayer(colorFilter = ColorFilter.tint(accentColor)),
+ verticalAlignment = Alignment.CenterVertically,
+ content = content
+ )
+ }
+
+ Box(
+ Modifier
+ .padding(horizontal = 4f.dp)
+ .graphicsLayer {
+ translationX =
+ if (isLtr) dampedDragAnimation.value * tabWidth + panelOffset
+ else size.width - (dampedDragAnimation.value + 1f) * tabWidth + panelOffset
+ }
+ .then(interactiveHighlight.gestureModifier)
+ .then(dampedDragAnimation.modifier)
+ .drawBackdrop(
+ backdrop = rememberCombinedBackdrop(backdrop, tabsBackdrop),
+ shape = { RoundedCornerShape(percent = 50) },
+ effects = {
+ val progress = dampedDragAnimation.pressProgress
+ lens(
+ 10f.dp.toPx() * progress,
+ 14f.dp.toPx() * progress,
+ chromaticAberration = true
+ )
+ },
+ highlight = {
+ val progress = dampedDragAnimation.pressProgress
+ Highlight.Default.copy(alpha = progress)
+ },
+ shadow = {
+ val progress = dampedDragAnimation.pressProgress
+ Shadow(alpha = progress)
+ },
+ innerShadow = {
+ val progress = dampedDragAnimation.pressProgress
+ InnerShadow(
+ radius = 8f.dp * progress,
+ alpha = progress
+ )
+ },
+ layerBlock = {
+ scaleX = dampedDragAnimation.scaleX
+ scaleY = dampedDragAnimation.scaleY
+ val velocity = dampedDragAnimation.velocity / 10f
+ scaleX /= 1f - (velocity * 0.75f).fastCoerceIn(-0.2f, 0.2f)
+ scaleY *= 1f - (velocity * 0.25f).fastCoerceIn(-0.2f, 0.2f)
+ },
+ onDrawSurface = {
+ val progress = dampedDragAnimation.pressProgress
+ drawRect(
+ if (isLightTheme) Color.Black.copy(0.1f)
+ else Color.White.copy(0.1f),
+ alpha = 1f - progress
+ )
+ drawRect(Color.Black.copy(alpha = 0.03f * progress))
+ }
+ )
+ .height(innerHeight)
+ .fillMaxWidth(1f / tabsCount)
+ )
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidButton.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidButton.kt
new file mode 100644
index 0000000..a936158
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidButton.kt
@@ -0,0 +1,135 @@
+/*
+ * Vendored from Kyant0/AndroidLiquidGlass (kmp branch)
+ * https://github.com/Kyant0/AndroidLiquidGlass — Copyright 2025 Kyant0, Apache License 2.0
+ * app/src/commonMain/kotlin/com/kyant/backdrop/catalog/components/LiquidButton.kt
+ *
+ * Not published as a library — ported straight from the catalog demo app that
+ * showcases Kyant0/backdrop, source-only. Package renamed, imports repointed at
+ * this app's vendored dev.lelonio.square.ui.glass.backdrop, and
+ * com.kyant.shapes.Capsule swapped for RoundedCornerShape(percent = 50) (the
+ * lens effect only supports CornerBasedShape here — see GlassEffect.kt).
+ *
+ * Not wired into any screen yet — vendored for later use.
+ */
+package dev.lelonio.square.ui.glass.backdrop.catalog.components
+
+import androidx.compose.foundation.LocalIndication
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.RowScope
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.isSpecified
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.util.fastCoerceAtMost
+import androidx.compose.ui.util.lerp
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.catalog.utils.InteractiveHighlight
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.effects.vibrancy
+import kotlin.math.abs
+import kotlin.math.atan2
+import kotlin.math.cos
+import kotlin.math.sin
+import kotlin.math.tanh
+
+@Composable
+fun LiquidButton(
+ onClick: () -> Unit,
+ backdrop: Backdrop,
+ modifier: Modifier = Modifier,
+ isInteractive: Boolean = true,
+ tint: Color = Color.Unspecified,
+ surfaceColor: Color = Color.Unspecified,
+ content: @Composable RowScope.() -> Unit
+) {
+ val animationScope = rememberCoroutineScope()
+
+ val interactiveHighlight = remember(animationScope) {
+ InteractiveHighlight(
+ animationScope = animationScope
+ )
+ }
+
+ Row(
+ modifier
+ .drawBackdrop(
+ backdrop = backdrop,
+ shape = { RoundedCornerShape(percent = 50) },
+ effects = {
+ vibrancy()
+ blur(2f.dp.toPx())
+ lens(12f.dp.toPx(), 24f.dp.toPx())
+ },
+ layerBlock = if (isInteractive) {
+ {
+ val width = size.width
+ val height = size.height
+
+ val progress = interactiveHighlight.pressProgress
+ val scale = lerp(1f, 1f + 4f.dp.toPx() / size.height, progress)
+
+ val maxOffset = size.minDimension
+ val initialDerivative = 0.05f
+ val offset = interactiveHighlight.offset
+ translationX = maxOffset * tanh(initialDerivative * offset.x / maxOffset)
+ translationY = maxOffset * tanh(initialDerivative * offset.y / maxOffset)
+
+ val maxDragScale = 4f.dp.toPx() / size.height
+ val offsetAngle = atan2(offset.y, offset.x)
+ scaleX =
+ scale +
+ maxDragScale * abs(cos(offsetAngle) * offset.x / size.maxDimension) *
+ (width / height).fastCoerceAtMost(1f)
+ scaleY =
+ scale +
+ maxDragScale * abs(sin(offsetAngle) * offset.y / size.maxDimension) *
+ (height / width).fastCoerceAtMost(1f)
+ }
+ } else {
+ null
+ },
+ onDrawSurface = {
+ if (tint.isSpecified) {
+ drawRect(tint, blendMode = BlendMode.Hue)
+ drawRect(tint.copy(alpha = 0.75f))
+ }
+ if (surfaceColor.isSpecified) {
+ drawRect(surfaceColor)
+ }
+ }
+ )
+ .clickable(
+ interactionSource = null,
+ indication = if (isInteractive) null else LocalIndication.current,
+ role = Role.Button,
+ onClick = onClick
+ )
+ .then(
+ if (isInteractive) {
+ Modifier
+ .then(interactiveHighlight.modifier)
+ .then(interactiveHighlight.gestureModifier)
+ } else {
+ Modifier
+ }
+ )
+ .height(48f.dp)
+ .padding(horizontal = 16f.dp),
+ horizontalArrangement = Arrangement.spacedBy(8f.dp, Alignment.CenterHorizontally),
+ verticalAlignment = Alignment.CenterVertically,
+ content = content
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidSlider.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidSlider.kt
new file mode 100644
index 0000000..b4b964b
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidSlider.kt
@@ -0,0 +1,223 @@
+/*
+ * Vendored from Kyant0/AndroidLiquidGlass (kmp branch)
+ * https://github.com/Kyant0/AndroidLiquidGlass — Copyright 2025 Kyant0, Apache License 2.0
+ * app/src/commonMain/kotlin/com/kyant/backdrop/catalog/components/LiquidSlider.kt
+ *
+ * Not published as a library — ported straight from the catalog demo app that
+ * showcases Kyant0/backdrop, source-only. Package renamed, imports repointed at
+ * this app's vendored dev.lelonio.square.ui.glass.backdrop, and
+ * com.kyant.shapes.Capsule swapped for RoundedCornerShape(percent = 50) (the
+ * lens effect only supports CornerBasedShape here — see GlassEffect.kt).
+ */
+package dev.lelonio.square.ui.glass.backdrop.catalog.components
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.gestures.detectTapGestures
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxWithConstraints
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.snapshotFlow
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.drawscope.scale
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.layout.layout
+import androidx.compose.ui.platform.LocalLayoutDirection
+import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.util.fastCoerceIn
+import androidx.compose.ui.util.fastRoundToInt
+import androidx.compose.ui.util.lerp
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.catalog.utils.DampedDragAnimation
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import kotlinx.coroutines.flow.collectLatest
+
+@Composable
+fun LiquidSlider(
+ value: () -> Float,
+ onValueChange: (Float) -> Unit,
+ valueRange: ClosedFloatingPointRange<Float>,
+ visibilityThreshold: Float,
+ backdrop: Backdrop,
+ modifier: Modifier = Modifier
+) {
+ val isLightTheme = !isSystemInDarkTheme()
+ val accentColor =
+ if (isLightTheme) Color(0xFF0088FF)
+ else Color(0xFF0091FF)
+ val trackColor =
+ if (isLightTheme) Color(0xFF787878).copy(0.2f)
+ else Color(0xFF787880).copy(0.36f)
+
+ val trackBackdrop = rememberLayerBackdrop()
+
+ BoxWithConstraints(
+ modifier.fillMaxWidth(),
+ contentAlignment = Alignment.CenterStart
+ ) {
+ val trackWidth = constraints.maxWidth
+
+ val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
+ val animationScope = rememberCoroutineScope()
+ var didDrag by remember { mutableStateOf(false) }
+ val dampedDragAnimation = remember(animationScope) {
+ DampedDragAnimation(
+ animationScope = animationScope,
+ initialValue = value(),
+ valueRange = valueRange,
+ visibilityThreshold = visibilityThreshold,
+ initialScale = 1f,
+ pressedScale = 1.5f,
+ onDragStarted = {},
+ onDragStopped = {
+ if (didDrag) {
+ onValueChange(targetValue)
+ }
+ },
+ onDrag = { _, dragAmount ->
+ if (!didDrag) {
+ didDrag = dragAmount.x != 0f
+ }
+ val delta = (valueRange.endInclusive - valueRange.start) * (dragAmount.x / trackWidth)
+ onValueChange(
+ if (isLtr) (targetValue + delta).coerceIn(valueRange)
+ else (targetValue - delta).coerceIn(valueRange)
+ )
+ }
+ )
+ }
+ LaunchedEffect(dampedDragAnimation) {
+ snapshotFlow { value() }
+ .collectLatest { value ->
+ if (dampedDragAnimation.targetValue != value) {
+ dampedDragAnimation.updateValue(value)
+ }
+ }
+ }
+
+ Box(Modifier.layerBackdrop(trackBackdrop)) {
+ Box(
+ Modifier
+ .clip(RoundedCornerShape(percent = 50))
+ .background(trackColor)
+ .pointerInput(animationScope) {
+ detectTapGestures { position ->
+ val delta = (valueRange.endInclusive - valueRange.start) * (position.x / trackWidth)
+ val targetValue =
+ (if (isLtr) valueRange.start + delta
+ else valueRange.endInclusive - delta)
+ .coerceIn(valueRange)
+ dampedDragAnimation.animateToValue(targetValue)
+ onValueChange(targetValue)
+ }
+ }
+ .height(6f.dp)
+ .fillMaxWidth()
+ )
+
+ Box(
+ Modifier
+ .clip(RoundedCornerShape(percent = 50))
+ .background(accentColor)
+ .height(6f.dp)
+ .layout { measurable, constraints ->
+ val placeable = measurable.measure(constraints)
+ val width = (constraints.maxWidth * dampedDragAnimation.progress).fastRoundToInt()
+ layout(width, placeable.height) {
+ placeable.place(0, 0)
+ }
+ }
+ )
+ }
+
+ Box(
+ Modifier
+ .graphicsLayer {
+ translationX =
+ (-size.width / 2f + trackWidth * dampedDragAnimation.progress)
+ .fastCoerceIn(-size.width / 4f, trackWidth - size.width * 3f / 4f) * if (isLtr) 1f else -1f
+ }
+ .then(dampedDragAnimation.modifier)
+ .drawBackdrop(
+ backdrop = rememberCombinedBackdrop(
+ backdrop,
+ rememberBackdrop(trackBackdrop) { drawBackdrop ->
+ val progress = dampedDragAnimation.pressProgress
+ val scaleX = lerp(2f / 3f, 1f, progress)
+ val scaleY = lerp(0f, 1f, progress)
+ scale(scaleX, scaleY) {
+ drawBackdrop()
+ }
+ }
+ ),
+ shape = { RoundedCornerShape(percent = 50) },
+ effects = {
+ val progress = dampedDragAnimation.pressProgress
+ blur(8f.dp.toPx() * (1f - progress))
+ lens(
+ 10f.dp.toPx() * progress,
+ 14f.dp.toPx() * progress,
+ chromaticAberration = true
+ )
+ },
+ highlight = {
+ val progress = dampedDragAnimation.pressProgress
+ Highlight.Ambient.copy(
+ width = Highlight.Ambient.width / 1.5f,
+ blurRadius = Highlight.Ambient.blurRadius / 1.5f,
+ alpha = progress
+ )
+ },
+ shadow = {
+ Shadow(
+ radius = 4f.dp,
+ color = Color.Black.copy(alpha = 0.05f)
+ )
+ },
+ innerShadow = {
+ val progress = dampedDragAnimation.pressProgress
+ InnerShadow(
+ radius = 4f.dp * progress,
+ alpha = progress
+ )
+ },
+ layerBlock = {
+ scaleX = dampedDragAnimation.scaleX
+ scaleY = dampedDragAnimation.scaleY
+ val velocity = dampedDragAnimation.velocity / 10f
+ scaleX /= 1f - (velocity * 0.75f).fastCoerceIn(-0.2f, 0.2f)
+ scaleY *= 1f - (velocity * 0.25f).fastCoerceIn(-0.2f, 0.2f)
+ },
+ onDrawSurface = {
+ val progress = dampedDragAnimation.pressProgress
+ drawRect(Color.White.copy(alpha = 1f - progress))
+ }
+ )
+ .size(40f.dp, 24f.dp)
+ )
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidToggle.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidToggle.kt
new file mode 100644
index 0000000..e090b70
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/components/LiquidToggle.kt
@@ -0,0 +1,216 @@
+/*
+ * Vendored from Kyant0/AndroidLiquidGlass (kmp branch)
+ * https://github.com/Kyant0/AndroidLiquidGlass — Copyright 2025 Kyant0, Apache License 2.0
+ * app/src/commonMain/kotlin/com/kyant/backdrop/catalog/components/LiquidToggle.kt
+ *
+ * Not published as a library — ported straight from the catalog demo app that
+ * showcases Kyant0/backdrop, source-only. Package renamed, imports repointed at
+ * this app's vendored dev.lelonio.square.ui.glass.backdrop, and
+ * com.kyant.shapes.Capsule swapped for RoundedCornerShape(percent = 50) (the
+ * lens effect only supports CornerBasedShape here — see GlassEffect.kt).
+ *
+ * Not wired into any screen yet — vendored for later use.
+ */
+package dev.lelonio.square.ui.glass.backdrop.catalog.components
+
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableFloatStateOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.snapshotFlow
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.drawBehind
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.drawscope.scale
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.graphics.lerp
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.platform.LocalLayoutDirection
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.semantics.role
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.util.fastCoerceIn
+import androidx.compose.ui.util.lerp
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.catalog.utils.DampedDragAnimation
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import kotlinx.coroutines.flow.collectLatest
+
+@Composable
+fun LiquidToggle(
+ selected: () -> Boolean,
+ onSelect: (Boolean) -> Unit,
+ backdrop: Backdrop,
+ modifier: Modifier = Modifier
+) {
+ val isLightTheme = !isSystemInDarkTheme()
+ val accentColor =
+ if (isLightTheme) Color(0xFF34C759)
+ else Color(0xFF30D158)
+ val trackColor =
+ if (isLightTheme) Color(0xFF787878).copy(0.2f)
+ else Color(0xFF787880).copy(0.36f)
+
+ val density = LocalDensity.current
+ val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
+ val dragWidth = with(density) { 20f.dp.toPx() }
+ val animationScope = rememberCoroutineScope()
+ var didDrag by remember { mutableStateOf(false) }
+ var fraction by remember { mutableFloatStateOf(if (selected()) 1f else 0f) }
+ val dampedDragAnimation = remember(animationScope) {
+ DampedDragAnimation(
+ animationScope = animationScope,
+ initialValue = fraction,
+ valueRange = 0f..1f,
+ visibilityThreshold = 0.001f,
+ initialScale = 1f,
+ pressedScale = 1.5f,
+ onDragStarted = {},
+ onDragStopped = {
+ if (didDrag) {
+ fraction = if (targetValue >= 0.5f) 1f else 0f
+ onSelect(fraction == 1f)
+ didDrag = false
+ } else {
+ fraction = if (selected()) 0f else 1f
+ onSelect(fraction == 1f)
+ }
+ },
+ onDrag = { _, dragAmount ->
+ if (!didDrag) {
+ didDrag = dragAmount.x != 0f
+ }
+ val delta = dragAmount.x / dragWidth
+ fraction =
+ if (isLtr) (fraction + delta).fastCoerceIn(0f, 1f)
+ else (fraction - delta).fastCoerceIn(0f, 1f)
+ }
+ )
+ }
+ LaunchedEffect(dampedDragAnimation) {
+ snapshotFlow { fraction }
+ .collectLatest { fraction ->
+ dampedDragAnimation.updateValue(fraction)
+ }
+ }
+ LaunchedEffect(selected) {
+ snapshotFlow { selected() }
+ .collectLatest { isSelected ->
+ val target = if (isSelected) 1f else 0f
+ if (target != fraction) {
+ fraction = target
+ dampedDragAnimation.animateToValue(target)
+ }
+ }
+ }
+
+ val trackBackdrop = rememberLayerBackdrop()
+
+ Box(
+ modifier,
+ contentAlignment = Alignment.CenterStart
+ ) {
+ Box(
+ Modifier
+ .layerBackdrop(trackBackdrop)
+ .clip(RoundedCornerShape(percent = 50))
+ .drawBehind {
+ val fraction = dampedDragAnimation.value
+ drawRect(lerp(trackColor, accentColor, fraction))
+ }
+ .size(64f.dp, 28f.dp)
+ )
+
+ Box(
+ Modifier
+ .graphicsLayer {
+ val fraction = dampedDragAnimation.value
+ val padding = 2f.dp.toPx()
+ translationX =
+ if (isLtr) lerp(padding, padding + dragWidth, fraction)
+ else lerp(-padding, -(padding + dragWidth), fraction)
+ }
+ .semantics {
+ role = Role.Switch
+ }
+ .then(dampedDragAnimation.modifier)
+ .drawBackdrop(
+ backdrop = rememberCombinedBackdrop(
+ backdrop,
+ rememberBackdrop(trackBackdrop) { drawBackdrop ->
+ val progress = dampedDragAnimation.pressProgress
+ val scaleX = lerp(2f / 3f, 0.75f, progress)
+ val scaleY = lerp(0f, 0.75f, progress)
+ scale(scaleX, scaleY) {
+ drawBackdrop()
+ }
+ }
+ ),
+ shape = { RoundedCornerShape(percent = 50) },
+ effects = {
+ val progress = dampedDragAnimation.pressProgress
+ blur(8f.dp.toPx() * (1f - progress))
+ lens(
+ 5f.dp.toPx() * progress,
+ 10f.dp.toPx() * progress,
+ chromaticAberration = true
+ )
+ },
+ highlight = {
+ val progress = dampedDragAnimation.pressProgress
+ Highlight.Ambient.copy(
+ width = Highlight.Ambient.width / 1.5f,
+ blurRadius = Highlight.Ambient.blurRadius / 1.5f,
+ alpha = progress
+ )
+ },
+ shadow = {
+ Shadow(
+ radius = 4f.dp,
+ color = Color.Black.copy(alpha = 0.05f)
+ )
+ },
+ innerShadow = {
+ val progress = dampedDragAnimation.pressProgress
+ InnerShadow(
+ radius = 4f.dp * progress,
+ alpha = progress
+ )
+ },
+ layerBlock = {
+ scaleX = dampedDragAnimation.scaleX
+ scaleY = dampedDragAnimation.scaleY
+ val velocity = dampedDragAnimation.velocity / 50f
+ scaleX /= 1f - (velocity * 0.75f).fastCoerceIn(-0.2f, 0.2f)
+ scaleY *= 1f - (velocity * 0.25f).fastCoerceIn(-0.2f, 0.2f)
+ },
+ onDrawSurface = {
+ val progress = dampedDragAnimation.pressProgress
+ drawRect(Color.White.copy(alpha = 1f - progress))
+ }
+ )
+ .size(40f.dp, 24f.dp)
+ )
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/DampedDragAnimation.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/DampedDragAnimation.kt
new file mode 100644
index 0000000..a4fe1cc
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/DampedDragAnimation.kt
@@ -0,0 +1,156 @@
+/*
+ * Vendored from Kyant0/AndroidLiquidGlass (kmp branch)
+ * https://github.com/Kyant0/AndroidLiquidGlass — Copyright 2025 Kyant0, Apache License 2.0
+ * app/src/commonMain/kotlin/com/kyant/backdrop/catalog/utils/DampedDragAnimation.kt
+ *
+ * Not published as a library — ported straight from the catalog demo app that
+ * showcases Kyant0/backdrop, source-only. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.catalog.utils
+
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.spring
+import androidx.compose.foundation.MutatorMutex
+import androidx.compose.runtime.snapshotFlow
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.input.pointer.util.VelocityTracker
+import androidx.compose.ui.unit.IntSize
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.launch
+import kotlin.math.abs
+
+class DampedDragAnimation(
+ private val animationScope: CoroutineScope,
+ val initialValue: Float,
+ val valueRange: ClosedRange<Float>,
+ val visibilityThreshold: Float,
+ val initialScale: Float,
+ val pressedScale: Float,
+ val onDragStarted: DampedDragAnimation.(position: Offset) -> Unit,
+ val onDragStopped: DampedDragAnimation.() -> Unit,
+ val onDrag: DampedDragAnimation.(size: IntSize, dragAmount: Offset) -> Unit,
+ /**
+ * Damping of the tracked drag velocity, which callers turn into stretch.
+ *
+ * The library's 0.5f is underdamped, so the velocity rings after every change
+ * of speed and anything driven by it wobbles rather than following the finger.
+ * Pass 1f for a stretch that tracks the drag and stops when it stops.
+ */
+ val velocityDampingRatio: Float = 0.5f,
+) {
+
+ private val valueAnimationSpec =
+ spring(1f, 1000f, visibilityThreshold)
+ private val velocityAnimationSpec =
+ spring(velocityDampingRatio, 300f, visibilityThreshold * 10f)
+ private val pressProgressAnimationSpec =
+ spring(1f, 1000f, 0.001f)
+ private val scaleXAnimationSpec =
+ spring(0.6f, 250f, 0.001f)
+ private val scaleYAnimationSpec =
+ spring(0.7f, 250f, 0.001f)
+
+ private val valueAnimation =
+ Animatable(initialValue, visibilityThreshold)
+ private val velocityAnimation =
+ Animatable(0f, 5f)
+ private val pressProgressAnimation =
+ Animatable(0f, 0.001f)
+ private val scaleXAnimation =
+ Animatable(initialScale, 0.001f)
+ private val scaleYAnimation =
+ Animatable(initialScale, 0.001f)
+
+ private val mutatorMutex = MutatorMutex()
+
+ private val velocityTracker = VelocityTracker()
+
+ val value: Float get() = valueAnimation.value
+ val progress: Float get() = (value - valueRange.start) / (valueRange.endInclusive - valueRange.start)
+ val targetValue: Float get() = valueAnimation.targetValue
+ val pressProgress: Float get() = pressProgressAnimation.value
+ val scaleX: Float get() = scaleXAnimation.value
+ val scaleY: Float get() = scaleYAnimation.value
+ val velocity: Float get() = velocityAnimation.value
+
+ val modifier: Modifier = Modifier.pointerInput(Unit) {
+ inspectDragGestures(
+ onDragStart = { down ->
+ onDragStarted(down.position)
+ press()
+ },
+ onDragEnd = {
+ onDragStopped()
+ release()
+ },
+ onDragCancel = {
+ onDragStopped()
+ release()
+ }
+ ) { change, dragAmount ->
+ onDrag(size, dragAmount)
+ }
+ }
+
+ fun press() {
+ velocityTracker.resetTracking()
+ animationScope.launch {
+ launch { pressProgressAnimation.animateTo(1f, pressProgressAnimationSpec) }
+ launch { scaleXAnimation.animateTo(pressedScale, scaleXAnimationSpec) }
+ launch { scaleYAnimation.animateTo(pressedScale, scaleYAnimationSpec) }
+ }
+ }
+
+ fun release() {
+ animationScope.launch {
+ awaitFrame()
+ if (value != targetValue) {
+ val threshold = (valueRange.endInclusive - valueRange.start) * 0.025f
+ snapshotFlow { valueAnimation.value }
+ .filter { abs(it - valueAnimation.targetValue) < threshold }
+ .first()
+ }
+ launch { pressProgressAnimation.animateTo(0f, pressProgressAnimationSpec) }
+ launch { scaleXAnimation.animateTo(initialScale, scaleXAnimationSpec) }
+ launch { scaleYAnimation.animateTo(initialScale, scaleYAnimationSpec) }
+ }
+ }
+
+ fun updateValue(value: Float) {
+ val targetValue = value.coerceIn(valueRange)
+ animationScope.launch {
+ launch { valueAnimation.animateTo(targetValue, valueAnimationSpec) { updateVelocity() } }
+ }
+ }
+
+ fun animateToValue(value: Float) {
+ animationScope.launch {
+ mutatorMutex.mutate {
+ press()
+ val targetValue = value.coerceIn(valueRange)
+ launch { valueAnimation.animateTo(targetValue, valueAnimationSpec) }
+ if (velocity != 0f) {
+ launch { velocityAnimation.animateTo(0f, velocityAnimationSpec) }
+ }
+ release()
+ }
+ }
+ }
+
+ private fun updateVelocity() {
+ velocityTracker.addPosition(
+ System.nanoTime() / 1_000_000L,
+ Offset(value, 0f)
+ )
+ val targetVelocity = velocityTracker.calculateVelocity().x / (valueRange.endInclusive - valueRange.start)
+ animationScope.launch { velocityAnimation.animateTo(targetVelocity, velocityAnimationSpec) }
+ }
+}
+
+private suspend fun awaitFrame() {
+ androidx.compose.runtime.withFrameNanos { }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/DragGestureInspector.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/DragGestureInspector.kt
new file mode 100644
index 0000000..7a0ce22
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/DragGestureInspector.kt
@@ -0,0 +1,93 @@
+/*
+ * Vendored from Kyant0/AndroidLiquidGlass (kmp branch)
+ * https://github.com/Kyant0/AndroidLiquidGlass — Copyright 2025 Kyant0, Apache License 2.0
+ * app/src/commonMain/kotlin/com/kyant/backdrop/catalog/utils/DragGestureInspector.kt
+ *
+ * Not published as a library — ported straight from the catalog demo app that
+ * showcases Kyant0/backdrop, source-only. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.catalog.utils
+
+import androidx.compose.foundation.gestures.awaitEachGesture
+import androidx.compose.foundation.gestures.awaitFirstDown
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.input.pointer.AwaitPointerEventScope
+import androidx.compose.ui.input.pointer.PointerEventPass
+import androidx.compose.ui.input.pointer.PointerId
+import androidx.compose.ui.input.pointer.PointerInputChange
+import androidx.compose.ui.input.pointer.PointerInputScope
+import androidx.compose.ui.input.pointer.changedToUpIgnoreConsumed
+import androidx.compose.ui.input.pointer.positionChange
+import androidx.compose.ui.util.fastFirstOrNull
+
+suspend fun PointerInputScope.inspectDragGestures(
+ onDragStart: (down: PointerInputChange) -> Unit = {},
+ onDragEnd: (change: PointerInputChange) -> Unit = {},
+ onDragCancel: () -> Unit = {},
+ onDrag: (change: PointerInputChange, dragAmount: Offset) -> Unit
+) {
+ awaitEachGesture {
+ val initialDown = awaitFirstDown(false, PointerEventPass.Initial)
+
+ val down = awaitFirstDown(false)
+ val drag = initialDown
+
+ onDragStart(down)
+ onDrag(drag, Offset.Zero)
+ val upEvent =
+ drag(
+ pointerId = drag.id,
+ onDrag = { onDrag(it, it.positionChange()) }
+ )
+ if (upEvent == null) {
+ onDragCancel()
+ } else {
+ onDragEnd(upEvent)
+ }
+ }
+}
+
+private suspend inline fun AwaitPointerEventScope.drag(
+ pointerId: PointerId,
+ onDrag: (PointerInputChange) -> Unit
+): PointerInputChange? {
+ val isPointerUp = currentEvent.changes.fastFirstOrNull { it.id == pointerId }?.pressed != true
+ if (isPointerUp) {
+ return null
+ }
+ var pointer = pointerId
+ while (true) {
+ val change = awaitDragOrUp(pointer) ?: return null
+ if (change.isConsumed) {
+ return null
+ }
+ if (change.changedToUpIgnoreConsumed()) {
+ return change
+ }
+ onDrag(change)
+ pointer = change.id
+ }
+}
+
+private suspend inline fun AwaitPointerEventScope.awaitDragOrUp(
+ pointerId: PointerId
+): PointerInputChange? {
+ var pointer = pointerId
+ while (true) {
+ val event = awaitPointerEvent()
+ val dragEvent = event.changes.fastFirstOrNull { it.id == pointer } ?: return null
+ if (dragEvent.changedToUpIgnoreConsumed()) {
+ val otherDown = event.changes.fastFirstOrNull { it.pressed }
+ if (otherDown == null) {
+ return dragEvent
+ } else {
+ pointer = otherDown.id
+ }
+ } else {
+ val hasDragged = dragEvent.previousPosition != dragEvent.position
+ if (hasDragged) {
+ return dragEvent
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/InteractiveHighlight.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/InteractiveHighlight.kt
new file mode 100644
index 0000000..25274d5
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/catalog/utils/InteractiveHighlight.kt
@@ -0,0 +1,136 @@
+/*
+ * Vendored from Kyant0/AndroidLiquidGlass (kmp branch)
+ * https://github.com/Kyant0/AndroidLiquidGlass — Copyright 2025 Kyant0, Apache License 2.0
+ * app/src/commonMain/kotlin/com/kyant/backdrop/catalog/utils/InteractiveHighlight.kt
+ *
+ * Not published as a library — ported straight from the catalog demo app that
+ * showcases Kyant0/backdrop, source-only. Package renamed and RuntimeShader
+ * imports repointed at this app's vendored dev.lelonio.square.ui.glass.backdrop.
+ */
+package dev.lelonio.square.ui.glass.backdrop.catalog.utils
+
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.VectorConverter
+import androidx.compose.animation.core.VisibilityThreshold
+import androidx.compose.animation.core.spring
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.drawWithContent
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ShaderBrush
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.util.fastCoerceIn
+import dev.lelonio.square.ui.glass.backdrop.RuntimeShader
+import dev.lelonio.square.ui.glass.backdrop.asComposeShader
+import dev.lelonio.square.ui.glass.backdrop.isRuntimeShaderSupported
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.launch
+
+class InteractiveHighlight(
+ val animationScope: CoroutineScope,
+ val position: (size: Size, offset: Offset) -> Offset = { _, offset -> offset },
+ // Glow radius = size.minDimension * radiusScale. Fine on the small components
+ // this was designed for (mini player pill, nav bar row) where minDimension is
+ // naturally small; on a tall, narrow container (the side panel) minDimension
+ // is still the panel's full width, so the default blows the glow up to
+ // several rows across and visually buries whatever's under the finger.
+ val radiusScale: Float = 1.5f,
+) {
+
+ private val pressProgressAnimationSpec =
+ spring(0.5f, 300f, 0.001f)
+ private val positionAnimationSpec =
+ spring(0.5f, 300f, Offset.VisibilityThreshold)
+
+ private val pressProgressAnimation =
+ Animatable(0f, 0.001f)
+ private val positionAnimation =
+ Animatable(Offset.Zero, Offset.VectorConverter, Offset.VisibilityThreshold)
+
+ private var startPosition = Offset.Zero
+ val pressProgress: Float get() = pressProgressAnimation.value
+ val offset: Offset get() = positionAnimation.value - startPosition
+
+ private val shader =
+ if (isRuntimeShaderSupported()) {
+ RuntimeShader(
+ """
+uniform float2 size;
+layout(color) uniform half4 color;
+uniform float radius;
+uniform float2 position;
+
+half4 main(float2 coord) {
+ float dist = distance(coord, position);
+ float intensity = smoothstep(radius, radius * 0.5, dist);
+ return color * intensity;
+}"""
+ )
+ } else {
+ null
+ }
+
+ val modifier: Modifier =
+ Modifier.drawWithContent {
+ val progress = pressProgressAnimation.value
+ if (progress > 0f) {
+ if (shader != null) {
+ drawRect(
+ Color.White.copy(0.08f * progress),
+ blendMode = BlendMode.Plus
+ )
+ shader.apply {
+ val position = position(size, positionAnimation.value)
+ setFloatUniform("size", size.width, size.height)
+ setColorUniform("color", Color.White.copy(0.15f * progress))
+ setFloatUniform("radius", size.minDimension * radiusScale)
+ setFloatUniform(
+ "position",
+ position.x.fastCoerceIn(0f, size.width),
+ position.y.fastCoerceIn(0f, size.height)
+ )
+ }
+ drawRect(
+ ShaderBrush(shader.asComposeShader()),
+ blendMode = BlendMode.Plus
+ )
+ } else {
+ drawRect(
+ Color.White.copy(0.25f * progress),
+ blendMode = BlendMode.Plus
+ )
+ }
+ }
+
+ drawContent()
+ }
+
+ val gestureModifier: Modifier =
+ Modifier.pointerInput(animationScope) {
+ inspectDragGestures(
+ onDragStart = { down ->
+ startPosition = down.position
+ animationScope.launch {
+ launch { pressProgressAnimation.animateTo(1f, pressProgressAnimationSpec) }
+ launch { positionAnimation.snapTo(startPosition) }
+ }
+ },
+ onDragEnd = {
+ animationScope.launch {
+ launch { pressProgressAnimation.animateTo(0f, pressProgressAnimationSpec) }
+ launch { positionAnimation.animateTo(startPosition, positionAnimationSpec) }
+ }
+ },
+ onDragCancel = {
+ animationScope.launch {
+ launch { pressProgressAnimation.animateTo(0f, pressProgressAnimationSpec) }
+ launch { positionAnimation.animateTo(startPosition, positionAnimationSpec) }
+ }
+ }
+ ) { change, _ ->
+ animationScope.launch { positionAnimation.snapTo(change.position) }
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/Blur.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/Blur.kt
new file mode 100644
index 0000000..2cf6be4
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/Blur.kt
@@ -0,0 +1,38 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.effects
+
+import androidx.annotation.FloatRange
+import androidx.compose.ui.graphics.BlurEffect
+import androidx.compose.ui.graphics.TileMode
+import dev.lelonio.square.ui.glass.backdrop.BackdropEffectScope
+import dev.lelonio.square.ui.glass.backdrop.isRenderEffectSupported
+
+fun BackdropEffectScope.blur(
+ @FloatRange(from = 0.0) radius: Float,
+ edgeTreatment: TileMode = TileMode.Clamp
+) {
+ if (!isRenderEffectSupported()) return
+ if (radius <= 0f) return
+
+ if (edgeTreatment != TileMode.Clamp || renderEffect != null) {
+ if (radius > padding) {
+ padding = radius
+ }
+ }
+
+ renderEffect =
+ BlurEffect(
+ renderEffect,
+ radius,
+ radius,
+ edgeTreatment
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/ColorFilter.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/ColorFilter.kt
new file mode 100644
index 0000000..09a55c7
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/ColorFilter.kt
@@ -0,0 +1,84 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.effects
+
+import androidx.annotation.FloatRange
+import androidx.compose.ui.graphics.ColorFilter
+import androidx.compose.ui.graphics.ColorMatrix
+import androidx.compose.ui.graphics.ColorMatrixColorFilter
+import dev.lelonio.square.ui.glass.backdrop.BackdropEffectScope
+import dev.lelonio.square.ui.glass.backdrop.internal.ColorFilterEffect
+import dev.lelonio.square.ui.glass.backdrop.isRenderEffectSupported
+
+fun BackdropEffectScope.colorFilter(colorFilter: ColorFilter) {
+ if (!isRenderEffectSupported()) return
+
+ renderEffect = ColorFilterEffect(renderEffect, colorFilter)
+}
+
+fun BackdropEffectScope.opacity(@FloatRange(from = 0.0, to = 1.0) alpha: Float) {
+ val colorMatrix = ColorMatrix(
+ floatArrayOf(
+ 1f, 0f, 0f, 0f, 0f,
+ 0f, 1f, 0f, 0f, 0f,
+ 0f, 0f, 1f, 0f, 0f,
+ 0f, 0f, 0f, alpha, 0f
+ )
+ )
+ colorFilter(ColorMatrixColorFilter(colorMatrix))
+}
+
+fun BackdropEffectScope.colorControls(
+ brightness: Float = 0f,
+ contrast: Float = 1f,
+ saturation: Float = 1f
+) {
+ if (brightness == 0f && contrast == 1f && saturation == 1f) {
+ return
+ }
+
+ colorFilter(colorControlsColorFilter(brightness, contrast, saturation))
+}
+
+private val VibrantColorFilter = colorControlsColorFilter(saturation = 1.5f)
+
+fun BackdropEffectScope.vibrancy() {
+ colorFilter(VibrantColorFilter)
+}
+
+private fun colorControlsColorFilter(
+ brightness: Float = 0f,
+ contrast: Float = 1f,
+ saturation: Float = 1f
+): ColorFilter {
+ val invSat = 1f - saturation
+ val r = 0.213f * invSat
+ val g = 0.715f * invSat
+ val b = 0.072f * invSat
+
+ val c = contrast
+ val t = (0.5f - c * 0.5f + brightness) * 255f
+ val s = saturation
+
+ val cr = c * r
+ val cg = c * g
+ val cb = c * b
+ val cs = c * s
+
+ val colorMatrix = ColorMatrix(
+ floatArrayOf(
+ cr + cs, cg, cb, 0f, t,
+ cr, cg + cs, cb, 0f, t,
+ cr, cg, cb + cs, 0f, t,
+ 0f, 0f, 0f, 1f, 0f
+ )
+ )
+ return ColorMatrixColorFilter(colorMatrix)
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/Lens.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/Lens.kt
new file mode 100644
index 0000000..db805bf
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/Lens.kt
@@ -0,0 +1,121 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.effects
+
+import androidx.annotation.FloatRange
+import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape
+import androidx.compose.foundation.shape.CornerBasedShape
+import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.util.fastCoerceAtLeast
+import androidx.compose.ui.util.fastCoerceAtMost
+import dev.lelonio.square.ui.glass.backdrop.BackdropEffectScope
+import dev.lelonio.square.ui.glass.backdrop.internal.RoundedRectRefractionShaderString
+import dev.lelonio.square.ui.glass.backdrop.internal.RoundedRectRefractionWithDispersionShaderString
+import dev.lelonio.square.ui.glass.backdrop.internal.RuntimeShaderEffect
+import dev.lelonio.square.ui.glass.backdrop.isRuntimeShaderSupported
+
+fun BackdropEffectScope.lens(
+ @FloatRange(from = 0.0) refractionHeight: Float,
+ @FloatRange(from = 0.0) refractionAmount: Float,
+ depthEffect: Boolean = false,
+ chromaticAberration: Boolean = false
+) {
+ if (!isRuntimeShaderSupported()) return
+ if (refractionHeight <= 0f || refractionAmount <= 0f) return
+
+ if (padding > 0f) {
+ padding = (padding - refractionHeight).fastCoerceAtLeast(0f)
+ }
+
+ val cornerRadii = cornerRadii
+ val effect =
+ if (cornerRadii != null) {
+ val shader =
+ if (!chromaticAberration) {
+ obtainRuntimeShader(
+ "Refraction",
+ RoundedRectRefractionShaderString
+ )
+ } else {
+ obtainRuntimeShader(
+ "RefractionWithDispersion",
+ RoundedRectRefractionWithDispersionShaderString
+ )
+ }
+ shader.apply {
+ setFloatUniform("size", size.width, size.height)
+ setFloatUniform("offset", -padding, -padding)
+ setFloatUniform("cornerRadii", cornerRadii)
+ setFloatUniform("refractionHeight", refractionHeight)
+ setFloatUniform("refractionAmount", -refractionAmount)
+ setFloatUniform("depthEffect", if (depthEffect) 1f else 0f)
+ if (chromaticAberration) {
+ setFloatUniform("chromaticAberration", 1f)
+ }
+ }
+ RuntimeShaderEffect(shader, "content")
+ } else {
+ throwUnsupportedSDFException()
+ }
+ effect(effect)
+}
+
+// Vendored change: support for io.github.kyant0:shapes' RoundedRectangularShape was
+// dropped so the vendored sources have no external dependency; this app only passes
+// CornerBasedShape here.
+private val BackdropEffectScope.cornerRadii: FloatArray?
+ get() = when (val shape = shape) {
+ is AbsoluteRoundedCornerShape -> {
+ val size = size
+ val maxRadius = size.minDimension / 2f
+ val topLeft = shape.topStart.toPx(size, this)
+ val topRight = shape.topEnd.toPx(size, this)
+ val bottomRight = shape.bottomEnd.toPx(size, this)
+ val bottomLeft = shape.bottomStart.toPx(size, this)
+ floatArrayOf(
+ topLeft.fastCoerceAtMost(maxRadius),
+ topRight.fastCoerceAtMost(maxRadius),
+ bottomRight.fastCoerceAtMost(maxRadius),
+ bottomLeft.fastCoerceAtMost(maxRadius)
+ )
+ }
+
+ is CornerBasedShape -> {
+ val size = size
+ val maxRadius = size.minDimension / 2f
+ val isLtr = layoutDirection == LayoutDirection.Ltr
+ val topLeft =
+ if (isLtr) shape.topStart.toPx(size, this)
+ else shape.topEnd.toPx(size, this)
+ val topRight =
+ if (isLtr) shape.topEnd.toPx(size, this)
+ else shape.topStart.toPx(size, this)
+ val bottomRight =
+ if (isLtr) shape.bottomEnd.toPx(size, this)
+ else shape.bottomStart.toPx(size, this)
+ val bottomLeft =
+ if (isLtr) shape.bottomStart.toPx(size, this)
+ else shape.bottomEnd.toPx(size, this)
+ floatArrayOf(
+ topLeft.fastCoerceAtMost(maxRadius),
+ topRight.fastCoerceAtMost(maxRadius),
+ bottomRight.fastCoerceAtMost(maxRadius),
+ bottomLeft.fastCoerceAtMost(maxRadius)
+ )
+ }
+
+ else -> null
+ }
+
+private fun throwUnsupportedSDFException(): Nothing {
+ throw UnsupportedOperationException(
+ "Only RoundedRectangularShape or CornerBasedShape is supported in lens effects."
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/RenderEffect.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/RenderEffect.kt
new file mode 100644
index 0000000..a61bff3
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/effects/RenderEffect.kt
@@ -0,0 +1,43 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.effects
+
+import androidx.compose.ui.graphics.RenderEffect
+import dev.lelonio.square.ui.glass.backdrop.BackdropEffectScope
+import dev.lelonio.square.ui.glass.backdrop.RuntimeShader
+import dev.lelonio.square.ui.glass.backdrop.internal.RuntimeShaderEffect
+import dev.lelonio.square.ui.glass.backdrop.internal.chain
+import dev.lelonio.square.ui.glass.backdrop.isRenderEffectSupported
+import dev.lelonio.square.ui.glass.backdrop.isRuntimeShaderSupported
+import org.intellij.lang.annotations.Language
+import kotlin.contracts.ExperimentalContracts
+
+fun BackdropEffectScope.effect(effect: RenderEffect) {
+ if (!isRenderEffectSupported()) return
+
+ renderEffect = renderEffect.chain(effect)
+}
+
+@OptIn(ExperimentalContracts::class)
+fun BackdropEffectScope.runtimeShaderEffect(
+ key: String,
+ @Language("AGSL") shaderString: String,
+ uniformShaderName: String,
+ block: RuntimeShader.() -> Unit
+) {
+ if (!isRuntimeShaderSupported()) return
+
+ val effect =
+ RuntimeShaderEffect(
+ runtimeShader = obtainRuntimeShader(key, shaderString).apply(block),
+ uniformShaderName = uniformShaderName
+ )
+ renderEffect = renderEffect.chain(effect)
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/Highlight.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/Highlight.kt
new file mode 100644
index 0000000..c1ca53f
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/Highlight.kt
@@ -0,0 +1,37 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.highlight
+
+import androidx.annotation.FloatRange
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+
+@Immutable
+data class Highlight(
+ val width: Dp = 0.5f.dp,
+ val blurRadius: Dp = width / 2f,
+ @param:FloatRange(from = 0.0, to = 1.0) val alpha: Float = 1f,
+ val style: HighlightStyle = HighlightStyle.Default
+) {
+
+ companion object {
+
+ @Stable
+ val Default: Highlight = Highlight()
+
+ @Stable
+ val Ambient: Highlight = Highlight(style = HighlightStyle.Ambient)
+
+ @Stable
+ val Plain: Highlight = Highlight(style = HighlightStyle.Plain)
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/HighlightModifier.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/HighlightModifier.kt
new file mode 100644
index 0000000..e1c4e94
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/HighlightModifier.kt
@@ -0,0 +1,175 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.highlight
+
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Outline
+import androidx.compose.ui.graphics.Paint
+import androidx.compose.ui.graphics.PaintingStyle
+import androidx.compose.ui.graphics.Path
+import androidx.compose.ui.graphics.drawOutline
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.drawscope.translate
+import androidx.compose.ui.graphics.layer.GraphicsLayer
+import androidx.compose.ui.graphics.layer.drawLayer
+import androidx.compose.ui.node.DrawModifierNode
+import androidx.compose.ui.node.ModifierNodeElement
+import androidx.compose.ui.node.invalidateDraw
+import androidx.compose.ui.node.requireGraphicsContext
+import androidx.compose.ui.platform.InspectorInfo
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.util.fastCoerceAtMost
+import dev.lelonio.square.ui.glass.backdrop.RuntimeShaderCacheImpl
+import dev.lelonio.square.ui.glass.backdrop.internal.ShapeProvider
+import dev.lelonio.square.ui.glass.backdrop.internal.blur
+import dev.lelonio.square.ui.glass.backdrop.internal.clipOutline
+import dev.lelonio.square.ui.glass.backdrop.internal.setRuntimeShader
+import dev.lelonio.square.ui.glass.backdrop.isRuntimeShaderSupported
+import kotlin.math.ceil
+
+internal class HighlightElement(
+ val shapeProvider: ShapeProvider,
+ val highlight: () -> Highlight?
+) : ModifierNodeElement<HighlightNode>() {
+
+ override fun create(): HighlightNode {
+ return HighlightNode(shapeProvider, highlight)
+ }
+
+ override fun update(node: HighlightNode) {
+ node.shapeProvider = shapeProvider
+ node.highlight = highlight
+ node.invalidateDraw()
+ }
+
+ override fun InspectorInfo.inspectableProperties() {
+ name = "highlight"
+ properties["shapeProvider"] = shapeProvider
+ properties["highlight"] = highlight
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is HighlightElement) return false
+
+ if (shapeProvider != other.shapeProvider) return false
+ if (highlight != other.highlight) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ var result = shapeProvider.hashCode()
+ result = 31 * result + highlight.hashCode()
+ return result
+ }
+}
+
+internal class HighlightNode(
+ var shapeProvider: ShapeProvider,
+ var highlight: () -> Highlight?
+) : DrawModifierNode, Modifier.Node() {
+
+ override val shouldAutoInvalidate: Boolean = false
+
+ private var highlightLayer: GraphicsLayer? = null
+
+ private val paint =
+ Paint().apply {
+ style = PaintingStyle.Stroke
+ }
+ private var clipPath: Path? = null
+
+ private val runtimeShaderCache = RuntimeShaderCacheImpl()
+
+ private var prevStyle: HighlightStyle? = null
+
+ override fun ContentDrawScope.draw() {
+ val highlight = highlight()
+ if (highlight == null || highlight.width.value <= 0f) {
+ return drawContent()
+ }
+
+ drawContent()
+
+ val highlightLayer = highlightLayer
+ if (highlightLayer != null) {
+ val size = size
+ val density: Density = this
+ val layoutDirection = layoutDirection
+
+ val safeSize =
+ IntSize(
+ ceil(size.width).toInt() + 2,
+ ceil(size.height).toInt() + 2
+ )
+
+ val outline = shapeProvider.shape.createOutline(size, layoutDirection, density)
+ val clipPath =
+ if (outline is Outline.Rounded) {
+ clipPath ?: Path().also { clipPath = it }
+ } else {
+ null
+ }
+
+ configurePaint(highlight)
+
+ highlightLayer.alpha = highlight.alpha
+ highlightLayer.blendMode = highlight.style.blendMode
+ highlightLayer.record(safeSize) {
+ translate(1f, 1f) {
+ val canvas = drawContext.canvas
+ canvas.save()
+ canvas.clipOutline(outline, clipPath)
+ canvas.drawOutline(outline, paint)
+ canvas.restore()
+ }
+ }
+
+ translate(-1f, -1f) {
+ drawLayer(highlightLayer)
+ }
+ }
+ }
+
+ override fun onAttach() {
+ val graphicsContext = requireGraphicsContext()
+ highlightLayer = graphicsContext.createGraphicsLayer()
+ }
+
+ override fun onDetach() {
+ val graphicsContext = requireGraphicsContext()
+ highlightLayer?.let { layer ->
+ graphicsContext.releaseGraphicsLayer(layer)
+ highlightLayer = null
+ }
+ clipPath = null
+ runtimeShaderCache.clear()
+ prevStyle = null
+ }
+
+ private fun DrawScope.configurePaint(highlight: Highlight) {
+ paint.color = highlight.style.color
+ paint.strokeWidth = ceil(highlight.width.toPx().fastCoerceAtMost(size.minDimension / 2f)) * 2f
+ paint.blur(highlight.blurRadius.toPx())
+ if (isRuntimeShaderSupported()) {
+ val shader =
+ with(highlight.style) {
+ createShader(
+ shape = shapeProvider.shape,
+ runtimeShaderCache = runtimeShaderCache
+ )
+ }
+ paint.setRuntimeShader(shader)
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/HighlightStyle.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/HighlightStyle.kt
new file mode 100644
index 0000000..c619195
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/highlight/HighlightStyle.kt
@@ -0,0 +1,147 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.highlight
+
+import androidx.annotation.FloatRange
+import androidx.compose.foundation.shape.CornerBasedShape
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.util.fastCoerceAtMost
+import dev.lelonio.square.ui.glass.backdrop.RuntimeShader
+import dev.lelonio.square.ui.glass.backdrop.RuntimeShaderCache
+import dev.lelonio.square.ui.glass.backdrop.internal.AmbientHighlightShaderString
+import dev.lelonio.square.ui.glass.backdrop.internal.DefaultHighlightShaderString
+import dev.lelonio.square.ui.glass.backdrop.isRuntimeShaderSupported
+import kotlin.math.PI
+
+@Immutable
+interface HighlightStyle {
+
+ val color: Color
+
+ val blendMode: BlendMode
+
+ fun DrawScope.createShader(
+ shape: Shape,
+ runtimeShaderCache: RuntimeShaderCache
+ ): RuntimeShader?
+
+ @Immutable
+ data class Plain(
+ override val color: Color = Color.White.copy(alpha = 0.38f),
+ override val blendMode: BlendMode = BlendMode.Plus
+ ) : HighlightStyle {
+
+ override fun DrawScope.createShader(
+ shape: Shape,
+ runtimeShaderCache: RuntimeShaderCache
+ ): RuntimeShader? = null
+ }
+
+ @Immutable
+ data class Default(
+ override val color: Color = Color.White.copy(alpha = 0.5f),
+ override val blendMode: BlendMode = BlendMode.Plus,
+ val angle: Float = 45f,
+ @param:FloatRange(from = 0.0) val falloff: Float = 1f
+ ) : HighlightStyle {
+
+ override fun DrawScope.createShader(
+ shape: Shape,
+ runtimeShaderCache: RuntimeShaderCache
+ ): RuntimeShader? {
+ return if (isRuntimeShaderSupported()) {
+ runtimeShaderCache.obtainRuntimeShader(
+ "Default",
+ DefaultHighlightShaderString
+ ).apply {
+ setFloatUniform("size", size.width, size.height)
+ setFloatUniform("cornerRadii", getCornerRadii(shape))
+ setColorUniform("color", color.copy(alpha = 1f))
+ setFloatUniform("angle", angle * (PI / 180f).toFloat())
+ setFloatUniform("falloff", falloff)
+ }
+ } else {
+ null
+ }
+ }
+ }
+
+ @Immutable
+ data class Ambient(
+ @param:FloatRange(from = 0.0, to = 1.0) val intensity: Float = 0.38f
+ ) : HighlightStyle {
+
+ override val color: Color = Color.White.copy(alpha = intensity)
+
+ override val blendMode: BlendMode = DrawScope.DefaultBlendMode
+
+ override fun DrawScope.createShader(
+ shape: Shape,
+ runtimeShaderCache: RuntimeShaderCache
+ ): RuntimeShader? {
+ return if (isRuntimeShaderSupported()) {
+ runtimeShaderCache.obtainRuntimeShader(
+ "Ambient",
+ AmbientHighlightShaderString
+ ).apply {
+ setFloatUniform("size", size.width, size.height)
+ setFloatUniform("cornerRadii", getCornerRadii(shape))
+ setFloatUniform("angle", 45f * (PI / 180f).toFloat())
+ setFloatUniform("falloff", 1f)
+ }
+ } else {
+ null
+ }
+ }
+ }
+
+ companion object {
+
+ @Stable
+ val Default: Default = Default()
+
+ @Stable
+ val Ambient: Ambient = Ambient()
+
+ @Stable
+ val Plain: Plain = Plain()
+ }
+}
+
+private fun DrawScope.getCornerRadii(shape: Shape): FloatArray {
+ val size = size
+ val maxRadius = size.minDimension / 2f
+ val shape = shape as? CornerBasedShape ?: return FloatArray(4) { maxRadius }
+ val isLtr = layoutDirection == LayoutDirection.Ltr
+ val topLeft =
+ if (isLtr) shape.topStart.toPx(size, this)
+ else shape.topEnd.toPx(size, this)
+ val topRight =
+ if (isLtr) shape.topEnd.toPx(size, this)
+ else shape.topStart.toPx(size, this)
+ val bottomRight =
+ if (isLtr) shape.bottomEnd.toPx(size, this)
+ else shape.bottomStart.toPx(size, this)
+ val bottomLeft =
+ if (isLtr) shape.bottomStart.toPx(size, this)
+ else shape.bottomEnd.toPx(size, this)
+ return floatArrayOf(
+ topLeft.fastCoerceAtMost(maxRadius),
+ topRight.fastCoerceAtMost(maxRadius),
+ bottomRight.fastCoerceAtMost(maxRadius),
+ bottomLeft.fastCoerceAtMost(maxRadius)
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/InverseLayerScope.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/InverseLayerScope.kt
new file mode 100644
index 0000000..7847115
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/InverseLayerScope.kt
@@ -0,0 +1,139 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.internal
+
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ColorFilter
+import androidx.compose.ui.graphics.CompositingStrategy
+import androidx.compose.ui.graphics.DefaultCameraDistance
+import androidx.compose.ui.graphics.DefaultShadowColor
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.Matrix
+import androidx.compose.ui.graphics.RectangleShape
+import androidx.compose.ui.graphics.RenderEffect
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.TransformOrigin
+import androidx.compose.ui.graphics.drawscope.DrawTransform
+import androidx.compose.ui.unit.Density
+import kotlin.math.PI
+import kotlin.math.cos
+import kotlin.math.sin
+
+internal class InverseLayerScope : GraphicsLayerScope {
+
+ override var size: Size = Size.Unspecified
+ override var density: Float = 1f
+ override var fontScale: Float = 1f
+
+ override var scaleX: Float = 1f
+ override var scaleY: Float = 1f
+ override var alpha: Float = 0f
+ override var translationX: Float = 0f
+ override var translationY: Float = 0f
+ override var shadowElevation: Float = 0f
+ override var ambientShadowColor: Color = DefaultShadowColor
+ override var spotShadowColor: Color = DefaultShadowColor
+ override var rotationX: Float = 0f
+ override var rotationY: Float = 0f
+ override var rotationZ: Float = 0f
+ override var cameraDistance: Float = DefaultCameraDistance
+ override var transformOrigin: TransformOrigin = TransformOrigin.Center
+ override var shape: Shape = RectangleShape
+ override var clip: Boolean = false
+ override var renderEffect: RenderEffect? = null
+ override var blendMode: BlendMode = BlendMode.SrcOver
+ override var colorFilter: ColorFilter? = null
+ override var compositingStrategy: CompositingStrategy = CompositingStrategy.Auto
+
+ private var matrix: Matrix? = null
+
+ fun DrawTransform.inverseTransform(
+ density: Density,
+ layerBlock: GraphicsLayerScope.() -> Unit
+ ) {
+ [email protected] = density.density
+ fontScale = density.fontScale
+
+ layerBlock()
+
+ inverseTransformAtTopLeft(
+ rotationZ = rotationZ,
+ scaleX = scaleX,
+ scaleY = scaleY
+ )
+ }
+
+ fun reset() {
+ size = Size.Unspecified
+ density = 1f
+ fontScale = 1f
+
+ scaleX = 1f
+ scaleY = 1f
+ alpha = 1f
+ translationX = 0f
+ translationY = 0f
+ shadowElevation = 0f
+ ambientShadowColor = DefaultShadowColor
+ spotShadowColor = DefaultShadowColor
+ rotationX = 0f
+ rotationY = 0f
+ rotationZ = 0f
+ cameraDistance = DefaultCameraDistance
+ transformOrigin = TransformOrigin.Center
+ shape = RectangleShape
+ clip = false
+ renderEffect = null
+ blendMode = BlendMode.SrcOver
+ colorFilter = null
+ compositingStrategy = CompositingStrategy.Auto
+
+ matrix = null
+ }
+
+ private fun DrawTransform.inverseTransformAtTopLeft(
+ rotationZ: Float = 0f,
+ scaleX: Float = 1f,
+ scaleY: Float = 1f
+ ) {
+ if (rotationZ == 0f) {
+ if (scaleX != 0f && scaleY != 0f) {
+ scale(1f / scaleX, 1f / scaleY, Offset.Zero)
+ }
+ return
+ }
+
+ val matrix = matrix ?: Matrix().also { matrix = it }
+ if (matrix.values.size < 16) return
+
+ val rz = rotationZ * (PI / 180.0)
+ val rsz = sin(rz).toFloat()
+ val rcz = cos(rz).toFloat()
+
+ val a00 = rcz * scaleX
+ val a01 = rsz * scaleY
+ val a10 = -rsz * scaleX
+ val a11 = rcz * scaleY
+
+ val det = a00 * a11 - a01 * a10
+ if (det == 0f) return
+ val invDet = 1f / det
+ matrix[0, 0] = a11 * invDet
+ matrix[0, 1] = -a01 * invDet
+ matrix[1, 0] = -a10 * invDet
+ matrix[1, 1] = a00 * invDet
+
+ transform(matrix)
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/LayerRecorder.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/LayerRecorder.kt
new file mode 100644
index 0000000..6e1b69f
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/LayerRecorder.kt
@@ -0,0 +1,39 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.internal
+
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.layer.GraphicsLayer
+import androidx.compose.ui.node.DelegatableNode
+import androidx.compose.ui.node.requireDensity
+import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.unit.toIntSize
+
+// Vendored change: the upstream declaration used an experimental Kotlin context
+// parameter (`context(node: DelegatableNode)`), which would require enabling
+// -Xcontext-parameters for the whole app module; the node is an explicit
+// parameter instead.
+internal fun DrawScope.recordLayer(
+ node: DelegatableNode,
+ layer: GraphicsLayer,
+ size: IntSize = this.size.toIntSize(),
+ block: DrawScope.() -> Unit
+) {
+ val density = node.requireDensity()
+ layer.record(size) {
+ val prevDensity = drawContext.density
+ drawContext.density = density
+ try {
+ this.block()
+ } finally {
+ drawContext.density = prevDensity
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Outline.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Outline.kt
new file mode 100644
index 0000000..28a85a3
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Outline.kt
@@ -0,0 +1,27 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.internal
+
+import androidx.compose.ui.graphics.Canvas
+import androidx.compose.ui.graphics.Outline
+import androidx.compose.ui.graphics.Path
+
+internal fun Canvas.clipOutline(outline: Outline, path: Path?) {
+ when (outline) {
+ is Outline.Rectangle -> clipRect(outline.rect)
+ is Outline.Rounded -> {
+ path!!.rewind()
+ path.addRoundRect(outline.roundRect)
+ clipPath(path)
+ }
+
+ is Outline.Generic -> clipPath(outline.path)
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Paint.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Paint.kt
new file mode 100644
index 0000000..4facdbd
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Paint.kt
@@ -0,0 +1,25 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.internal
+
+import android.graphics.BlurMaskFilter
+import androidx.compose.ui.graphics.Paint
+import dev.lelonio.square.ui.glass.backdrop.RuntimeShader
+import dev.lelonio.square.ui.glass.backdrop.asAndroidRuntimeShader
+
+internal fun Paint.blur(radius: Float) {
+ this.asFrameworkPaint().maskFilter =
+ if (radius > 0f) BlurMaskFilter(radius, BlurMaskFilter.Blur.NORMAL)
+ else null
+}
+
+internal fun Paint.setRuntimeShader(runtimeShader: RuntimeShader?) {
+ this.asFrameworkPaint().shader = runtimeShader?.asAndroidRuntimeShader()
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/RenderEffect.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/RenderEffect.kt
new file mode 100644
index 0000000..ec4b783
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/RenderEffect.kt
@@ -0,0 +1,59 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.internal
+
+import android.os.Build
+import androidx.annotation.RequiresApi
+import androidx.compose.ui.graphics.ColorFilter
+import androidx.compose.ui.graphics.RenderEffect
+import androidx.compose.ui.graphics.asAndroidColorFilter
+import androidx.compose.ui.graphics.asComposeRenderEffect
+import dev.lelonio.square.ui.glass.backdrop.RuntimeShader
+import dev.lelonio.square.ui.glass.backdrop.asAndroidRuntimeShader
+
+@RequiresApi(Build.VERSION_CODES.S)
+internal fun RenderEffect?.chain(other: RenderEffect): RenderEffect {
+ return if (this != null) {
+ android.graphics.RenderEffect.createChainEffect(
+ other.asAndroidRenderEffect(),
+ this.asAndroidRenderEffect()
+ ).asComposeRenderEffect()
+ } else {
+ other
+ }
+}
+
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
+internal fun RuntimeShaderEffect(
+ runtimeShader: RuntimeShader,
+ uniformShaderName: String
+): RenderEffect {
+ return android.graphics.RenderEffect.createRuntimeShaderEffect(
+ runtimeShader.asAndroidRuntimeShader(),
+ uniformShaderName
+ ).asComposeRenderEffect()
+}
+
+@RequiresApi(Build.VERSION_CODES.S)
+internal fun ColorFilterEffect(
+ renderEffect: RenderEffect?,
+ colorFilter: ColorFilter
+): RenderEffect {
+ return if (renderEffect != null) {
+ android.graphics.RenderEffect.createColorFilterEffect(
+ colorFilter.asAndroidColorFilter(),
+ renderEffect.asAndroidRenderEffect()
+ ).asComposeRenderEffect()
+ } else {
+ android.graphics.RenderEffect.createColorFilterEffect(
+ colorFilter.asAndroidColorFilter(),
+ ).asComposeRenderEffect()
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Shaders.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Shaders.kt
new file mode 100644
index 0000000..7aa18b2
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/Shaders.kt
@@ -0,0 +1,213 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+/*
+ Copyright 2025 Kyant
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+package dev.lelonio.square.ui.glass.backdrop.internal
+
+import org.intellij.lang.annotations.Language
+
+@Language("AGSL")
+private const val RoundedRectSDF = """
+float radiusAt(float2 coord, float4 radii) {
+ if (coord.x >= 0.0) {
+ if (coord.y <= 0.0) return radii.y;
+ else return radii.z;
+ } else {
+ if (coord.y <= 0.0) return radii.x;
+ else return radii.w;
+ }
+}
+
+float sdRoundedRect(float2 coord, float2 halfSize, float radius) {
+ float2 cornerCoord = abs(coord) - (halfSize - float2(radius));
+ float outside = length(max(cornerCoord, 0.0)) - radius;
+ float inside = min(max(cornerCoord.x, cornerCoord.y), 0.0);
+ return outside + inside;
+}
+
+float2 gradSdRoundedRect(float2 coord, float2 halfSize, float radius) {
+ float2 cornerCoord = abs(coord) - (halfSize - float2(radius));
+ if (cornerCoord.x >= 0.0 || cornerCoord.y >= 0.0) {
+ return sign(coord) * normalize(max(cornerCoord, 0.0));
+ } else {
+ float gradX = step(cornerCoord.y, cornerCoord.x);
+ return sign(coord) * float2(gradX, 1.0 - gradX);
+ }
+}"""
+
+@Language("AGSL")
+internal const val RoundedRectRefractionShaderString = """
+uniform shader content;
+
+uniform float2 size;
+uniform float2 offset;
+uniform float4 cornerRadii;
+uniform float refractionHeight;
+uniform float refractionAmount;
+uniform float depthEffect;
+
+$RoundedRectSDF
+
+float circleMap(float x) {
+ return 1.0 - sqrt(1.0 - x * x);
+}
+
+half4 main(float2 coord) {
+ float2 halfSize = size * 0.5;
+ float2 centeredCoord = (coord + offset) - halfSize;
+ float radius = radiusAt(coord, cornerRadii);
+
+ float sd = sdRoundedRect(centeredCoord, halfSize, radius);
+ if (-sd >= refractionHeight) {
+ return content.eval(coord);
+ }
+ sd = min(sd, 0.0);
+
+ float d = circleMap(1.0 - -sd / refractionHeight) * refractionAmount;
+ float gradRadius = min(radius * 1.5, min(halfSize.x, halfSize.y));
+ float2 grad = normalize(gradSdRoundedRect(centeredCoord, halfSize, gradRadius) + depthEffect * normalize(centeredCoord));
+
+ float2 refractedCoord = coord + d * grad;
+ return content.eval(refractedCoord);
+}"""
+
+@Language("AGSL")
+internal val RoundedRectRefractionWithDispersionShaderString = """
+uniform shader content;
+
+uniform float2 size;
+uniform float2 offset;
+uniform float4 cornerRadii;
+uniform float refractionHeight;
+uniform float refractionAmount;
+uniform float depthEffect;
+uniform float chromaticAberration;
+
+$RoundedRectSDF
+
+float circleMap(float x) {
+ return 1.0 - sqrt(1.0 - x * x);
+}
+
+half4 main(float2 coord) {
+ float2 halfSize = size * 0.5;
+ float2 centeredCoord = (coord + offset) - halfSize;
+ float radius = radiusAt(coord, cornerRadii);
+
+ float sd = sdRoundedRect(centeredCoord, halfSize, radius);
+ if (-sd >= refractionHeight) {
+ return content.eval(coord);
+ }
+ sd = min(sd, 0.0);
+
+ float d = circleMap(1.0 - -sd / refractionHeight) * refractionAmount;
+ float gradRadius = min(radius * 1.5, min(halfSize.x, halfSize.y));
+ float2 grad = normalize(gradSdRoundedRect(centeredCoord, halfSize, gradRadius) + depthEffect * normalize(centeredCoord));
+
+ float2 refractedCoord = coord + d * grad;
+ float dispersionIntensity = chromaticAberration * ((centeredCoord.x * centeredCoord.y) / (halfSize.x * halfSize.y));
+ float2 dispersedCoord = d * grad * dispersionIntensity;
+
+ half4 color = half4(0.0);
+
+ half4 red = content.eval(refractedCoord + dispersedCoord);
+ color.r += red.r / 3.5;
+ color.a += red.a / 7.0;
+
+ half4 orange = content.eval(refractedCoord + dispersedCoord * (2.0 / 3.0));
+ color.r += orange.r / 3.5;
+ color.g += orange.g / 7.0;
+ color.a += orange.a / 7.0;
+
+ half4 yellow = content.eval(refractedCoord + dispersedCoord * (1.0 / 3.0));
+ color.r += yellow.r / 3.5;
+ color.g += yellow.g / 3.5;
+ color.a += yellow.a / 7.0;
+
+ half4 green = content.eval(refractedCoord);
+ color.g += green.g / 3.5;
+ color.a += green.a / 7.0;
+
+ half4 cyan = content.eval(refractedCoord - dispersedCoord * (1.0 / 3.0));
+ color.g += cyan.g / 3.5;
+ color.b += cyan.b / 3.0;
+ color.a += cyan.a / 7.0;
+
+ half4 blue = content.eval(refractedCoord - dispersedCoord * (2.0 / 3.0));
+ color.b += blue.b / 3.0;
+ color.a += blue.a / 7.0;
+
+ half4 purple = content.eval(refractedCoord - dispersedCoord);
+ color.r += purple.r / 7.0;
+ color.b += purple.b / 3.0;
+ color.a += purple.a / 7.0;
+
+ return color;
+}"""
+
+@Language("AGSL")
+internal const val DefaultHighlightShaderString = """
+uniform float2 size;
+uniform float4 cornerRadii;
+layout(color) uniform half4 color;
+uniform float angle;
+uniform float falloff;
+
+$RoundedRectSDF
+
+half4 main(float2 coord) {
+ float2 halfSize = size * 0.5;
+ float2 centeredCoord = coord - halfSize;
+ float radius = radiusAt(coord, cornerRadii);
+
+ float gradRadius = min(radius * 1.5, min(halfSize.x, halfSize.y));
+ float2 grad = gradSdRoundedRect(centeredCoord, halfSize, gradRadius);
+ float2 normal = float2(cos(angle), sin(angle));
+ float d = dot(grad, normal);
+ float intensity = pow(abs(d), falloff);
+ return color * intensity;
+}"""
+
+@Language("AGSL")
+internal const val AmbientHighlightShaderString = """
+uniform float2 size;
+uniform float4 cornerRadii;
+uniform float angle;
+uniform float falloff;
+
+$RoundedRectSDF
+
+half4 main(float2 coord) {
+ float2 halfSize = size * 0.5;
+ float2 centeredCoord = coord - halfSize;
+ float radius = radiusAt(coord, cornerRadii);
+
+ float gradRadius = min(radius * 1.5, min(halfSize.x, halfSize.y));
+ float2 grad = gradSdRoundedRect(centeredCoord, halfSize, gradRadius);
+ float2 normal = float2(cos(angle), sin(angle));
+ float d = dot(grad, normal);
+ float intensity = pow(abs(d), falloff);
+ float t = step(0.0, d);
+ return half4(t, t, t, 1.0) * intensity;
+}"""
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/ShapeProvider.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/ShapeProvider.kt
new file mode 100644
index 0000000..86be379
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/internal/ShapeProvider.kt
@@ -0,0 +1,53 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.internal
+
+import androidx.compose.runtime.Immutable
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.Outline
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.LayoutDirection
+
+@Immutable
+internal class ShapeProvider(val shapeBlock: () -> Shape) {
+
+ private var _shape: Shape? = null
+ private var _outline: Outline? = null
+ private var _size: Size = Size.Unspecified
+ private var _layoutDirection: LayoutDirection? = null
+ private var _density: Float? = null
+
+ val innerShape
+ get() = shapeBlock()
+
+ val shape = object : Shape {
+
+ override fun createOutline(
+ size: Size,
+ layoutDirection: LayoutDirection,
+ density: Density
+ ): Outline {
+ val shape = shapeBlock()
+ if (_shape != shape) {
+ _shape = shape
+ _outline = null
+ }
+ if (_outline == null || _size != size || _layoutDirection != layoutDirection || _density != density.density) {
+ _size = size
+ _layoutDirection = layoutDirection
+ _density = density.density
+ _outline = shape.createOutline(size, layoutDirection, density)
+ }
+
+ return _outline!!
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/InnerShadow.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/InnerShadow.kt
new file mode 100644
index 0000000..f935fca
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/InnerShadow.kt
@@ -0,0 +1,50 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.shadow
+
+import androidx.annotation.FloatRange
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.lerp
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.DpOffset
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.lerp
+import androidx.compose.ui.util.lerp
+
+@Immutable
+data class InnerShadow(
+ val radius: Dp = 24f.dp,
+ val offset: DpOffset = DpOffset(0f.dp, radius),
+ val color: Color = Color.Black.copy(alpha = 0.15f),
+ @param:FloatRange(from = 0.0, to = 1.0) val alpha: Float = 1f,
+ val blendMode: BlendMode = DrawScope.DefaultBlendMode
+) {
+
+ companion object {
+
+ @Stable
+ val Default: InnerShadow = InnerShadow()
+ }
+}
+
+@Stable
+fun lerp(start: InnerShadow, stop: InnerShadow, fraction: Float): InnerShadow {
+ return InnerShadow(
+ radius = lerp(start.radius, stop.radius, fraction),
+ offset = lerp(start.offset, stop.offset, fraction),
+ color = lerp(start.color, stop.color, fraction),
+ alpha = lerp(start.alpha, stop.alpha, fraction),
+ blendMode = if (fraction < 0.5f) start.blendMode else stop.blendMode
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/InnerShadowModifier.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/InnerShadowModifier.kt
new file mode 100644
index 0000000..b07a529
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/InnerShadowModifier.kt
@@ -0,0 +1,167 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.shadow
+
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.BlurEffect
+import androidx.compose.ui.graphics.Outline
+import androidx.compose.ui.graphics.Paint
+import androidx.compose.ui.graphics.Path
+import androidx.compose.ui.graphics.TileMode
+import androidx.compose.ui.graphics.drawOutline
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.layer.CompositingStrategy
+import androidx.compose.ui.graphics.layer.GraphicsLayer
+import androidx.compose.ui.graphics.layer.drawLayer
+import androidx.compose.ui.node.DrawModifierNode
+import androidx.compose.ui.node.ModifierNodeElement
+import androidx.compose.ui.node.invalidateDraw
+import androidx.compose.ui.node.requireGraphicsContext
+import androidx.compose.ui.platform.InspectorInfo
+import androidx.compose.ui.unit.Density
+import dev.lelonio.square.ui.glass.backdrop.internal.ShapeProvider
+import dev.lelonio.square.ui.glass.backdrop.internal.clipOutline
+import dev.lelonio.square.ui.glass.backdrop.isRenderEffectSupported
+
+internal class InnerShadowElement(
+ val shapeProvider: ShapeProvider,
+ val shadow: () -> InnerShadow?
+) : ModifierNodeElement<InnerShadowNode>() {
+
+ override fun create(): InnerShadowNode {
+ return InnerShadowNode(shapeProvider, shadow)
+ }
+
+ override fun update(node: InnerShadowNode) {
+ node.shapeProvider = shapeProvider
+ node.shadow = shadow
+ node.invalidateDraw()
+ }
+
+ override fun InspectorInfo.inspectableProperties() {
+ name = "innerShadow"
+ properties["shapeProvider"] = shapeProvider
+ properties["shadow"] = shadow
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is InnerShadowElement) return false
+
+ if (shapeProvider != other.shapeProvider) return false
+ if (shadow != other.shadow) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ var result = shapeProvider.hashCode()
+ result = 31 * result + shadow.hashCode()
+ return result
+ }
+}
+
+internal class InnerShadowNode(
+ var shapeProvider: ShapeProvider,
+ var shadow: () -> InnerShadow?
+) : DrawModifierNode, Modifier.Node() {
+
+ override val shouldAutoInvalidate: Boolean = false
+
+ private var shadowLayer: GraphicsLayer? = null
+
+ private val paint = Paint()
+ private var clipPath: Path? = null
+
+ private var prevRadius = Float.NaN
+
+ override fun ContentDrawScope.draw() {
+ drawContent()
+
+ if (!isRenderEffectSupported()) return
+
+ val shadow = shadow() ?: return
+
+ val shadowLayer = shadowLayer
+ if (shadowLayer != null) {
+ val size = size
+ val density: Density = this
+ val layoutDirection = layoutDirection
+
+ val radius = shadow.radius.toPx()
+ val offsetX = shadow.offset.x.toPx()
+ val offsetY = shadow.offset.y.toPx()
+
+ val outline = shapeProvider.shape.createOutline(size, layoutDirection, density)
+ val clipPath =
+ if (outline is Outline.Rounded) {
+ clipPath ?: Path().also { clipPath = it }
+ } else {
+ null
+ }
+
+ configurePaint(shadow)
+
+ shadowLayer.alpha = shadow.alpha
+ shadowLayer.blendMode = shadow.blendMode
+ if (prevRadius != radius) {
+ shadowLayer.renderEffect =
+ if (radius > 0f) {
+ BlurEffect(radius, radius, TileMode.Decal)
+ } else {
+ null
+ }
+ prevRadius = radius
+ }
+ shadowLayer.record {
+ val canvas = drawContext.canvas
+ canvas.save()
+ canvas.clipOutline(outline, clipPath)
+ canvas.drawOutline(outline, paint)
+ canvas.translate(offsetX, offsetY)
+ canvas.drawOutline(outline, ShadowMaskPaint)
+ canvas.translate(-offsetX, -offsetY)
+ canvas.restore()
+ }
+
+ val canvas = drawContext.canvas
+ canvas.save()
+ canvas.clipOutline(outline, clipPath)
+ drawLayer(shadowLayer)
+ canvas.restore()
+ }
+ }
+
+ override fun onAttach() {
+ val graphicsContext = requireGraphicsContext()
+ shadowLayer =
+ graphicsContext.createGraphicsLayer().apply {
+ compositingStrategy = CompositingStrategy.Offscreen
+ }
+ }
+
+ override fun onDetach() {
+ val graphicsContext = requireGraphicsContext()
+ shadowLayer?.let { layer ->
+ graphicsContext.releaseGraphicsLayer(layer)
+ shadowLayer = null
+ }
+ }
+
+ private fun DrawScope.configurePaint(shadow: InnerShadow) {
+ paint.color = shadow.color
+ }
+}
+
+private val ShadowMaskPaint = Paint().apply {
+ blendMode = BlendMode.Clear
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/Shadow.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/Shadow.kt
new file mode 100644
index 0000000..4ea1f51
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/Shadow.kt
@@ -0,0 +1,36 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.shadow
+
+import androidx.annotation.FloatRange
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.DpOffset
+import androidx.compose.ui.unit.dp
+
+@Immutable
+data class Shadow(
+ val radius: Dp = 24f.dp,
+ val offset: DpOffset = DpOffset(0f.dp, radius / 6f),
+ val color: Color = Color.Black.copy(alpha = 0.1f),
+ @param:FloatRange(from = 0.0, to = 1.0) val alpha: Float = 1f,
+ val blendMode: BlendMode = DrawScope.DefaultBlendMode
+) {
+
+ companion object {
+
+ @Stable
+ val Default: Shadow = Shadow()
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/ShadowModifier.kt b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/ShadowModifier.kt
new file mode 100644
index 0000000..c242159
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/backdrop/shadow/ShadowModifier.kt
@@ -0,0 +1,146 @@
+/*
+ * Vendored from Kyant0/backdrop v2.0.0 (io.github.kyant0:backdrop)
+ * https://github.com/Kyant0/backdrop — Copyright 2025 Kyant0, Apache License 2.0
+ *
+ * Vendored so the library ships as source with this app (binary AARs compiled
+ * against older Compose broke at runtime) and to add a backdrop resolution
+ * scale for cheaper effect rendering. KMP expect/actual declarations were
+ * merged into this single Android source set. Package renamed accordingly.
+ */
+package dev.lelonio.square.ui.glass.backdrop.shadow
+
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.graphics.Paint
+import androidx.compose.ui.graphics.drawOutline
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.drawscope.translate
+import androidx.compose.ui.graphics.layer.CompositingStrategy
+import androidx.compose.ui.graphics.layer.GraphicsLayer
+import androidx.compose.ui.graphics.layer.drawLayer
+import androidx.compose.ui.node.DrawModifierNode
+import androidx.compose.ui.node.ModifierNodeElement
+import androidx.compose.ui.node.invalidateDraw
+import androidx.compose.ui.node.requireGraphicsContext
+import androidx.compose.ui.platform.InspectorInfo
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.IntSize
+import dev.lelonio.square.ui.glass.backdrop.internal.ShapeProvider
+import dev.lelonio.square.ui.glass.backdrop.internal.blur
+import kotlin.math.ceil
+
+internal class ShadowElement(
+ val shapeProvider: ShapeProvider,
+ val shadow: () -> Shadow?
+) : ModifierNodeElement<ShadowNode>() {
+
+ override fun create(): ShadowNode {
+ return ShadowNode(shapeProvider, shadow)
+ }
+
+ override fun update(node: ShadowNode) {
+ node.shapeProvider = shapeProvider
+ node.shadow = shadow
+ node.invalidateDraw()
+ }
+
+ override fun InspectorInfo.inspectableProperties() {
+ name = "shadow"
+ properties["shapeProvider"] = shapeProvider
+ properties["shadow"] = shadow
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is ShadowElement) return false
+
+ if (shapeProvider != other.shapeProvider) return false
+ if (shadow != other.shadow) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ var result = shapeProvider.hashCode()
+ result = 31 * result + shadow.hashCode()
+ return result
+ }
+}
+
+internal class ShadowNode(
+ var shapeProvider: ShapeProvider,
+ var shadow: () -> Shadow?
+) : DrawModifierNode, Modifier.Node() {
+
+ override val shouldAutoInvalidate: Boolean = false
+
+ private var shadowLayer: GraphicsLayer? = null
+
+ private val paint = Paint()
+
+ override fun ContentDrawScope.draw() {
+ val shadow = shadow() ?: return drawContent()
+
+ val shadowLayer = shadowLayer
+ if (shadowLayer != null) {
+ val size = size
+ val density: Density = this
+ val layoutDirection = layoutDirection
+
+ val radius = shadow.radius.toPx()
+ val offsetX = shadow.offset.x.toPx()
+ val offsetY = shadow.offset.y.toPx()
+ val shadowSize = IntSize(
+ ceil(size.width + radius * 4f + offsetX).toInt(),
+ ceil(size.height + radius * 4f + offsetY).toInt()
+ )
+ val outline = shapeProvider.shape.createOutline(size, layoutDirection, density)
+
+ configurePaint(shadow)
+
+ shadowLayer.alpha = shadow.alpha
+ shadowLayer.blendMode = shadow.blendMode
+ shadowLayer.record(shadowSize) {
+ translate(radius * 2f + offsetX, radius * 2f + offsetY) {
+ val canvas = drawContext.canvas
+ canvas.drawOutline(outline, paint)
+ canvas.translate(-offsetX, -offsetY)
+ canvas.drawOutline(outline, ShadowMaskPaint)
+ canvas.translate(offsetX, offsetY)
+ }
+ }
+
+ translate(-radius * 2f, -radius * 2f) {
+ drawLayer(shadowLayer)
+ }
+ }
+
+ drawContent()
+ }
+
+ override fun onAttach() {
+ val graphicsContext = requireGraphicsContext()
+ shadowLayer =
+ graphicsContext.createGraphicsLayer().apply {
+ compositingStrategy = CompositingStrategy.Offscreen
+ }
+ }
+
+ override fun onDetach() {
+ val graphicsContext = requireGraphicsContext()
+ shadowLayer?.let { layer ->
+ graphicsContext.releaseGraphicsLayer(layer)
+ shadowLayer = null
+ }
+ }
+
+ private fun DrawScope.configurePaint(shadow: Shadow) {
+ paint.color = shadow.color
+ paint.blur(shadow.radius.toPx())
+ }
+}
+
+private val ShadowMaskPaint = Paint().apply {
+ blendMode = BlendMode.Clear
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/floatingtabbar/FloatingTabBar.kt b/app/src/main/java/dev/lelonio/square/ui/glass/floatingtabbar/FloatingTabBar.kt
new file mode 100644
index 0000000..00d4a35
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/floatingtabbar/FloatingTabBar.kt
@@ -0,0 +1,2077 @@
+@file:OptIn(ExperimentalSharedTransitionApi::class)
+
+/*
+ * FloatingTabBar v1.0.1 by Elyes Mansour
+ * https://github.com/elyesmansour/compose-floating-tab-bar
+ * Licensed under the Apache License, Version 2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Vendored from the v1.0.1 tag: the published AAR is compiled against
+ * Compose 1.8 and crashes with NoSuchMethodError on
+ * SharedTransitionScope.sharedElement under the Compose version this app uses.
+ * Compiling the source here keeps it binary-compatible.
+ *
+ * Local modifications on top of v1.0.1:
+ * - Package renamed.
+ * - InlineBar/ExpandedBar use Row/Column instead of ConstraintLayout, and the
+ * tab pill + standalone tab cluster is centered (iOS 26 style) instead of
+ * being pinned to opposite screen edges.
+ * - The inline/expanded AnimatedContent is center-aligned so the collapse
+ * animation morphs around the center instead of the start edge.
+ * - ExpandedTabs grew a draggable selection puck ported from Kyant0's
+ * AndroidLiquidGlass catalog (LiquidBottomTabs/LiquidBottomTab): equal-width
+ * tabs, a spring-damped indicator you can press-drag between tabs (release
+ * snaps to and navigates the nearest tab), a finger-tracking glow, and —
+ * when an optional [Backdrop] is supplied — chromatic lens refraction and
+ * an accent-tinted glass sample of the selected tab's icon showing through
+ * the puck. See [DampedDragAnimation] and [InteractiveHighlight].
+ */
+
+package dev.lelonio.square.ui.glass.floatingtabbar
+
+import androidx.compose.animation.AnimatedContent
+import androidx.compose.animation.AnimatedVisibilityScope
+import androidx.compose.animation.EnterExitState
+import androidx.compose.animation.ExperimentalSharedTransitionApi
+import androidx.compose.animation.SharedTransitionLayout
+import androidx.compose.animation.SharedTransitionScope
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.EaseOut
+import androidx.compose.animation.core.FastOutSlowInEasing
+import androidx.compose.animation.core.animateFloat
+import androidx.compose.animation.core.keyframes
+import androidx.compose.animation.core.spring
+import androidx.compose.animation.core.tween
+import androidx.compose.animation.core.updateTransition
+import androidx.compose.animation.fadeIn
+import androidx.compose.animation.fadeOut
+import androidx.compose.animation.togetherWith
+import androidx.compose.foundation.Indication
+import androidx.compose.foundation.LocalIndication
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.IntrinsicSize
+import androidx.compose.foundation.layout.aspectRatio
+import androidx.compose.foundation.layout.defaultMinSize
+import androidx.compose.foundation.layout.calculateEndPadding
+import androidx.compose.foundation.layout.calculateStartPadding
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.layout.wrapContentWidth
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.staticCompositionLocalOf
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.derivedStateOf
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.rememberUpdatedState
+import androidx.compose.runtime.mutableIntStateOf
+import androidx.compose.runtime.mutableStateListOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.alpha
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.shadow
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.graphics.BlurEffect
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ColorFilter
+import androidx.compose.ui.graphics.CompositingStrategy
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
+import androidx.compose.ui.input.nestedscroll.NestedScrollSource
+import androidx.compose.ui.draw.drawBehind
+import androidx.compose.ui.graphics.drawOutline
+import androidx.compose.ui.layout.onSizeChanged
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.platform.LocalLayoutDirection
+import androidx.compose.ui.semantics.clearAndSetSemantics
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.unit.Velocity
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.util.fastCoerceIn
+import androidx.compose.ui.util.fastRoundToInt
+import dev.lelonio.square.ui.glass.LocalGlassEffectConfig
+import dev.lelonio.square.ui.glass.glassResolutionScale
+import androidx.compose.ui.util.lerp
+import androidx.compose.ui.graphics.isSpecified
+import androidx.compose.ui.graphics.luminance
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.catalog.utils.DampedDragAnimation
+import dev.lelonio.square.ui.glass.backdrop.catalog.utils.InteractiveHighlight
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.effects.lens
+import dev.lelonio.square.ui.glass.backdrop.effects.vibrancy
+import dev.lelonio.square.ui.glass.backdrop.highlight.Highlight
+import dev.lelonio.square.ui.glass.backdrop.shadow.InnerShadow
+import dev.lelonio.square.ui.glass.backdrop.shadow.Shadow
+import dev.lelonio.square.ui.glass.shapes.ContinuousRoundedRectangle
+import kotlinx.coroutines.launch
+import kotlin.math.abs
+import kotlin.math.sign
+
+
+
+// Tuning for the gooey merge/split pulse across the inline<->expanded
+// crossfade — see GooeyTransition.kt. Not derived from fadeIn()/fadeOut()'s
+// own duration; just a reasonable match for it.
+private val GooeyPeakBlur = 12.dp
+private const val GooeyDurationMs = 300
+
+// Rim/shadow the selection puck keeps when it is NOT being pressed. Both used to
+// be driven straight off pressProgress, i.e. zero at rest, which left the puck
+// defined only by its own dark surface wash — invisible against a dark bar.
+// How long the selection puck takes to arrive when the bar unfolds, and how
+// small it starts. Matched to [GooeyDurationMs], the length of the fold itself:
+// the puck is not part of the shared element that travels, so the only thing
+// keeping the two together is that they take the same time.
+private const val PuckEnterMs = GooeyDurationMs
+private const val PuckEnterScale = 0.82f
+
+private const val PuckRestHighlightAlpha = 0.5f
+private const val PuckRestShadowAlpha = 0.35f
+
+// Vendored addition: the three shapes the bar can render. INLINE is the
+// scroll-collapsed row (unchanged by search mode); EXPANDED is the normal
+// all-tabs pill; SEARCH_EXPANDED replaces EXPANDED while search mode is
+// active (see SearchExpandedBar).
+private enum class FloatingTabBarVisual { INLINE, EXPANDED, SEARCH_EXPANDED }
+
+// Matches the established inline-row height (InlineStandaloneTab's own
+// defaultMinSize floor at the FloatingNavBar call site, and the inline mini
+// player's own ~48dp content height) so the search-expanded row doesn't read
+// shorter than the bar's own shrunk state.
+private val SearchBarRowHeight = 48.dp
+
+/**
+ * A floating tab bar that transitions between inline and expanded states based on scroll behavior.
+ *
+ * @param selectedTabKey the key of the currently selected tab
+ * @param scrollConnection the scroll connection that handles state transitions
+ * @param modifier the modifier to be applied to the tab bar
+ * @param colors the colors used by the tab bar components
+ * @param shapes the shapes used by the tab bar components
+ * @param sizes the sizes and spacing used by the tab bar components
+ * @param elevations the elevation values used by the tab bar components
+ * @param tabBarContentModifier modifier applied to the tab bar sections containing the grouped tabs and standalone tab.
+ * It is applied after the default styling (background, shadow, clip) but before any content padding.
+ * @param inlineAccessory the accessory composable that appears in inline state (e.g., compact media player)
+ * @param expandedAccessory the accessory composable that appears in expanded state (e.g., full media player)
+ * @param content the content defining the tabs
+ */
+@Composable
+fun FloatingTabBar(
+ selectedTabKey: Any?,
+ scrollConnection: FloatingTabBarScrollConnection,
+ modifier: Modifier = Modifier,
+ tabBarContentModifier: Modifier = Modifier,
+ inlineAccessory: (@Composable SharedTransitionScope.(Modifier, AnimatedVisibilityScope) -> Unit)? = null,
+ expandedAccessory: (@Composable SharedTransitionScope.(Modifier, AnimatedVisibilityScope) -> Unit)? = null,
+ colors: FloatingTabBarColors = FloatingTabBarDefaults.colors(),
+ shapes: FloatingTabBarShapes = FloatingTabBarDefaults.shapes(),
+ sizes: FloatingTabBarSizes = FloatingTabBarDefaults.sizes(),
+ elevations: FloatingTabBarElevations = FloatingTabBarDefaults.elevations(),
+ // Vendored addition: when non-null, the expanded selection puck samples this
+ // backdrop for lens refraction and an accent-tinted glass preview of the
+ // selected tab's icon. Null falls back to a flat colored puck.
+ backdrop: Backdrop? = null,
+ accentColor: Color? = null,
+ // Vendored addition: when true (and searchBarContent non-null), the
+ // expanded state renders SearchExpandedBar instead of ExpandedBar — the
+ // tab group shrinks to the current screen's own icon and the standalone
+ // slot expands to fill the rest of the row with searchBarContent. The
+ // inline (scrolled) state is unaffected — it stays the normal collapsed
+ // icon+accessory+standalone row regardless of searchMode.
+ searchMode: Boolean = false,
+ searchBarContent: (@Composable (Modifier) -> Unit)? = null,
+ // Vendored addition: caller-held width (from a previous onExpandedWidthChanged
+ // report) that SearchExpandedBar holds its row to, so the bar doesn't visibly
+ // widen to fill available space when entering search mode. Null/0 falls back
+ // to filling available space (e.g. first-ever composition in search mode).
+ expandedContentWidthPx: Int? = null,
+ onExpandedWidthChanged: ((Int) -> Unit)? = null,
+ content: FloatingTabBarScope.() -> Unit
+) {
+ // Rebuilt every composition, deliberately not remembered. The tabs hold
+ // @Composable lambdas that close over selection state and colours; caching
+ // them behind a key meant every value they captured had to be listed in that
+ // key by hand, and anything forgotten showed up as a stale icon or colour on
+ // one navigation path only. Re-running the builder is a handful of
+ // allocations for a few tabs, and it makes that whole class of bug
+ // unrepresentable.
+ val scope = FloatingTabBarScopeImpl().apply { content() }
+
+ val isAccessoryShared = inlineAccessory != null && expandedAccessory != null
+
+ val visual = when {
+ scrollConnection.isInline -> FloatingTabBarVisual.INLINE
+ searchMode && searchBarContent != null -> FloatingTabBarVisual.SEARCH_EXPANDED
+ else -> FloatingTabBarVisual.EXPANDED
+ }
+
+ // updateTransition (rather than the sugared top-level AnimatedContent) so
+ // the transition object is available here to drive the gooey blur pulse,
+ // not just inside the content lambda.
+ val transition = updateTransition(targetState = visual, label = "floatingTabBarVisual")
+ val gooeyBlurPx = with(LocalDensity.current) { GooeyPeakBlur.toPx() }
+ // Liquid "gooey" merge/split (see GooeyTransition.kt): peaks mid-crossfade
+ // and returns to 0 at rest, on every transition regardless of direction —
+ // the keyframes spec defines the peak explicitly rather than deriving it
+ // from a start/end value, since the steady-state target is always 0.
+ // LOCAL CHANGE: held as State and read in the draw phase, not unwrapped
+ // here. Read as a value, every frame of the fold recomposed this whole
+ // subtree — the bar, both of its states, and the accessory inside them —
+ // which is what made the animation stutter on a mid-range phone. The
+ // modifier below reads it inside its own graphicsLayer block instead, so a
+ // frame of the fold costs a draw and nothing more.
+ val gooeyProgress = transition.animateFloat(
+ transitionSpec = {
+ keyframes {
+ durationMillis = GooeyDurationMs
+ 0f at 0
+ 1f atFraction 0.5f using FastOutSlowInEasing
+ 0f at GooeyDurationMs
+ }
+ },
+ label = "gooeyProgress"
+ ) { _ -> 0f }
+
+ SharedTransitionLayout(modifier = modifier) {
+ // Wrapping AnimatedContent itself (not SharedTransitionLayout's own
+ // modifier) so the offscreen gooey capture stays under
+ // SharedTransitionLayout's own overlay mechanism — sharedElement-
+ // tracked content (like the search tab's shared "standaloneTab"
+ // bounds) renders via that overlay, and capturing it into the gooey
+ // layer at the wrong level made it visibly pop in a frame late when
+ // re-expanding. This way the overlay draws normally, on top.
+ // Held as a lambda rather than a Boolean so flipping it costs no
+ // recomposition — the glass surfaces call it during draw. See
+ // LocalTabBarBackdropFrozen.
+ val frozenWhileAnimating = remember(transition) {
+ { transition.currentState != transition.targetState }
+ }
+ CompositionLocalProvider(LocalTabBarBackdropFrozen provides frozenWhileAnimating) {
+ // Always applied: `gooey` is a no-op at radius 0 (no offscreen layer,
+ // no filter), so there is nothing to gate on and nothing to recompose.
+ Box(Modifier.gooey { gooeyBlurPx * gooeyProgress.value }) {
+ transition.AnimatedContent(
+ transitionSpec = { fadeIn() togetherWith fadeOut() },
+ contentAlignment = Alignment.BottomCenter
+ ) { targetVisual ->
+ when (targetVisual) {
+ FloatingTabBarVisual.INLINE -> InlineBar(
+ scope = scope,
+ selectedTabKey = selectedTabKey,
+ accessory = inlineAccessory,
+ isAccessoryShared = isAccessoryShared,
+ onInlineTabClick = { scrollConnection.expand() },
+ colors = colors,
+ shapes = shapes,
+ sizes = sizes,
+ elevations = elevations,
+ tabBarContentModifier = tabBarContentModifier,
+ animatedVisibilityScope = this@AnimatedContent
+ )
+ FloatingTabBarVisual.EXPANDED -> ExpandedBar(
+ scope = scope,
+ selectedTabKey = selectedTabKey,
+ accessory = expandedAccessory,
+ isAccessoryShared = isAccessoryShared,
+ colors = colors,
+ shapes = shapes,
+ sizes = sizes,
+ elevations = elevations,
+ tabBarContentModifier = tabBarContentModifier,
+ animatedVisibilityScope = this@AnimatedContent,
+ backdrop = backdrop,
+ accentColor = accentColor,
+ onWidthMeasured = onExpandedWidthChanged
+ )
+ FloatingTabBarVisual.SEARCH_EXPANDED -> SearchExpandedBar(
+ scope = scope,
+ selectedTabKey = selectedTabKey,
+ accessory = expandedAccessory,
+ isAccessoryShared = isAccessoryShared,
+ colors = colors,
+ shapes = shapes,
+ sizes = sizes,
+ elevations = elevations,
+ tabBarContentModifier = tabBarContentModifier,
+ animatedVisibilityScope = this@AnimatedContent,
+ searchBarContent = searchBarContent ?: {},
+ targetWidthPx = expandedContentWidthPx
+ )
+ }
+ }
+ }
+ }
+ }
+}
+
+/**
+ * True for exactly the frames of a tab bar transition (inline <-> expanded <->
+ * search). The bar's glass surfaces pass it to `drawBackdrop`'s `frozen`, which
+ * makes them reuse their last backdrop capture instead of re-recording the whole
+ * screen every frame while their bounds animate.
+ *
+ * A lambda, not a Boolean, so flipping it triggers no recomposition — the surfaces
+ * call it during draw. Static local for the same reason: the lambda's identity is
+ * stable, only what it reads changes.
+ */
+val LocalTabBarBackdropFrozen = staticCompositionLocalOf<() -> Boolean> { { false } }
+
+/**
+ * A [NestedScrollConnection] that handles scroll events to transition between inline and expanded states.
+ *
+ * @param initialIsInline Initial state of the tab bar (inline or expanded).
+ * @param scrollThresholdPx The minimum scroll distance in pixels required to collapse to inline.
+ * @param expandThresholdPx The minimum scroll distance in pixels required to expand back. Kept
+ * well below [scrollThresholdPx] so the bar returns as soon as the user scrolls up.
+ * @param inlineBehavior Defines when the tab bar should transition to inline state.
+ */
+class FloatingTabBarScrollConnection(
+ initialIsInline: Boolean = false,
+ private val scrollThresholdPx: Float,
+ private val expandThresholdPx: Float = scrollThresholdPx,
+ private val inlineBehavior: FloatingTabBarInlineBehavior = FloatingTabBarInlineBehavior.OnScrollDown
+) : NestedScrollConnection {
+ var isInline by mutableStateOf(initialIsInline)
+ private set
+
+ /**
+ * LOCAL CHANGE: while true, scrolling leaves the bar alone.
+ *
+ * For searching. The bar carries the text field, and folding it takes the
+ * field away mid-search: scrolling the results put it back a moment later,
+ * which re-created the field, which asked for the focus again, which opened
+ * the keyboard — every scroll up. And a bar that folds while you are typing
+ * in it is wrong even without that.
+ */
+ var locked by mutableStateOf(false)
+
+ /**
+ * LOCAL CHANGE: true while the page under the bar is moving.
+ *
+ * Every glass surface samples a recording of the screen, and a recording of
+ * a scrolling screen is a new recording sixty times a second — so each pane
+ * re-captures and re-runs its blur and lens on every frame of every scroll.
+ * Measured on the home page: 57ms a frame with the glass on, 25ms with it
+ * off. Nobody can read the refraction through a surface while the thing
+ * behind it is flying past, so during the scroll they hold the last one.
+ */
+ var scrolling by mutableStateOf(false)
+ private set
+
+ private var accumulatedScroll = 0f
+
+ fun expand() {
+ isInline = false
+ accumulatedScroll = 0f
+ }
+
+ fun inline() {
+ isInline = true
+ accumulatedScroll = 0f
+ }
+
+ override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
+ // If behavior is Never, don't change state
+ if (inlineBehavior == FloatingTabBarInlineBehavior.Never || locked) {
+ return Offset.Zero
+ }
+
+ val scrollDelta = available.y
+ if (scrollDelta != 0f) scrolling = true
+
+ // Reset accumulated scroll if changing direction
+ if ((accumulatedScroll > 0 && scrollDelta < 0) || (accumulatedScroll < 0 && scrollDelta > 0)) {
+ accumulatedScroll = 0f
+ }
+
+ // Accumulate scroll
+ accumulatedScroll += scrollDelta
+
+ when (inlineBehavior) {
+ FloatingTabBarInlineBehavior.OnScrollDown -> {
+ // Asymmetric on purpose. Collapsing wants hysteresis so a jittery
+ // downward scroll can't flicker the bar, and the distance is free
+ // there — the user is already moving away. Expanding is the
+ // opposite: the bar is what they are reaching for, so making them
+ // drag the same distance back reads as the bar being slow to
+ // return. Coming back is near-immediate, with just enough travel
+ // required that a shaky finger mid-scroll can't oscillate it.
+ // LOCAL CHANGE: scrolling down folds it, scrolling up does not
+ // bring it back. Only arriving at the top of the page does (see
+ // onPostScroll), or tapping a tab.
+ //
+ // Upstream is symmetric, and symmetric is what a scrolling reader
+ // feels as the bar flickering: every small correction upwards
+ // pulled the whole thing open over the text again. The top of the
+ // page is a place rather than a direction, so the bar comes back
+ // when you have actually arrived somewhere.
+ if (accumulatedScroll <= -scrollThresholdPx && !isInline) {
+ isInline = true
+ accumulatedScroll = 0f // Reset after state change
+ }
+ }
+
+ FloatingTabBarInlineBehavior.OnScrollUp -> {
+ // Check if we've scrolled enough to trigger state change
+ if (accumulatedScroll >= scrollThresholdPx && !isInline) {
+ // Scrolling up enough - transition to inline mode
+ isInline = true
+ accumulatedScroll = 0f // Reset after state change
+ } else if (accumulatedScroll <= -scrollThresholdPx && isInline) {
+ // Scrolling down enough - transition to expanded mode
+ isInline = false
+ accumulatedScroll = 0f // Reset after state change
+ }
+ }
+
+ FloatingTabBarInlineBehavior.Never -> {
+ // Already handled above, but included for completeness
+ }
+ }
+
+ return Offset.Zero // Don't consume the scroll, let it pass through
+ }
+
+ /**
+ * LOCAL CHANGE: the bar comes back at the top of the page.
+ *
+ * What reaches here is what the content could not use. Dragging downwards
+ * with nothing left to scroll means the list is already at its first item,
+ * which is the one moment the bar is asked for rather than in the way.
+ */
+ override suspend fun onPreFling(available: Velocity): Velocity {
+ // The end of the gesture, fling or not: Compose calls this on release
+ // either way, with a velocity of zero when there was none.
+ scrolling = false
+ return Velocity.Zero
+ }
+
+ override fun onPostScroll(
+ consumed: Offset,
+ available: Offset,
+ source: NestedScrollSource,
+ ): Offset {
+ if (inlineBehavior == FloatingTabBarInlineBehavior.Never || locked) {
+ return Offset.Zero
+ }
+ if (isInline && available.y > 0f) expand()
+ return Offset.Zero
+ }
+}
+
+/**
+ * Creates and remembers a [FloatingTabBarScrollConnection] instance.
+ *
+ * @param initialIsInline Initial state of the tab bar (inline or expanded). Default is false.
+ * @param scrollThreshold The scroll distance required to collapse to inline. Default is 50.dp.
+ * @param expandThreshold The scroll distance required to expand back. Default is 8.dp — small
+ * enough that the bar returns immediately on scroll up, large enough that a shaky finger
+ * mid-scroll cannot oscillate it.
+ * @param inlineBehavior Defines when the tab bar should transition to inline state. Default is [FloatingTabBarInlineBehavior.OnScrollDown].
+ * @return A remembered [FloatingTabBarScrollConnection] instance.
+ */
+@Composable
+fun rememberFloatingTabBarScrollConnection(
+ initialIsInline: Boolean = false,
+ scrollThreshold: Dp = 50.dp,
+ expandThreshold: Dp = 8.dp,
+ inlineBehavior: FloatingTabBarInlineBehavior = FloatingTabBarInlineBehavior.OnScrollDown
+): FloatingTabBarScrollConnection = with(LocalDensity.current) {
+ val scrollThresholdPx = scrollThreshold.toPx()
+ val expandThresholdPx = expandThreshold.toPx()
+ remember(scrollThresholdPx, expandThresholdPx, inlineBehavior, initialIsInline) {
+ FloatingTabBarScrollConnection(
+ initialIsInline,
+ scrollThresholdPx,
+ expandThresholdPx,
+ inlineBehavior,
+ )
+ }
+}
+
+/**
+ * Defines when the floating tab bar should transition to inline state.
+ */
+enum class FloatingTabBarInlineBehavior {
+ /** Never transition to inline - it stays in expanded state */
+ Never,
+
+ /** Transition to inline when scrolling down */
+ OnScrollDown,
+
+ /** Transition to inline when scrolling up */
+ OnScrollUp
+}
+
+interface FloatingTabBarScope {
+ /**
+ * Adds a regular tab to the floating tab bar.
+ *
+ * @param key Unique identifier for the tab
+ * @param title Composable content for the tab title
+ * @param icon Composable content for the tab icon
+ * @param onClick Callback invoked when the tab is clicked
+ * @param indication Optional indication provider for touch feedback, defaults to LocalIndication.current
+ */
+ fun tab(
+ key: Any,
+ title: @Composable () -> Unit,
+ icon: @Composable () -> Unit,
+ onClick: () -> Unit,
+ indication: (@Composable () -> Indication)? = { LocalIndication.current }
+ )
+
+ /**
+ * Adds a standalone tab to the floating tab bar.
+ *
+ * Note: Calling this method more than once will override the previous standalone tab value.
+ *
+ * @param key Unique identifier for the standalone tab
+ * @param icon Composable content for the tab icon
+ * @param onClick Callback invoked when the tab is clicked
+ * @param indication Optional indication provider for touch feedback, defaults to LocalIndication.current
+ * @param title Composable content for the tab title. Never actually shown —
+ * the standalone tab is always an icon-only floating circle, in both inline
+ * and expanded states (see InlineStandaloneTab / ExpandedStandaloneTab).
+ */
+ fun standaloneTab(
+ key: Any,
+ icon: @Composable () -> Unit,
+ onClick: () -> Unit,
+ indication: (@Composable () -> Indication)? = { LocalIndication.current },
+ title: @Composable () -> Unit = {}
+ )
+}
+
+/**
+ * Plain release-triggered [clickable]. Firing on finger-DOWN (the old behaviour)
+ * meant any touch that turned into a scroll or a puck drag still navigated first —
+ * "opens a screen even when I didn't drop the puck". Release-fire lets Compose's
+ * touch-slop arbitration cancel the tap when the gesture becomes a drag/scroll, so
+ * only a real tap navigates. Keeps the custom [indication].
+ */
+@Composable
+private fun Modifier.tapClickable(
+ indication: Indication?,
+ onClick: () -> Unit,
+): Modifier {
+ val interactionSource = remember { MutableInteractionSource() }
+ return clickable(
+ onClick = onClick,
+ indication = indication,
+ interactionSource = interactionSource
+ )
+}
+
+@Composable
+private fun SharedTransitionScope.InlineBar(
+ scope: FloatingTabBarScopeImpl,
+ selectedTabKey: Any?,
+ accessory: (@Composable SharedTransitionScope.(Modifier, AnimatedVisibilityScope) -> Unit)?,
+ isAccessoryShared: Boolean,
+ onInlineTabClick: () -> Unit,
+ colors: FloatingTabBarColors,
+ shapes: FloatingTabBarShapes,
+ sizes: FloatingTabBarSizes,
+ elevations: FloatingTabBarElevations,
+ tabBarContentModifier: Modifier,
+ animatedVisibilityScope: AnimatedVisibilityScope
+) {
+ val inlineTab = scope.getInlineTab(selectedTabKey)
+ val standaloneTab = scope.standaloneTab
+ val hasInlineTab = inlineTab != null
+
+ // With an accessory the row spans the full width ([tab][accessory][standalone],
+ // iOS 26 Apple Music style); without one, the cluster is packed and centered.
+ Row(
+ horizontalArrangement = Arrangement.spacedBy(sizes.componentSpacing),
+ verticalAlignment = Alignment.CenterVertically,
+ modifier = Modifier
+ .fillMaxWidth()
+ .then(if (accessory == null) Modifier.wrapContentWidth() else Modifier)
+ .height(IntrinsicSize.Max)
+ ) {
+ if (hasInlineTab) {
+ InlineTab(
+ inlineTab = inlineTab,
+ onInlineTabClick = onInlineTabClick,
+ shapes = shapes,
+ sizes = sizes,
+ colors = colors,
+ elevations = elevations,
+ animatedVisibilityScope = animatedVisibilityScope,
+ tabBarContentModifier = tabBarContentModifier,
+ modifier = Modifier
+ )
+ }
+
+ if (accessory != null) {
+ InlineAccessory(
+ accessory = accessory,
+ isAccessoryShared = isAccessoryShared,
+ shapes = shapes,
+ colors = colors,
+ elevations = elevations,
+ animatedVisibilityScope = animatedVisibilityScope,
+ modifier = Modifier
+ .weight(1f)
+ .fillMaxHeight()
+ )
+ }
+
+ if (standaloneTab != null) {
+ InlineStandaloneTab(
+ standaloneTab = standaloneTab,
+ shapes = shapes,
+ sizes = sizes,
+ colors = colors,
+ elevations = elevations,
+ animatedVisibilityScope = animatedVisibilityScope,
+ tabBarContentModifier = tabBarContentModifier,
+ // fillMaxHeight() + the row's IntrinsicSize.Max is supposed to
+ // match this to the docked mini player's height, but intrinsic
+ // measurement can under-report the mini player's actual
+ // (dynamically-measured) content height — floor it explicitly
+ // so the standalone tab pill can't end up shorter.
+ modifier = Modifier
+ .defaultMinSize(minHeight = 48.dp)
+ .fillMaxHeight()
+ // Height-first: aspectRatio resolves from maxWidth by default,
+ // so on a narrow bar the leftover width — not the row height —
+ // decided the circle's diameter and it came out smaller than the
+ // bar beside it.
+ .aspectRatio(1f, matchHeightConstraintsFirst = true)
+ )
+ }
+ }
+}
+
+@Composable
+private fun SharedTransitionScope.InlineTab(
+ inlineTab: FloatingTabBarTab,
+ onInlineTabClick: () -> Unit,
+ shapes: FloatingTabBarShapes,
+ sizes: FloatingTabBarSizes,
+ colors: FloatingTabBarColors,
+ elevations: FloatingTabBarElevations,
+ animatedVisibilityScope: AnimatedVisibilityScope,
+ modifier: Modifier,
+ tabBarContentModifier: Modifier
+) {
+ Box(
+ modifier = modifier
+ .sharedElement(
+ sharedContentState = rememberSharedContentState("tabGroup"),
+ animatedVisibilityScope = animatedVisibilityScope,
+ zIndexInOverlay = 1f
+ )
+ .shadow(
+ shape = shapes.tabBarShape,
+ elevation = elevations.inlineElevation
+ )
+ .background(
+ color = colors.backgroundColor,
+ shape = shapes.tabBarShape
+ )
+ .clip(shapes.tabBarShape)
+ .then(tabBarContentModifier)
+ .tapClickable(
+ indication = inlineTab.indication?.invoke(),
+ onClick = {
+ onInlineTabClick()
+ inlineTab.onClick()
+ }
+ )
+ .padding(sizes.tabInlineContentPadding)
+ ) {
+ Tab(
+ icon = {
+ Box(
+ Modifier.sharedElement(
+ sharedContentState = rememberSharedContentState("tab#${inlineTab.key}-icon"),
+ animatedVisibilityScope = animatedVisibilityScope,
+ zIndexInOverlay = 1f
+ )
+ ) {
+ inlineTab.icon()
+ }
+ },
+ title = { inlineTab.title() },
+ isInline = true
+ )
+ }
+}
+
+@Composable
+private fun SharedTransitionScope.InlineStandaloneTab(
+ standaloneTab: FloatingTabBarTab,
+ shapes: FloatingTabBarShapes,
+ sizes: FloatingTabBarSizes,
+ colors: FloatingTabBarColors,
+ elevations: FloatingTabBarElevations,
+ animatedVisibilityScope: AnimatedVisibilityScope,
+ modifier: Modifier,
+ tabBarContentModifier: Modifier
+) {
+ // Same finger-tracking glow as the keyboard-active search pill
+ // (NavBarSearchInputBar) — a soft radial light following the touch point.
+ val glowScope = rememberCoroutineScope()
+ val glow = remember(glowScope) { InteractiveHighlight(animationScope = glowScope) }
+
+ Tab(
+ icon = standaloneTab.icon,
+ title = standaloneTab.title,
+ isInline = true,
+ isStandalone = true,
+ modifier = modifier
+ .sharedElement(
+ sharedContentState = rememberSharedContentState("standaloneTab"),
+ animatedVisibilityScope = animatedVisibilityScope,
+ zIndexInOverlay = 1f
+ )
+ .shadow(
+ shape = shapes.standaloneTabShape,
+ elevation = elevations.inlineElevation
+ )
+ .background(
+ color = colors.backgroundColor,
+ shape = shapes.standaloneTabShape
+ )
+ .clip(shapes.standaloneTabShape)
+ .then(tabBarContentModifier)
+ .then(glow.gestureModifier)
+ .then(glow.modifier)
+ .tapClickable(
+ indication = standaloneTab.indication?.invoke(),
+ onClick = standaloneTab.onClick
+ )
+ // Unlike the regular tab pill (InlineTab, ExpandedTabs), this circle had
+ // no inset at all — the icon sat flush against its edge.
+ .padding(sizes.tabInlineContentPadding)
+ )
+}
+
+@Composable
+private fun SharedTransitionScope.InlineAccessory(
+ accessory: (@Composable SharedTransitionScope.(Modifier, AnimatedVisibilityScope) -> Unit)?,
+ isAccessoryShared: Boolean,
+ colors: FloatingTabBarColors,
+ shapes: FloatingTabBarShapes,
+ elevations: FloatingTabBarElevations,
+ animatedVisibilityScope: AnimatedVisibilityScope,
+ modifier: Modifier
+) {
+ accessory?.let { accessory ->
+ Box(
+ modifier = modifier
+ .then(
+ if (isAccessoryShared) {
+ Modifier.sharedElement(
+ sharedContentState = rememberSharedContentState("accessory"),
+ animatedVisibilityScope = animatedVisibilityScope
+ )
+ } else {
+ Modifier.animateEnterExitAccessory(
+ sharedTransitionScope = this,
+ animatedVisibilityScope = animatedVisibilityScope
+ )
+ }
+ )
+ ) {
+ accessory(
+ Modifier
+ .fillMaxSize()
+ .shadow(
+ shape = shapes.accessoryShape,
+ elevation = elevations.inlineElevation
+ )
+ .background(color = colors.accessoryBackgroundColor, shapes.accessoryShape)
+ .clip(shapes.accessoryShape),
+ animatedVisibilityScope
+ )
+ }
+ }
+}
+
+@Composable
+private fun SharedTransitionScope.ExpandedBar(
+ scope: FloatingTabBarScopeImpl,
+ selectedTabKey: Any?,
+ accessory: (@Composable SharedTransitionScope.(Modifier, AnimatedVisibilityScope) -> Unit)?,
+ isAccessoryShared: Boolean,
+ colors: FloatingTabBarColors,
+ shapes: FloatingTabBarShapes,
+ sizes: FloatingTabBarSizes,
+ elevations: FloatingTabBarElevations,
+ tabBarContentModifier: Modifier,
+ animatedVisibilityScope: AnimatedVisibilityScope,
+ backdrop: Backdrop?,
+ accentColor: Color?,
+ // Vendored addition: reports this row's own measured width upward so
+ // SearchExpandedBar can hold the bar at the exact same overall width
+ // instead of expanding to fill all available space in search mode.
+ onWidthMeasured: ((Int) -> Unit)? = null,
+) {
+ val hasTabGroup = scope.tabs.isNotEmpty()
+ val standaloneTab = scope.standaloneTab
+
+ // The accessory matches the tab row's own (content-sized, not full-bleed)
+ // width, so both pills line up edge to edge. The tab row is measured first
+ // (onSizeChanged below); the accessory falls back to fillMaxWidth until
+ // that first measurement lands — a one-frame lag, same pattern as
+ // FloatingMiniPlayer's measuredHeightPx.
+ val density = LocalDensity.current
+ var tabRowWidthPx by remember { mutableIntStateOf(0) }
+
+ // The standalone tab (search) is always its own floating circle — same as
+ // the inline (collapsed) state — never merged into the tab group pill, so
+ // it reads as one consistent circular element through both inline and
+ // expanded states (see ExpandedStandaloneTab / InlineStandaloneTab, tied
+ // together by the shared "standaloneTab" element).
+ Column(
+ horizontalAlignment = Alignment.CenterHorizontally,
+ verticalArrangement = Arrangement.spacedBy(sizes.componentSpacing),
+ modifier = Modifier.fillMaxWidth()
+ ) {
+ if (accessory != null) {
+ ExpandedAccessory(
+ accessory = accessory,
+ isAccessoryShared = isAccessoryShared,
+ shapes = shapes,
+ colors = colors,
+ elevations = elevations,
+ animatedVisibilityScope = animatedVisibilityScope,
+ modifier = if (tabRowWidthPx > 0) {
+ Modifier.width(with(density) { tabRowWidthPx.toDp() })
+ } else {
+ Modifier.fillMaxWidth()
+ }
+ )
+ }
+
+ Row(
+ horizontalArrangement = Arrangement.spacedBy(sizes.componentSpacing),
+ verticalAlignment = Alignment.CenterVertically,
+ modifier = Modifier
+ .height(IntrinsicSize.Max)
+ .onSizeChanged {
+ tabRowWidthPx = it.width
+ onWidthMeasured?.invoke(it.width)
+ }
+ ) {
+ if (hasTabGroup) {
+ ExpandedTabs(
+ scope = scope,
+ selectedTabKey = selectedTabKey,
+ shapes = shapes,
+ sizes = sizes,
+ colors = colors,
+ elevations = elevations,
+ animatedVisibilityScope = animatedVisibilityScope,
+ tabBarContentModifier = tabBarContentModifier,
+ backdrop = backdrop,
+ accentColor = accentColor ?: colors.backgroundColor,
+ modifier = Modifier
+ )
+ }
+
+ if (standaloneTab != null) {
+ ExpandedStandaloneTab(
+ standaloneTab = standaloneTab,
+ shapes = shapes,
+ sizes = sizes,
+ colors = colors,
+ elevations = elevations,
+ animatedVisibilityScope = animatedVisibilityScope,
+ tabBarContentModifier = tabBarContentModifier,
+ modifier = Modifier
+ // Same floor the inline row already needed: IntrinsicSize.Max
+ // can under-report the tab group's real height, and without a
+ // floor this circle shrinks to that under-reported value while
+ // the tab pill measures its true (taller) content — which is
+ // the search pill looking smaller than the nav bar.
+ .defaultMinSize(minHeight = 48.dp)
+ .fillMaxHeight()
+ // Height-first, as in the inline row: the default resolves the
+ // square from maxWidth, so leftover row width could decide the
+ // diameter instead of the bar height.
+ .aspectRatio(1f, matchHeightConstraintsFirst = true)
+ )
+ }
+ }
+ }
+}
+
+/**
+ * Vendored addition: the search-active expanded shape. Same accessory-above
+ * treatment as [ExpandedBar], but the row below it is the collapsed-style
+ * single current-screen icon ([InlineTab], reused as-is) next to
+ * [searchBarContent] filling the rest of the row — instead of the full
+ * tab-group pill + circular standalone tab.
+ */
+@Composable
+private fun SharedTransitionScope.SearchExpandedBar(
+ scope: FloatingTabBarScopeImpl,
+ selectedTabKey: Any?,
+ accessory: (@Composable SharedTransitionScope.(Modifier, AnimatedVisibilityScope) -> Unit)?,
+ isAccessoryShared: Boolean,
+ colors: FloatingTabBarColors,
+ shapes: FloatingTabBarShapes,
+ sizes: FloatingTabBarSizes,
+ elevations: FloatingTabBarElevations,
+ tabBarContentModifier: Modifier,
+ animatedVisibilityScope: AnimatedVisibilityScope,
+ searchBarContent: @Composable (Modifier) -> Unit,
+ // Vendored addition: the normal-expanded row's own last-measured width
+ // (see ExpandedBar's onWidthMeasured) — holding this row to that same
+ // width keeps the bar's overall footprint constant across search mode
+ // instead of the searchBarContent's weight(1f) filling all available
+ // space. Null/0 (nothing measured yet) falls back to filling available
+ // width.
+ targetWidthPx: Int?,
+) {
+ val inlineTab = scope.getInlineTab(selectedTabKey)
+ val density = LocalDensity.current
+ val targetWidthModifier = if (targetWidthPx != null && targetWidthPx > 0) {
+ Modifier.width(with(density) { targetWidthPx.toDp() })
+ } else {
+ Modifier.fillMaxWidth()
+ }
+
+ Column(
+ horizontalAlignment = Alignment.CenterHorizontally,
+ verticalArrangement = Arrangement.spacedBy(sizes.componentSpacing),
+ modifier = Modifier.fillMaxWidth()
+ ) {
+ if (accessory != null) {
+ ExpandedAccessory(
+ accessory = accessory,
+ isAccessoryShared = isAccessoryShared,
+ shapes = shapes,
+ colors = colors,
+ elevations = elevations,
+ animatedVisibilityScope = animatedVisibilityScope,
+ modifier = targetWidthModifier
+ )
+ }
+
+ Row(
+ horizontalArrangement = Arrangement.spacedBy(sizes.componentSpacing),
+ verticalAlignment = Alignment.CenterVertically,
+ // Fixed rather than IntrinsicSize.Max: matches the mini player's own
+ // inline (shrunk) height exactly instead of letting a short
+ // searchBarContent under-report its intrinsic height and shrink the row.
+ modifier = Modifier.height(SearchBarRowHeight).then(targetWidthModifier)
+ ) {
+ if (inlineTab != null) {
+ InlineTab(
+ inlineTab = inlineTab,
+ // Already expanded — a tap here should just navigate
+ // (inlineTab.onClick, fired inside InlineTab itself), not
+ // trigger the inline scroll-connection's expand().
+ onInlineTabClick = {},
+ shapes = shapes,
+ sizes = sizes,
+ colors = colors,
+ elevations = elevations,
+ animatedVisibilityScope = animatedVisibilityScope,
+ tabBarContentModifier = tabBarContentModifier,
+ modifier = Modifier.fillMaxHeight()
+ )
+ }
+
+ searchBarContent(
+ Modifier
+ .weight(1f)
+ .fillMaxHeight()
+ // Same "standaloneTab" key as ExpandedStandaloneTab/InlineStandaloneTab
+ // (the search circle) — without this the circle just pops out and the
+ // bar pops in as two unrelated fades instead of one smoothly growing
+ // pill; this is what makes the tab-group icon side already morph
+ // smoothly, and lets the search-inline (scrolled) state morph back
+ // down to a circle too.
+ .sharedElement(
+ sharedContentState = rememberSharedContentState("standaloneTab"),
+ animatedVisibilityScope = animatedVisibilityScope,
+ zIndexInOverlay = 1f
+ )
+ .shadow(shape = shapes.tabBarShape, elevation = elevations.expandedElevation)
+ .background(color = colors.backgroundColor, shape = shapes.tabBarShape)
+ .clip(shapes.tabBarShape)
+ .then(tabBarContentModifier)
+ )
+ }
+ }
+}
+
+@Composable
+private fun SharedTransitionScope.ExpandedStandaloneTab(
+ standaloneTab: FloatingTabBarTab,
+ shapes: FloatingTabBarShapes,
+ sizes: FloatingTabBarSizes,
+ colors: FloatingTabBarColors,
+ elevations: FloatingTabBarElevations,
+ animatedVisibilityScope: AnimatedVisibilityScope,
+ modifier: Modifier,
+ tabBarContentModifier: Modifier
+) {
+ // Same finger-tracking glow as the keyboard-active search pill
+ // (NavBarSearchInputBar) — a soft radial light following the touch point.
+ val glowScope = rememberCoroutineScope()
+ val glow = remember(glowScope) { InteractiveHighlight(animationScope = glowScope) }
+
+ Tab(
+ icon = standaloneTab.icon,
+ title = standaloneTab.title,
+ isInline = true,
+ isStandalone = true,
+ modifier = modifier
+ .sharedElement(
+ sharedContentState = rememberSharedContentState("standaloneTab"),
+ animatedVisibilityScope = animatedVisibilityScope,
+ zIndexInOverlay = 1f
+ )
+ .shadow(
+ shape = shapes.standaloneTabShape,
+ elevation = elevations.expandedElevation
+ )
+ .background(
+ color = colors.backgroundColor,
+ shape = shapes.standaloneTabShape
+ )
+ .clip(shapes.standaloneTabShape)
+ .then(tabBarContentModifier)
+ .then(glow.gestureModifier)
+ .then(glow.modifier)
+ .tapClickable(
+ indication = standaloneTab.indication?.invoke(),
+ onClick = standaloneTab.onClick
+ )
+ // Unlike the regular tab pill (ExpandedTabs), this circle had no inset
+ // at all — the icon sat flush against its edge.
+ .padding(sizes.tabExpandedContentPadding)
+ )
+}
+
+@Composable
+private fun SharedTransitionScope.ExpandedAccessory(
+ accessory: @Composable SharedTransitionScope.(Modifier, AnimatedVisibilityScope) -> Unit,
+ isAccessoryShared: Boolean,
+ colors: FloatingTabBarColors,
+ shapes: FloatingTabBarShapes,
+ elevations: FloatingTabBarElevations,
+ animatedVisibilityScope: AnimatedVisibilityScope,
+ modifier: Modifier
+) {
+ Box(
+ modifier = modifier
+ .then(
+ if (isAccessoryShared) {
+ Modifier.sharedElement(
+ sharedContentState = rememberSharedContentState("accessory"),
+ animatedVisibilityScope = animatedVisibilityScope
+ )
+ } else {
+ Modifier.animateEnterExitAccessory(
+ sharedTransitionScope = this,
+ animatedVisibilityScope = animatedVisibilityScope
+ )
+ }
+ )
+ ) {
+ accessory(
+ Modifier
+ .shadow(
+ shape = shapes.accessoryShape,
+ elevation = elevations.expandedElevation
+ )
+ .background(color = colors.accessoryBackgroundColor, shapes.accessoryShape)
+ .clip(shapes.accessoryShape),
+ animatedVisibilityScope
+ )
+ }
+}
+@Composable
+private fun SharedTransitionScope.ExpandedTabs(
+ scope: FloatingTabBarScopeImpl,
+ selectedTabKey: Any?,
+ shapes: FloatingTabBarShapes,
+ sizes: FloatingTabBarSizes,
+ colors: FloatingTabBarColors,
+ elevations: FloatingTabBarElevations,
+ animatedVisibilityScope: AnimatedVisibilityScope,
+ modifier: Modifier,
+ tabBarContentModifier: Modifier,
+ backdrop: Backdrop?,
+ accentColor: Color
+) {
+ // The standalone tab (e.g. search) never appears here — it's always its
+ // own floating circle, rendered as a sibling by ExpandedBar (see
+ // ExpandedStandaloneTab). Only the regular tabs form this pill/puck group.
+ val allTabs = scope.tabs
+ val tabsCount = allTabs.size
+ if (tabsCount == 0) return
+ // dampedDragAnimation is remember(...)-ed and its onDragStopped closure would
+ // otherwise capture the FIRST composition's allTabs — freezing each tab's
+ // onClick (and the isSelected it closed over). That stranded drag-to-Home:
+ // Home started selected, so its frozen onClick did scroll-to-top forever
+ // instead of navigating. Read the live tabs through this instead.
+ val currentTabs = rememberUpdatedState(allTabs)
+
+ val density = LocalDensity.current
+ val layoutDirection = LocalLayoutDirection.current
+ val isLtr = layoutDirection == LayoutDirection.Ltr
+ val animationScope = rememberCoroutineScope()
+ val glassConfig = LocalGlassEffectConfig.current
+ // Puck wash. Unset follows the theme rather than assuming a dark bar: a light
+ // scheme gets a light wash, so the pill still reads as a raised surface instead
+ // of a black patch.
+ val puckWash = if (glassConfig.puckColor.isSpecified) {
+ glassConfig.puckColor
+ } else if (MaterialTheme.colorScheme.surface.luminance() > 0.5f) {
+ Color(0xFFF2F2F2)
+ } else {
+ Color(28, 27, 28)
+ }
+ val puckRestAlpha = glassConfig.puckOpacity.coerceIn(0f, 1f)
+
+ val tabWidthPx = with(density) { sizes.tabWidth.toPx() }
+ // The row's own content padding insets the tabs from the pill's edges, so
+ // the puck (a sibling, not a row child) has to account for it explicitly —
+ // otherwise it drifts out of alignment with where the tabs actually sit.
+ val paddingStartPx = with(density) { sizes.tabBarContentPadding.calculateStartPadding(layoutDirection).toPx() }
+ val paddingEndPx = with(density) { sizes.tabBarContentPadding.calculateEndPadding(layoutDirection).toPx() }
+ val totalWidthPx = tabWidthPx * tabsCount + paddingStartPx + paddingEndPx
+
+ // Ported from LiquidBottomTabs: the whole pill nudges a few dp in the drag
+ // direction (eased, clamped) so it feels like it's being tugged, not just
+ // the puck sliding inside a static shell.
+ val offsetAnimation = remember(tabsCount) { Animatable(0f) }
+ val panelOffset by remember(density, totalWidthPx) {
+ derivedStateOf {
+ val fraction = (offsetAnimation.value / totalWidthPx).fastCoerceIn(-1f, 1f)
+ with(density) {
+ 4f.dp.toPx() * fraction.sign * EaseOut.transform(abs(fraction))
+ }
+ }
+ }
+
+ var currentIndex by remember(tabsCount) {
+ mutableIntStateOf(
+ allTabs.indexOfFirst { it.key == selectedTabKey }.coerceIn(0, tabsCount - 1)
+ )
+ }
+ // Matches Kyant's LiquidBottomTabs behavior exactly: navigation fires ONLY
+ // in onDragStopped (finger lifted, puck settling onto its target) — never
+ // mid-drag. An earlier "predictive fire" here navigated while the puck was
+ // still being dragged, which opened screens before the drop.
+ // inspectDragGestures (vendored) fires onDragStart/onDrag/onDragEnd for a
+ // plain tap-through too, with zero net movement, and never consumes the
+ // touch — so a tap that lands on the puck while it's mid-sweep between
+ // two tabs would otherwise re-navigate to targetValue (the sweep's
+ // destination) on top of whatever the tapped tab's own tapClickable just
+ // navigated to. Gate the puck's own navigate-on-release to genuine drags.
+ var hasDraggedPuck = false
+ val dampedDragAnimation = remember(animationScope, tabsCount) {
+ DampedDragAnimation(
+ animationScope = animationScope,
+ initialValue = currentIndex.toFloat(),
+ valueRange = 0f..(tabsCount - 1).toFloat(),
+ visibilityThreshold = 0.001f,
+ initialScale = 1f,
+ // Matches LiquidBottomTabs' literal ratio (78dp/56dp) rather than a
+ // fraction of our own tab width — a proportional scale factor, not
+ // an absolute size, so it should track the source value directly.
+ pressedScale = 78f / 56f,
+ onDragStarted = { hasDraggedPuck = false },
+ onDragStopped = {
+ val targetIndex = targetValue.fastRoundToInt().coerceIn(0, tabsCount - 1)
+ currentIndex = targetIndex
+ // updateValue (not animateToValue): the modifier's own
+ // onDragStart/onDragEnd already own the press-grow + release
+ // shrink. animateToValue pressed a SECOND time and, worse, ran
+ // under mutatorMutex — a later sync could cancel it mid-settle
+ // and strand the puck at the old index (puck stuck on Home while
+ // a different screen is showing). updateValue just springs the
+ // position, no press, no mutex.
+ updateValue(targetIndex.toFloat())
+ animationScope.launch {
+ offsetAnimation.animateTo(0f, spring(1f, 300f, 0.5f))
+ }
+ if (hasDraggedPuck) {
+ currentTabs.value.getOrNull(targetIndex)?.onClick?.invoke()
+ }
+ },
+ onDrag = { _, dragAmount ->
+ if (dragAmount != Offset.Zero) hasDraggedPuck = true
+ updateValue(
+ (targetValue + dragAmount.x / tabWidthPx * if (isLtr) 1f else -1f)
+ .fastCoerceIn(0f, (tabsCount - 1).toFloat())
+ )
+ animationScope.launch {
+ offsetAnimation.snapTo(offsetAnimation.value + dragAmount.x)
+ }
+ },
+ // Critically damped, so the stretch tracks the drag instead of ringing
+ // after it: the library's underdamped default is what made the puck
+ // wobble as it crossed each tab.
+ )
+ }
+ // False until this bar has run its selection sync once. Expanding back from
+ // inline builds a brand new ExpandedBar (it is its own AnimatedContent
+ // branch), so everything here re-remembers and this effect fires on first
+ // composition — with the puck ALREADY on the right tab, because
+ // dampedDragAnimation starts at currentIndex. animateToValue would then
+ // press-grow and release the puck without moving it anywhere, launched into a
+ // coroutine under mutatorMutex so it lands a frame or two into the crossfade:
+ // the indicator appears to pop in late and twitch. On that first pass the
+ // position is already correct, so there is nothing to animate.
+ var hasSyncedSelection by remember(tabsCount) { mutableStateOf(false) }
+ // Keeps the puck synced when selection changes from a tap (or external
+ // navigation) rather than a drag on this bar.
+ LaunchedEffect(selectedTabKey, tabsCount) {
+ val index = allTabs.indexOfFirst { it.key == selectedTabKey }
+ if (index != -1) {
+ currentIndex = index
+ if (!hasSyncedSelection) {
+ hasSyncedSelection = true
+ // Pin without the press animation; already in the right place.
+ dampedDragAnimation.updateValue(index.toFloat())
+ return@LaunchedEffect
+ }
+ // Re-pin on EVERY selection change, not only when currentIndex differs:
+ // the puck's animated value can drift out from under a matching currentIndex
+ // (a cancelled drag, an interrupted settle) and strand the indicator on the
+ // wrong tab — the "selected icon doesn't update" bug. Forcing this here
+ // always snaps it back to the actually-selected route.
+ //
+ // animateToValue (not updateValue): a tap should feel like a drag-release —
+ // the same press/grow-then-settle the puck does when you actually drag it,
+ // not just a bare position slide. This used to fall back to updateValue
+ // because animateToValue's press-grow visibly doubled the selected icon
+ // against the puck's glass copy — that's fixed now (the hidden backdrop row's
+ // contentScale and padding are kept in sync with the visible row, see above).
+ dampedDragAnimation.animateToValue(index.toFloat())
+ }
+ }
+
+ val interactiveHighlight = remember(animationScope) {
+ InteractiveHighlight(
+ animationScope = animationScope,
+ position = { size, offset ->
+ Offset(
+ if (isLtr) paddingStartPx + (dampedDragAnimation.value + 0.5f) * tabWidthPx + panelOffset
+ else size.width - paddingStartPx - (dampedDragAnimation.value + 0.5f) * tabWidthPx + panelOffset,
+ size.height / 2f
+ )
+ }
+ )
+ }
+
+ // Invisible tinted copy of the tabs, sampled by the puck below so the
+ // selected icon shows through the glass in the accent color.
+ val tabsBackdrop = rememberLayerBackdrop()
+ // Whether the accent-tinted copy of the tabs is worth keeping alive; see
+ // where it is composed below.
+ val tabsTinted = dampedDragAnimation.pressProgress > 0f
+
+ Box(modifier.width(with(density) { totalWidthPx.toDp() })) {
+ Row(
+ Modifier
+ .fillMaxSize()
+ .graphicsLayer { translationX = panelOffset }
+ .sharedElement(
+ sharedContentState = rememberSharedContentState("tabGroup"),
+ animatedVisibilityScope = animatedVisibilityScope,
+ zIndexInOverlay = 1f
+ )
+ .shadow(
+ shape = shapes.tabBarShape,
+ elevation = elevations.expandedElevation
+ )
+ .background(
+ color = colors.backgroundColor,
+ shape = shapes.tabBarShape
+ )
+ .clip(shapes.tabBarShape)
+ .then(tabBarContentModifier)
+ .then(interactiveHighlight.modifier)
+ .padding(sizes.tabBarContentPadding),
+ horizontalArrangement = Arrangement.spacedBy(sizes.tabSpacing)
+ ) {
+ allTabs.forEachIndexed { index, tab ->
+ Tab(
+ icon = {
+ Box(
+ modifier = Modifier
+ .graphicsLayer {
+ // Unselected tabs sit back; the selected one is
+ // never dimmed, so the puck must not darken it.
+ alpha = if (tab.key == selectedTabKey) 1f else 0.6f
+ }
+ .then(
+ if (tab.key == selectedTabKey) {
+ Modifier.sharedElement(
+ sharedContentState = rememberSharedContentState("tab#${tab.key}-icon"),
+ animatedVisibilityScope = animatedVisibilityScope,
+ zIndexInOverlay = 1f
+ )
+ } else {
+ Modifier.animateEnterExitTab(
+ sharedTransitionScope = this@ExpandedTabs,
+ animatedVisibilityScope = animatedVisibilityScope
+ )
+ }
+ )
+ ) {
+ tab.icon()
+ }
+ },
+ title = {
+ Box(
+ Modifier.animateEnterExitTab(
+ sharedTransitionScope = this@ExpandedTabs,
+ animatedVisibilityScope = animatedVisibilityScope
+ )
+ ) {
+ tab.title()
+ }
+ },
+ isInline = false,
+ isStandalone = false,
+ contentScale = if (index == currentIndex) {
+ lerp(1f, 1.12f, dampedDragAnimation.pressProgress)
+ } else {
+ 1f
+ },
+ modifier = Modifier
+ .weight(1f)
+ .fillMaxHeight()
+ .skipToLookaheadSize()
+ .clip(shapes.tabShape)
+ .tapClickable(
+ indication = tab.indication?.invoke(),
+ onClick = tab.onClick
+ )
+ .padding(sizes.tabExpandedContentPadding)
+ )
+ }
+ }
+
+ // LOCAL CHANGE: only while the puck is being touched.
+ //
+ // This is a second, invisible copy of the whole tab row, kept so the
+ // selected icon can show through the puck's glass in the accent colour.
+ // It is also a full row composed, measured and recorded into a layer for
+ // every frame the bar is on screen, which is every frame of every scroll:
+ // measured at 8ms a frame on the home page, for a tint that only exists
+ // while a finger is on the puck. Composed when that happens instead.
+ if (backdrop != null && tabsTinted) {
+ // Fixed 1dp blur here (see the blur() call below), so this is a
+ // stable fraction, not something that needs recomputing per frame.
+ val tabsBackdropScale = glassResolutionScale(1f)
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .clearAndSetSemantics {}
+ .alpha(0f)
+ .layerBackdrop(tabsBackdrop)
+ .graphicsLayer { translationX = panelOffset }
+ // Padding here (not after drawBackdrop, like the tail
+ // .padding below) so it actually shrinks this row's own
+ // measured bounds — matching LiquidBottomTabs' explicit
+ // .height(56dp) vs the main row's 64dp: what tabsBackdrop
+ // captures needs to be genuinely inset, not full-bleed.
+ .padding(sizes.tabBarContentPadding)
+ // Ported from LiquidBottomTabs: this hidden row isn't just a
+ // tinted icon cutout, it's a real blurred/lensed glass sample
+ // of the screen behind the bar — that's what makes the puck
+ // below look like it's made of the *bar's* frosted material
+ // (not a flat color) when it slides underneath.
+ .drawBackdrop(
+ backdrop = backdrop,
+ shape = { shapes.tabBarShape },
+ effects = {
+ val progress = dampedDragAnimation.pressProgress
+ vibrancy()
+ // Without any blur here, this hidden row's lens()
+ // distortion (below) samples the raw, sharp backdrop —
+ // that's what made the puck look like undistorted,
+ // "blur gone" background while dragging. Kyant's source
+ // uses a fixed 8dp; we drive it from the user's own
+ // glass blur-intensity setting instead of hardcoding.
+ blur(glassConfig.blurRadius.dp.toPx() * tabsBackdropScale)
+ lens(
+ 15f.dp.toPx() * progress * tabsBackdropScale,
+ 18f.dp.toPx() * progress * tabsBackdropScale
+ )
+ },
+ highlight = {
+ val progress = dampedDragAnimation.pressProgress
+ Highlight.Default.copy(alpha = progress)
+ },
+ onDrawSurface = { drawRect(colors.backgroundColor) },
+ backdropScale = tabsBackdropScale,
+ frozen = LocalTabBarBackdropFrozen.current,
+ // Same GPU-saving trick as Modifier.liquidGlass: record this
+ // hidden row at a fraction of surface resolution and let the
+ // blur hide the upscale — was left at the 1f (full-res)
+ // default here even though liquidGlass already uses this.
+ )
+ .then(interactiveHighlight.modifier)
+ // NOT a second .padding(sizes.tabBarContentPadding) here — the one
+ // above (before drawBackdrop) already insets this row's measured
+ // bounds. A second one compounded the inset only on this hidden
+ // row (the visible row above applies it exactly once), shifting
+ // its tabs right of their real counterparts — the puck's sampled
+ // icon then visibly drifted from the real icon under it.
+ .graphicsLayer(colorFilter = ColorFilter.tint(accentColor)),
+ horizontalArrangement = Arrangement.spacedBy(sizes.tabSpacing)
+ ) {
+ allTabs.forEachIndexed { index, tab ->
+ Tab(
+ icon = tab.icon,
+ title = tab.title,
+ isInline = false,
+ isStandalone = false,
+ // Must match the visible row's per-tab contentScale (see
+ // above) — this hidden row is what the puck's glass samples,
+ // so if it doesn't zoom in sync with the real icon during a
+ // press/drag, the accent-tinted copy visibly drifts from the
+ // real icon on top, reading as a ghosted double image.
+ contentScale = if (index == currentIndex) {
+ lerp(1f, 1.12f, dampedDragAnimation.pressProgress)
+ } else {
+ 1f
+ },
+ modifier = Modifier
+ .weight(1f)
+ .fillMaxHeight()
+ // Must match the visible row's skipToLookaheadSize() too
+ // (see below) — without it this hidden row can measure a
+ // hair differently under the shared-transition lookahead
+ // pass, leaving the puck's sampled icon slightly off from
+ // the real one even at rest.
+ .skipToLookaheadSize()
+ .padding(sizes.tabExpandedContentPadding)
+ )
+ }
+ }
+ }
+
+ // The draggable selection puck. Position and press/velocity-driven
+ // scale come from dampedDragAnimation; tapping a tab still works via
+ // each tab's own clickable — the puck only intercepts drags.
+ //
+ // LOCAL CHANGE: it grows in with the tabs it belongs to. The tab group is
+ // a shared element and travels between the two states; the puck is not
+ // part of it, so coming back from the folded bar it simply appeared,
+ // final size and full strength, over tabs that were still on their way.
+ //
+ // A fade alone was not enough to fix that, and it is worth saying why: at
+ // 160ms over a fold that takes twice as long, what you see is a
+ // fully-formed puck arriving early and quickly — which is the same
+ // complaint. It has to be the same length as the movement it belongs to,
+ // and it has to move: the scale is what makes it read as the puck
+ // settling onto the tab rather than being switched on there.
+ // Driven from this composable's own first frame rather than from the
+ // enter transition, which was the second wrong answer here and is worth
+ // recording. Hung off `animatedVisibilityScope.transition`, the animation
+ // starts at whatever the transition already is — and by the time the
+ // expanded bar composes its puck, the transition has usually moved on, so
+ // the value began at 1 and nothing animated at all. An Animatable started
+ // on composition cannot miss its own beginning.
+ val puckEnter = remember { Animatable(0f) }
+ LaunchedEffect(Unit) {
+ puckEnter.animateTo(1f, tween(durationMillis = PuckEnterMs, easing = FastOutSlowInEasing))
+ }
+ // See the `frozen` argument below: the puck may only hold a capture once
+ // it has one. A lambda so flipping it costs no recomposition — the glass
+ // asks during draw.
+ val tabBarFrozen = LocalTabBarBackdropFrozen.current
+ val puckFrozen = remember(tabBarFrozen, puckEnter) {
+ { tabBarFrozen() && puckEnter.value >= 1f }
+ }
+ Box(
+ Modifier
+ .padding(sizes.tabBarContentPadding)
+ // NOT rendered in the shared transition overlay, though the tab
+ // row above it is, and that is why the indicator only becomes
+ // visible when the unfold ends: for the frames of the transition
+ // the row is drawn in the overlay, over everything else in the
+ // layout, and the puck fades in underneath it. Putting the puck
+ // in the overlay too is the obvious answer and was tried: the
+ // overlay positions it in its own coordinates, so it left the bar
+ // entirely and sat lit up over the mini player. Left as it is,
+ // rather than half-fixed.
+ .graphicsLayer {
+ val enter = puckEnter.value
+ alpha = enter
+ val enterScale = lerp(PuckEnterScale, 1f, enter)
+ scaleX = enterScale
+ scaleY = enterScale
+ translationX =
+ if (isLtr) dampedDragAnimation.value * tabWidthPx + panelOffset
+ else size.width - (dampedDragAnimation.value + 1f) * tabWidthPx + panelOffset
+ }
+ .then(interactiveHighlight.gestureModifier)
+ .then(dampedDragAnimation.modifier)
+ .width(sizes.tabWidth)
+ .fillMaxHeight()
+ // The puck's shape in plain paint, under the glass, while it is
+ // arriving. Fading a pane of glass in is fading in something that
+ // has nothing to show yet: a backdrop-sampling surface has no
+ // capture on its first frames, so for the length of the entrance
+ // the animation was running over an empty pill and the puck still
+ // looked like it appeared all at once, at the end. This is what
+ // grows into place; the glass takes over from underneath it as
+ // soon as it has something to refract, and both draw the same
+ // wash, so the hand-over is not a change of colour.
+ .drawBehind {
+ val enter = puckEnter.value
+ if (enter < 1f) {
+ drawOutline(
+ shapes.tabShape.createOutline(size, layoutDirection, this),
+ color = puckWash.copy(alpha = puckRestAlpha * (1f - enter)),
+ )
+ }
+ }
+ .then(
+ if (backdrop != null) {
+ Modifier.drawBackdrop(
+ // Only combined while the hidden row above exists.
+ // An empty layer has no version for the surface to
+ // compare against, so sampling one makes the puck
+ // re-record the screen on every single frame — which
+ // is worse than the row it was meant to save.
+ backdrop = rememberCombinedBackdrop(backdrop, tabsBackdrop)
+ .takeIf { tabsTinted } ?: backdrop,
+ shape = { shapes.tabShape },
+ effects = {
+ val progress = dampedDragAnimation.pressProgress
+ // Soft frosted puck at rest (constant blur), deepening
+ //
+ blur(3f.dp.toPx() * (1f - progress))
+
+ // Refraction is weakest at REST and deepens while the
+ // puck is held and dragged: at rest the sharp overlay
+ // icon sits on top at full alpha, and any real bend
+ // there splits it from its lensed copy underneath —
+ // the doubled/ghosted icon. That overlay fades out
+ // over the first third of the press ramp, so by the
+ // time the bend is at full strength there is only one
+ // copy left to warp.
+ lens(
+ lerp(0f.dp.toPx(), 10f.dp.toPx(), progress),
+ lerp(0f.dp.toPx(), 12f.dp.toPx(), progress),
+ // Dispersion is a drag-only flourish. It costs a
+ // second, heavier shader, so a puck sitting still
+ // should not be paying for it.
+ chromaticAberration = progress > 0.01f
+ )
+ },
+ highlight = {
+ val progress = dampedDragAnimation.pressProgress
+ // Floored, not 0-at-rest. With no rim the puck's
+ // shape came entirely from its dark wash below,
+ // so it vanished into the bar whenever the bar
+ // itself sat on dark content. A specular rim
+ // reads against light AND dark, and unlike
+ // lightening the wash it leaves the selected
+ // icon (white by default, drawn on top) legible.
+ Highlight.Default.copy(
+ alpha = lerp(PuckRestHighlightAlpha, 1f, progress)
+ )
+ },
+ shadow = {
+ val progress = dampedDragAnimation.pressProgress
+ // Same reasoning: a little separation at rest so
+ // the puck reads as a raised element rather than
+ // a flat patch of the bar.
+ Shadow(alpha = lerp(PuckRestShadowAlpha, 1f, progress))
+ },
+ innerShadow = {
+ val progress = dampedDragAnimation.pressProgress
+ InnerShadow(radius = 8f.dp * progress, alpha = progress)
+ },
+ layerBlock = {
+ scaleX = dampedDragAnimation.scaleX
+ scaleY = dampedDragAnimation.scaleY
+ val velocity = dampedDragAnimation.velocity / 10f
+ scaleX /= 1f - (velocity * 0.75f).fastCoerceIn(-0.2f, 0.2f)
+ scaleY *= 1f - (velocity * 0.25f).fastCoerceIn(-0.2f, 0.2f)
+ },
+ onDrawSurface = {
+ // What shows inside the puck is the hidden tinted tab
+ // row sampled back through this glass, so anything
+ // painted here lands ON TOP of the selected icon.
+ // Black at any real strength crushes it — hence an
+ // accent wash that defines the pill's shape while
+ // leaving the icon at full strength, deepening only
+ // while pressed.
+ val progress = dampedDragAnimation.pressProgress
+
+ // Was a hardcoded near-black at 0.8 alpha, which on a
+ // dark bar made the whole puck read as a dark blob and
+ // on a light theme was simply wrong. Colour and resting
+ // opacity are configurable now, and the unset default
+ // follows the theme instead of assuming dark.
+ drawRect(puckWash.copy(alpha = puckRestAlpha * (1f - 0.75f * progress)))
+ },
+ // LOCAL CHANGE, and this is what actually made the
+ // indicator appear out of nowhere. Freezing tells a
+ // surface to reuse its last capture instead of
+ // re-recording the screen while its bounds animate —
+ // which is right for the bar, and wrong for the puck:
+ // the puck does not exist while the bar is folded, so
+ // for the whole of the unfold it was reusing a capture
+ // it had never taken, and drew nothing at all. It
+ // arrived the instant the transition ended and the
+ // freeze lifted, at full strength, on the frame after
+ // everything else had finished moving. So it records
+ // for the frames it is arriving on, and freezes with
+ // the rest of the bar once it is there.
+ frozen = puckFrozen,
+ )
+ } else {
+ Modifier
+ .graphicsLayer {
+ scaleX = dampedDragAnimation.scaleX
+ scaleY = dampedDragAnimation.scaleY
+ }
+ .shadow(
+ shape = shapes.tabShape,
+ elevation = elevations.expandedElevation * dampedDragAnimation.pressProgress
+ )
+ .background(
+ colors.backgroundColor.copy(
+ alpha = 0.5f + 0.5f * dampedDragAnimation.pressProgress
+ ),
+ shapes.tabShape
+ )
+ .clip(shapes.tabShape)
+ }
+ )
+ )
+
+ // The selected icon, drawn a second time above the puck.
+ //
+ // What shows *through* the puck is the hidden accent-tinted tab row
+ // refracted by the glass, and the puck's surface tint necessarily paints
+ // over it — so that copy can never be at full opacity. Redrawing the icon
+ // here is the only way to keep it crisp.
+ //
+ // It rides the puck's own translation and squash, so the two cannot drift
+ // apart mid-drag, and it always covers the dimmed copy underneath rather
+ // than ghosting beside it. Which icon to draw is derived state, so this
+ // recomposes when the puck crosses into a new tab, not every frame.
+ val puckIndex by remember(tabsCount) {
+ derivedStateOf {
+ dampedDragAnimation.value
+ .fastRoundToInt()
+ .coerceIn(0, (tabsCount - 1).coerceAtLeast(0))
+ }
+ }
+ Box(
+ Modifier
+ .padding(sizes.tabBarContentPadding)
+ .graphicsLayer {
+ translationX =
+ if (isLtr) dampedDragAnimation.value * tabWidthPx + panelOffset
+ else size.width - (dampedDragAnimation.value + 1f) * tabWidthPx + panelOffset
+ scaleX = dampedDragAnimation.scaleX
+ scaleY = dampedDragAnimation.scaleY
+ // Settled state only. Fades roughly three times faster than the
+ // press ramp, so it is fully gone a third of the way into the
+ // gesture instead of lingering over the moving puck. Read in the
+ // draw phase, so it costs no recomposition.
+ alpha = (1f - dampedDragAnimation.pressProgress * 3f).fastCoerceIn(0f, 1f)
+ }
+ .width(sizes.tabWidth)
+ .fillMaxHeight()
+ // Purely decorative: the tab underneath keeps the click and the
+ // semantics, and this must never swallow either.
+ .clearAndSetSemantics {},
+ ) {
+ currentTabs.value.getOrNull(puckIndex)?.let { tab ->
+ // Must go through Tab, not just tab.icon(): Tab is a Column of
+ // icon THEN title, so drawing the icon alone centres it on the
+ // puck while the row centres it on the icon+title pair — which is
+ // exactly how far off it looked. Same props as the row's selected
+ // tab, so the two line up.
+ Tab(
+ // No tint override: the icon keeps the selected colour its
+ // caller gave it, which is the point of drawing it again.
+ icon = { tab.icon() },
+ title = { tab.title() },
+ isInline = false,
+ isStandalone = false,
+ // No press zoom: only visible at rest, where the row's own lerp
+ // lands on 1f. Leaving it out also stops the overlay recomposing
+ // on every frame of a drag.
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(sizes.tabExpandedContentPadding),
+ )
+ }
+ }
+ }
+}
+
+@Composable
+private fun Tab(
+ icon: @Composable () -> Unit,
+ title: @Composable () -> Unit,
+ isInline: Boolean,
+ modifier: Modifier = Modifier,
+ isStandalone: Boolean = false,
+ // Vendored addition: press-zoom scale for the icon+label, driven by the
+ // drag puck's press progress (Kyant's LocalLiquidBottomTabScale trick).
+ contentScale: Float = 1f
+) {
+ val showTitle = !isStandalone && !isInline
+ Column(
+ // A real gap between icon and title, centered as a group — rather than
+ // nudging the icon down with a raw offset(), which shifts its drawn
+ // position without growing the Column's measured height and gets it
+ // clipped by the tab bar's own bounds.
+ verticalArrangement = if (showTitle) {
+ Arrangement.spacedBy((-2).dp, Alignment.CenterVertically)
+ } else {
+ Arrangement.Center
+ },
+ horizontalAlignment = Alignment.CenterHorizontally,
+ modifier = modifier
+ .then(
+ if (contentScale != 1f) {
+ Modifier.graphicsLayer {
+ scaleX = contentScale
+ scaleY = contentScale
+ }
+ } else {
+ Modifier
+ }
+ )
+ ) {
+ icon()
+ if (showTitle) {
+ title()
+ }
+ }
+}
+
+/**
+ * A custom modifier that provides smooth enter/exit animations without clipping shadows or other content.
+ * This is an alternative to animateEnterExit that uses renderInSharedTransitionScopeOverlay to prevent clipping.
+ */
+@Composable
+private fun Modifier.animateEnterExitAccessory(
+ sharedTransitionScope: SharedTransitionScope,
+ animatedVisibilityScope: AnimatedVisibilityScope
+): Modifier = with(sharedTransitionScope) {
+ with(animatedVisibilityScope) {
+ val animatedAlpha by transition.animateFloat { targetState ->
+ when (targetState) {
+ EnterExitState.Visible -> 1f
+ else -> 0f
+ }
+ }
+
+ this@animateEnterExitAccessory
+ .renderInSharedTransitionScopeOverlay()
+ .graphicsLayer(
+ compositingStrategy = CompositingStrategy.ModulateAlpha,
+ alpha = animatedAlpha
+ )
+ }
+}
+
+/**
+ * A custom modifier that provides smooth enter/exit animations with fade and blur effects.
+ */
+@Composable
+private fun Modifier.animateEnterExitTab(
+ sharedTransitionScope: SharedTransitionScope,
+ animatedVisibilityScope: AnimatedVisibilityScope
+): Modifier = with(sharedTransitionScope) {
+ with(animatedVisibilityScope) {
+ val enterStartFraction = 0.5f
+ val enterEndFraction = 0.8f
+ val durationMs = 150
+
+ val animatedAlpha by transition.animateFloat(
+ transitionSpec = {
+ keyframes {
+ durationMillis = durationMs
+ if (targetState == EnterExitState.Visible) {
+ 0f atFraction enterStartFraction using FastOutSlowInEasing
+ 1f atFraction enterEndFraction
+ }
+ }
+ }
+ ) { targetState ->
+ when (targetState) {
+ EnterExitState.Visible -> 1f
+ else -> 0f
+ }
+ }
+
+ val blurRadius = with(LocalDensity.current) { 50.dp.toPx() }
+ val animatedBlur by transition.animateFloat(
+ transitionSpec = {
+ keyframes {
+ durationMillis = durationMs
+ if (targetState == EnterExitState.Visible) {
+ blurRadius atFraction enterStartFraction using FastOutSlowInEasing
+ 0f atFraction enterEndFraction
+ }
+ }
+ }
+ ) { targetState ->
+ when (targetState) {
+ EnterExitState.Visible -> 0f
+ else -> blurRadius
+ }
+ }
+
+ graphicsLayer {
+ alpha = animatedAlpha
+ renderEffect = BlurEffect(
+ radiusX = animatedBlur,
+ radiusY = animatedBlur
+ )
+ }
+ }
+}
+
+private class FloatingTabBarScopeImpl : FloatingTabBarScope {
+ val tabs = mutableStateListOf<FloatingTabBarTab>()
+ var standaloneTab: FloatingTabBarTab? by mutableStateOf(null)
+ private set
+ private var inlineTab: FloatingTabBarTab? = null
+
+ fun getInlineTab(selectedTabKey: Any?): FloatingTabBarTab? {
+ // Screen-accurate: only ever report a regular tab as "the inline tab"
+ // when it's actually the current screen. selectedTabKey not matching
+ // any regular tab (e.g. currently on the standalone tab) falls back to
+ // the last regular tab that really was selected — never a hardcoded
+ // default like tabs.firstOrNull(), which would misrepresent Home as
+ // selected when the user has never actually been there.
+ val selectedTab = tabs.find { it.key == selectedTabKey }
+ if (selectedTab != null) {
+ inlineTab = selectedTab
+ return selectedTab
+ }
+ return inlineTab
+ }
+
+ override fun tab(
+ key: Any,
+ title: @Composable () -> Unit,
+ icon: @Composable () -> Unit,
+ onClick: () -> Unit,
+ indication: (@Composable () -> Indication)?
+ ) {
+ tabs.add(
+ FloatingTabBarTab(
+ key = key,
+ title = title,
+ icon = icon,
+ onClick = onClick,
+ indication = indication
+ )
+ )
+ }
+
+ override fun standaloneTab(
+ key: Any,
+ icon: @Composable () -> Unit,
+ onClick: () -> Unit,
+ indication: (@Composable () -> Indication)?,
+ title: @Composable () -> Unit
+ ) {
+ standaloneTab = FloatingTabBarTab(
+ key = key,
+ title = title,
+ icon = icon,
+ onClick = onClick,
+ indication = indication
+ )
+ }
+}
+
+private data class FloatingTabBarTab(
+ val key: Any,
+ val title: @Composable () -> Unit,
+ val icon: @Composable () -> Unit,
+ val onClick: () -> Unit,
+ val indication: (@Composable () -> Indication)?
+)
+
+/**
+ * Represents the colors used in [FloatingTabBar].
+ */
+@Immutable
+data class FloatingTabBarColors(
+ val backgroundColor: Color,
+ val accessoryBackgroundColor: Color,
+)
+
+/**
+ * Represents the shapes used in [FloatingTabBar].
+ */
+@Immutable
+data class FloatingTabBarShapes(
+ val tabBarShape: Shape,
+ val tabShape: Shape,
+ val standaloneTabShape: Shape,
+ val accessoryShape: Shape,
+)
+
+/**
+ * Represents the elevations used in [FloatingTabBar].
+ */
+@Immutable
+data class FloatingTabBarElevations(
+ val inlineElevation: Dp,
+ val expandedElevation: Dp,
+)
+
+/**
+ * Represents the sizes and spacing used in [FloatingTabBar].
+ */
+@Immutable
+data class FloatingTabBarSizes(
+ val tabBarContentPadding: PaddingValues,
+ val tabInlineContentPadding: PaddingValues,
+ val tabExpandedContentPadding: PaddingValues,
+ val componentSpacing: Dp,
+ val tabSpacing: Dp,
+ // Vendored addition: fixed width of one expanded tab slot. The drag-puck
+ // indicator needs a known per-tab width to map drag offset to tab index,
+ // so expanded tabs are equal-width instead of sized to their content.
+ val tabWidth: Dp = FloatingTabBarDefaults.TabWidth,
+)
+
+/**
+ * Contains the default values used by [FloatingTabBar].
+ */
+object FloatingTabBarDefaults {
+ /**
+ * Width of one expanded tab slot at full size. Callers that have to fit the
+ * pill plus the standalone tab into a narrow screen shrink below this — see
+ * [com.convx.music.ui.component.AppFloatingNavBar] — so it is the ceiling,
+ * not a guarantee.
+ */
+ val TabWidth: Dp = 88.dp
+
+ /**
+ * Creates a [FloatingTabBarColors] that represents the default colors used in a [FloatingTabBar].
+ *
+ * @param backgroundColor the color used for the tab bar background
+ * @param accessoryBackgroundColor the color used for the accessory background
+ */
+ @Composable
+ fun colors(
+ backgroundColor: Color = MaterialTheme.colorScheme.surfaceContainerHigh,
+ accessoryBackgroundColor: Color = MaterialTheme.colorScheme.surfaceContainerHigh,
+ ): FloatingTabBarColors = FloatingTabBarColors(
+ backgroundColor = backgroundColor,
+ accessoryBackgroundColor = accessoryBackgroundColor,
+ )
+
+ /**
+ * Creates a [FloatingTabBarShapes] that represents the default shapes used in a [FloatingTabBar].
+ *
+ * @param tabBarShape the shape used to clip the tab bar
+ * @param tabShape the shape used to clip individual tabs. Can be useful for example to control the click ripple effect shape
+ * @param standaloneTabShape the shape used to clip the standalone tab
+ * @param accessoryShape the shape used to clip the accessory container
+ */
+ @Composable
+ fun shapes(
+ // ContinuousRoundedRectangle(percent = 50) instead of RoundedCornerShape/
+ // CircleShape: same capsule/circle silhouette, but Kyant0/Capsule's
+ // continuous (superellipse) corners instead of Android's circular-arc
+ // ones — smoother, and lerp-able for the puck's drag-to-search morph.
+ tabBarShape: Shape = ContinuousRoundedRectangle(percent = 50),
+ tabShape: Shape = ContinuousRoundedRectangle(percent = 50),
+ standaloneTabShape: Shape = ContinuousRoundedRectangle(percent = 50),
+ accessoryShape: Shape = ContinuousRoundedRectangle(percent = 50),
+ ): FloatingTabBarShapes = FloatingTabBarShapes(
+ tabBarShape = tabBarShape,
+ tabShape = tabShape,
+ standaloneTabShape = standaloneTabShape,
+ accessoryShape = accessoryShape,
+ )
+
+ /**
+ * Creates a [FloatingTabBarSizes] that represents the default sizes used in a [FloatingTabBar].
+ *
+ * @param tabBarContentPadding the padding applied to the tab bar content. This also applies to the standalone tab content.
+ * @param tabInlineContentPadding the padding applied to tabs in inline state
+ * @param tabExpandedContentPadding the padding applied to tabs in expanded state
+ * @param componentSpacing the spacing between components
+ * @param tabSpacing the spacing between tabs in expanded state
+ */
+ @Composable
+ fun sizes(
+ tabBarContentPadding: PaddingValues = PaddingValues(vertical = 4.dp, horizontal = 4.dp),
+ tabInlineContentPadding: PaddingValues = PaddingValues(10.dp),
+ // horizontal was 20dp (the source lib's default for content-hugging
+ // tabs); with fixed-width tabWidth cells that ate too much of the
+ // budget and clipped labels like "Settings" — tightened to fit text.
+ tabExpandedContentPadding: PaddingValues = PaddingValues(vertical = 6.dp, horizontal = 6.dp),
+ componentSpacing: Dp = 8.dp,
+ tabSpacing: Dp = 0.dp,
+ tabWidth: Dp = TabWidth,
+ ): FloatingTabBarSizes = FloatingTabBarSizes(
+ tabBarContentPadding = tabBarContentPadding,
+ tabInlineContentPadding = tabInlineContentPadding,
+ tabExpandedContentPadding = tabExpandedContentPadding,
+ componentSpacing = componentSpacing,
+ tabSpacing = tabSpacing,
+ tabWidth = tabWidth,
+ )
+
+ /**
+ * Creates a [FloatingTabBarElevations] that represents the default elevations used in a [FloatingTabBar].
+ *
+ * @param inlineElevation the elevation used for tabs in inline state
+ * @param expandedElevation the elevation used for tabs in expanded state
+ */
+ @Composable
+ fun elevations(
+ inlineElevation: Dp = 6.dp,
+ expandedElevation: Dp = 12.dp,
+ ): FloatingTabBarElevations = FloatingTabBarElevations(
+ inlineElevation = inlineElevation,
+ expandedElevation = expandedElevation,
+ )
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/floatingtabbar/GooeyTransition.kt b/app/src/main/java/dev/lelonio/square/ui/glass/floatingtabbar/GooeyTransition.kt
new file mode 100644
index 0000000..4a8cd92
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/floatingtabbar/GooeyTransition.kt
@@ -0,0 +1,90 @@
+/*
+ * Liquid "gooey" merge/split effect for the inline↔expanded crossfade.
+ *
+ * Not ported from anywhere — Kyant0/AndroidLiquidGlass has no blob/metaball
+ * utility. This is the standard "gooey" technique (blur, then a steep alpha
+ * threshold) used by most liquid-blob UI effects: blurring bleeds nearby
+ * shapes' alpha together, and the threshold snaps it back to a crisp edge,
+ * which is what produces a connecting neck that thins and pinches off
+ * instead of a flat crossfade. Built from primitives already vendored in
+ * this app (see imports) rather than a new custom shader.
+ */
+package dev.lelonio.square.ui.glass.floatingtabbar
+
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.CompositingStrategy
+import androidx.compose.ui.graphics.RenderEffect
+import androidx.compose.ui.graphics.asComposeRenderEffect
+import androidx.compose.ui.graphics.graphicsLayer
+import dev.lelonio.square.ui.glass.backdrop.isRenderEffectSupported
+
+// Alpha (0..255 scale, matching this app's other ColorMatrix usage in
+// backdrop/effects/ColorFilter.kt) snaps from 0 to 1 across a narrow band
+// centered on 0.5 — steep enough to read as a crisp edge, not more blur.
+private const val ThresholdSlope = 10f
+private const val ThresholdMidpoint255 = 0.5f * 255f
+
+// The threshold never varies, so build the matrix filter once instead of
+// allocating an identical one on every frame of every transition.
+//
+// LOCAL CHANGE: built from the platform's own classes. Upstream reaches for
+// the backdrop library's `ColorFilterEffect`, which is internal to the
+// published artifact — visible where the library is vendored whole, not where
+// it is a dependency. The two compose the same thing: a blur with a colour
+// matrix applied after it.
+private val ThresholdColorFilter = android.graphics.ColorMatrixColorFilter(
+ android.graphics.ColorMatrix(
+ floatArrayOf(
+ 1f, 0f, 0f, 0f, 0f,
+ 0f, 1f, 0f, 0f, 0f,
+ 0f, 0f, 1f, 0f, 0f,
+ 0f, 0f, 0f, ThresholdSlope, -ThresholdSlope * ThresholdMidpoint255
+ )
+ )
+)
+
+// Radius is quantised to whole pixels before the effect is built and cached, so a
+// transition reuses one RenderEffect per distinct radius instead of allocating a
+// fresh BlurEffect + ColorMatrixColorFilter every frame. Sub-pixel blur steps are
+// not visible through an alpha threshold anyway. Bounded: the radius only ever
+// ranges over 0..GooeyPeakBlur.
+private val gooeyEffectCache = HashMap<Int, RenderEffect>()
+
+private fun gooeyRenderEffect(blurRadiusPx: Float): RenderEffect {
+ val key = blurRadiusPx.toInt()
+ return gooeyEffectCache.getOrPut(key) {
+ android.graphics.RenderEffect.createColorFilterEffect(
+ ThresholdColorFilter,
+ android.graphics.RenderEffect.createBlurEffect(
+ key.toFloat(),
+ key.toFloat(),
+ android.graphics.Shader.TileMode.DECAL,
+ ),
+ ).asComposeRenderEffect()
+ }
+}
+
+/**
+ * Composites this element into one offscreen layer and gooifies it: blurs by
+ * [blurRadiusPx], then snaps the blur back to a crisp edge via an alpha
+ * threshold. Offscreen compositing is what makes overlapping shapes' alpha
+ * bleed together *before* the threshold — two independently-filtered layers
+ * would just look like two blurred blobs with a seam, not a merged one.
+ *
+ * Zero cost at rest: when [blurRadiusPx] returns 0 (or RenderEffect isn't
+ * supported pre-API 31), this is a no-op — no offscreen layer, no filter.
+ */
+fun Modifier.gooey(blurRadiusPx: () -> Float): Modifier {
+ if (!isRenderEffectSupported()) return this
+ return this.graphicsLayer {
+ val radius = blurRadiusPx()
+ if (radius > 0f) {
+ compositingStrategy = CompositingStrategy.Offscreen
+ renderEffect = gooeyRenderEffect(radius)
+ } else {
+ compositingStrategy = CompositingStrategy.Auto
+ renderEffect = null
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/AdvancedContinuity.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/AdvancedContinuity.kt
new file mode 100644
index 0000000..9fb2d92
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/AdvancedContinuity.kt
@@ -0,0 +1,174 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/AdvancedContinuity.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes
+
+import androidx.compose.runtime.Immutable
+import androidx.compose.ui.geometry.Rect
+import androidx.compose.ui.geometry.RoundRect
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.Outline
+import dev.lelonio.square.ui.glass.shapes.core.Point
+import dev.lelonio.square.ui.glass.shapes.path.PathSegments
+import dev.lelonio.square.ui.glass.shapes.path.buildCirclePathSegments
+import dev.lelonio.square.ui.glass.shapes.path.toPath
+
+@Immutable
+abstract class AdvancedContinuity : Continuity {
+
+ protected abstract fun createStandardRoundedRectanglePathSegments(
+ width: Double,
+ height: Double,
+ topLeft: Double,
+ topRight: Double,
+ bottomRight: Double,
+ bottomLeft: Double
+ ): PathSegments
+
+ protected open fun createStandardRoundedRectangleOutline(
+ size: Size,
+ topLeft: Float,
+ topRight: Float,
+ bottomRight: Float,
+ bottomLeft: Float
+ ): Outline {
+ val path =
+ createStandardRoundedRectanglePathSegments(
+ width = size.width.toDouble(),
+ height = size.height.toDouble(),
+ topLeft = topLeft.toDouble(),
+ topRight = topRight.toDouble(),
+ bottomRight = bottomRight.toDouble(),
+ bottomLeft = bottomLeft.toDouble()
+ ).toPath()
+ return Outline.Generic(path)
+ }
+
+ protected open fun createHorizontalCapsulePathSegments(width: Double, height: Double): PathSegments {
+ val cornerRadius = width * 0.5
+ return createStandardRoundedRectanglePathSegments(
+ width = width,
+ height = height,
+ topLeft = cornerRadius,
+ topRight = cornerRadius,
+ bottomRight = cornerRadius,
+ bottomLeft = cornerRadius
+ )
+ }
+
+ protected open fun createHorizontalCapsuleOutline(size: Size): Outline {
+ val path =
+ createHorizontalCapsulePathSegments(
+ width = size.width.toDouble(),
+ height = size.height.toDouble()
+ ).toPath()
+ return Outline.Generic(path)
+ }
+
+ protected open fun createVerticalCapsulePathSegments(width: Double, height: Double): PathSegments {
+ val cornerRadius = height * 0.5
+ return createStandardRoundedRectanglePathSegments(
+ width = width,
+ height = height,
+ topLeft = cornerRadius,
+ topRight = cornerRadius,
+ bottomRight = cornerRadius,
+ bottomLeft = cornerRadius
+ )
+ }
+
+ protected open fun createVerticalCapsuleOutline(size: Size): Outline {
+ val path =
+ createVerticalCapsulePathSegments(
+ width = size.width.toDouble(),
+ height = size.height.toDouble()
+ ).toPath()
+ return Outline.Generic(path)
+ }
+
+ protected open fun createCirclePathSegments(size: Double): PathSegments {
+ val radius = size * 0.5
+ return buildCirclePathSegments(
+ center = Point(radius, radius),
+ radius = radius
+ )
+ }
+
+ protected open fun createCircleOutline(size: Float): Outline {
+ val radius = size * 0.5f
+ return Outline.Rounded(
+ RoundRect(
+ rect = Rect(0f, 0f, size, size),
+ radiusX = radius,
+ radiusY = radius
+ )
+ )
+ }
+
+ final override fun createRoundedRectanglePathSegments(
+ width: Double,
+ height: Double,
+ topLeft: Double,
+ topRight: Double,
+ bottomRight: Double,
+ bottomLeft: Double
+ ): PathSegments {
+ // capsule
+ if ((topLeft + topRight == width || topLeft + bottomLeft == height) &&
+ (topLeft == topRight && bottomRight == bottomLeft && topLeft == bottomRight)
+ ) {
+ return createCapsulePathSegments(width, height)
+ }
+
+ return createStandardRoundedRectanglePathSegments(
+ width = width,
+ height = height,
+ topLeft = topLeft,
+ topRight = topRight,
+ bottomRight = bottomRight,
+ bottomLeft = bottomLeft
+ )
+ }
+
+ final override fun createRoundedRectangleOutline(
+ size: Size,
+ topLeft: Float,
+ topRight: Float,
+ bottomRight: Float,
+ bottomLeft: Float
+ ): Outline {
+ // capsule
+ if ((topLeft + topRight == size.width || topLeft + bottomLeft == size.height) &&
+ (topLeft == topRight && bottomRight == bottomLeft && topLeft == bottomRight)
+ ) {
+ return createCapsuleOutline(size)
+ }
+
+ return createStandardRoundedRectangleOutline(
+ size = size,
+ topLeft = topLeft,
+ topRight = topRight,
+ bottomRight = bottomRight,
+ bottomLeft = bottomLeft
+ )
+ }
+
+ fun createCapsulePathSegments(width: Double, height: Double): PathSegments =
+ when {
+ width > height -> createHorizontalCapsulePathSegments(width, height)
+ width < height -> createVerticalCapsulePathSegments(width, height)
+ else -> createCirclePathSegments(width)
+ }
+
+ final override fun createCapsuleOutline(size: Size): Outline =
+ when {
+ size.width > size.height -> createHorizontalCapsuleOutline(size)
+ size.width < size.height -> createVerticalCapsuleOutline(size)
+ else -> createCircleOutline(size.width)
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/Continuity.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/Continuity.kt
new file mode 100644
index 0000000..82c6f75
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/Continuity.kt
@@ -0,0 +1,68 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/Continuity.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes
+
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.Outline
+import dev.lelonio.square.ui.glass.shapes.continuities.G2Continuity
+import dev.lelonio.square.ui.glass.shapes.path.PathSegments
+import dev.lelonio.square.ui.glass.shapes.path.toPath
+
+@Immutable
+interface Continuity {
+
+ fun createRoundedRectanglePathSegments(
+ width: Double,
+ height: Double,
+ topLeft: Double,
+ topRight: Double,
+ bottomRight: Double,
+ bottomLeft: Double
+ ): PathSegments
+
+ fun createRoundedRectangleOutline(
+ size: Size,
+ topLeft: Float,
+ topRight: Float,
+ bottomRight: Float,
+ bottomLeft: Float
+ ): Outline {
+ val path =
+ createRoundedRectanglePathSegments(
+ width = size.width.toDouble(),
+ height = size.height.toDouble(),
+ topLeft = topLeft.toDouble(),
+ topRight = topRight.toDouble(),
+ bottomRight = bottomRight.toDouble(),
+ bottomLeft = bottomLeft.toDouble()
+ ).toPath()
+ return Outline.Generic(path)
+ }
+
+ fun createCapsuleOutline(size: Size): Outline {
+ val radius = size.minDimension * 0.5f
+ return createRoundedRectangleOutline(
+ size = size,
+ topLeft = radius,
+ topRight = radius,
+ bottomRight = radius,
+ bottomLeft = radius
+ )
+ }
+
+ fun lerp(stop: Continuity, fraction: Double): Continuity
+
+ companion object {
+
+ @Stable
+ val Default: Continuity = G2Continuity()
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/ContinuousRoundedRectangle.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/ContinuousRoundedRectangle.kt
new file mode 100644
index 0000000..7d615fc
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/ContinuousRoundedRectangle.kt
@@ -0,0 +1,279 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/ContinuousRoundedRectangle.kt
+ *
+ * Vendored so the shape ships as source with this app (not published to
+ * Maven Central). Package renamed accordingly, and the AbsoluteContinuous*
+ * variants were dropped — this app only uses the LTR-aware
+ * ContinuousRoundedRectangle.
+ */
+package dev.lelonio.square.ui.glass.shapes
+
+import androidx.annotation.FloatRange
+import androidx.annotation.IntRange
+import androidx.compose.foundation.shape.CornerBasedShape
+import androidx.compose.foundation.shape.CornerSize
+import androidx.compose.foundation.shape.ZeroCornerSize
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.geometry.toRect
+import androidx.compose.ui.graphics.Outline
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.unit.LayoutDirection.Ltr
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.util.fastCoerceIn
+import kotlin.math.min
+
+@Immutable
+open class ContinuousRoundedRectangle(
+ topStart: CornerSize,
+ topEnd: CornerSize,
+ bottomEnd: CornerSize,
+ bottomStart: CornerSize,
+ open val continuity: Continuity = Continuity.Default
+) : CornerBasedShape(
+ topStart = topStart,
+ topEnd = topEnd,
+ bottomEnd = bottomEnd,
+ bottomStart = bottomStart
+) {
+
+ override fun createOutline(
+ size: Size,
+ topStart: Float,
+ topEnd: Float,
+ bottomEnd: Float,
+ bottomStart: Float,
+ layoutDirection: LayoutDirection
+ ): Outline {
+ // rectangle
+ if (topStart + topEnd + bottomEnd + bottomStart == 0f) {
+ return Outline.Rectangle(size.toRect())
+ }
+
+ val maxRadius = min(size.width, size.height) * 0.5f
+ val topLeft = (if (layoutDirection == Ltr) topStart else topEnd).fastCoerceIn(0f, maxRadius)
+ val topRight = (if (layoutDirection == Ltr) topEnd else topStart).fastCoerceIn(0f, maxRadius)
+ val bottomRight = (if (layoutDirection == Ltr) bottomEnd else bottomStart).fastCoerceIn(0f, maxRadius)
+ val bottomLeft = (if (layoutDirection == Ltr) bottomStart else bottomEnd).fastCoerceIn(0f, maxRadius)
+
+ return continuity.createRoundedRectangleOutline(
+ size = size,
+ topLeft = topLeft,
+ topRight = topRight,
+ bottomRight = bottomRight,
+ bottomLeft = bottomLeft
+ )
+ }
+
+ override fun copy(
+ topStart: CornerSize,
+ topEnd: CornerSize,
+ bottomEnd: CornerSize,
+ bottomStart: CornerSize
+ ): ContinuousRoundedRectangle {
+ return ContinuousRoundedRectangle(
+ topStart = topStart,
+ topEnd = topEnd,
+ bottomEnd = bottomEnd,
+ bottomStart = bottomStart,
+ continuity = continuity
+ )
+ }
+
+ fun copy(
+ topStart: CornerSize = this.topStart,
+ topEnd: CornerSize = this.topEnd,
+ bottomEnd: CornerSize = this.bottomEnd,
+ bottomStart: CornerSize = this.bottomStart,
+ continuity: Continuity = this.continuity
+ ): ContinuousRoundedRectangle {
+ return ContinuousRoundedRectangle(
+ topStart = topStart,
+ topEnd = topEnd,
+ bottomEnd = bottomEnd,
+ bottomStart = bottomStart,
+ continuity = continuity
+ )
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is ContinuousRoundedRectangle) return false
+
+ if (topStart != other.topStart) return false
+ if (topEnd != other.topEnd) return false
+ if (bottomEnd != other.bottomEnd) return false
+ if (bottomStart != other.bottomStart) return false
+ if (continuity != other.continuity) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ var result = topStart.hashCode()
+ result = 31 * result + topEnd.hashCode()
+ result = 31 * result + bottomEnd.hashCode()
+ result = 31 * result + bottomStart.hashCode()
+ result = 31 * result + continuity.hashCode()
+ return result
+ }
+
+ override fun toString(): String {
+ return "ContinuousRoundedRectangle(topStart=$topStart, topEnd=$topEnd, bottomEnd=$bottomEnd, " +
+ "bottomStart=$bottomStart, continuity=$continuity)"
+ }
+}
+
+@Stable
+val ContinuousRectangle: ContinuousRoundedRectangle = ContinuousRectangleImpl()
+
+@Suppress("FunctionName")
+@Stable
+fun ContinuousRectangle(continuity: Continuity = Continuity.Default): ContinuousRoundedRectangle =
+ ContinuousRectangleImpl(continuity)
+
+@Immutable
+private data class ContinuousRectangleImpl(
+ override val continuity: Continuity = Continuity.Default
+) : ContinuousRoundedRectangle(
+ topStart = ZeroCornerSize,
+ topEnd = ZeroCornerSize,
+ bottomEnd = ZeroCornerSize,
+ bottomStart = ZeroCornerSize,
+ continuity = continuity
+) {
+
+ override fun toString(): String {
+ return "ContinuousRectangle(continuity=$continuity)"
+ }
+}
+
+private val FullCornerSize = CornerSize(50)
+
+@Stable
+val ContinuousCapsule: ContinuousRoundedRectangle = ContinuousCapsule()
+
+@Suppress("FunctionName")
+@Stable
+fun ContinuousCapsule(continuity: Continuity = Continuity.Default): ContinuousRoundedRectangle =
+ ContinuousCapsuleImpl(continuity)
+
+@Immutable
+private data class ContinuousCapsuleImpl(
+ override val continuity: Continuity = Continuity.Default
+) : ContinuousRoundedRectangle(
+ topStart = FullCornerSize,
+ topEnd = FullCornerSize,
+ bottomEnd = FullCornerSize,
+ bottomStart = FullCornerSize,
+ continuity = continuity
+) {
+
+ override fun createOutline(
+ size: Size,
+ topStart: Float,
+ topEnd: Float,
+ bottomEnd: Float,
+ bottomStart: Float,
+ layoutDirection: LayoutDirection
+ ): Outline = continuity.createCapsuleOutline(size)
+
+ override fun toString(): String {
+ return "ContinuousCapsule(continuity=$continuity)"
+ }
+}
+
+@Stable
+fun ContinuousRoundedRectangle(
+ corner: CornerSize,
+ continuity: Continuity = Continuity.Default
+): ContinuousRoundedRectangle =
+ ContinuousRoundedRectangle(
+ topStart = corner,
+ topEnd = corner,
+ bottomEnd = corner,
+ bottomStart = corner,
+ continuity = continuity
+ )
+
+@Stable
+fun ContinuousRoundedRectangle(
+ size: Dp,
+ continuity: Continuity = Continuity.Default
+): ContinuousRoundedRectangle =
+ ContinuousRoundedRectangle(
+ corner = CornerSize(size),
+ continuity = continuity
+ )
+
+@Stable
+fun ContinuousRoundedRectangle(
+ @FloatRange(from = 0.0) size: Float,
+ continuity: Continuity = Continuity.Default
+): ContinuousRoundedRectangle =
+ ContinuousRoundedRectangle(
+ corner = CornerSize(size),
+ continuity = continuity
+ )
+
+@Stable
+fun ContinuousRoundedRectangle(
+ @IntRange(from = 0, to = 100) percent: Int,
+ continuity: Continuity = Continuity.Default
+): ContinuousRoundedRectangle =
+ ContinuousRoundedRectangle(
+ corner = CornerSize(percent),
+ continuity = continuity
+ )
+
+@Stable
+fun ContinuousRoundedRectangle(
+ topStart: Dp = 0f.dp,
+ topEnd: Dp = 0f.dp,
+ bottomEnd: Dp = 0f.dp,
+ bottomStart: Dp = 0f.dp,
+ continuity: Continuity = Continuity.Default
+): ContinuousRoundedRectangle =
+ ContinuousRoundedRectangle(
+ topStart = CornerSize(topStart),
+ topEnd = CornerSize(topEnd),
+ bottomEnd = CornerSize(bottomEnd),
+ bottomStart = CornerSize(bottomStart),
+ continuity = continuity
+ )
+
+@Stable
+fun ContinuousRoundedRectangle(
+ @FloatRange(from = 0.0) topStart: Float = 0f,
+ @FloatRange(from = 0.0) topEnd: Float = 0f,
+ @FloatRange(from = 0.0) bottomEnd: Float = 0f,
+ @FloatRange(from = 0.0) bottomStart: Float = 0f,
+ continuity: Continuity = Continuity.Default
+): ContinuousRoundedRectangle =
+ ContinuousRoundedRectangle(
+ topStart = CornerSize(topStart),
+ topEnd = CornerSize(topEnd),
+ bottomEnd = CornerSize(bottomEnd),
+ bottomStart = CornerSize(bottomStart),
+ continuity = continuity
+ )
+
+@Stable
+fun ContinuousRoundedRectangle(
+ @IntRange(from = 0, to = 100) topStartPercent: Int = 0,
+ @IntRange(from = 0, to = 100) topEndPercent: Int = 0,
+ @IntRange(from = 0, to = 100) bottomEndPercent: Int = 0,
+ @IntRange(from = 0, to = 100) bottomStartPercent: Int = 0,
+ continuity: Continuity = Continuity.Default
+): ContinuousRoundedRectangle =
+ ContinuousRoundedRectangle(
+ topStart = CornerSize(topStartPercent),
+ topEnd = CornerSize(topEndPercent),
+ bottomEnd = CornerSize(bottomEndPercent),
+ bottomStart = CornerSize(bottomStartPercent),
+ continuity = continuity
+ )
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/LerpContinuousRoundedRectangle.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/LerpContinuousRoundedRectangle.kt
new file mode 100644
index 0000000..075c663
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/LerpContinuousRoundedRectangle.kt
@@ -0,0 +1,59 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/LerpContinuousRoundedRectangle.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly, and the Absolute variant was dropped (unused).
+ */
+package dev.lelonio.square.ui.glass.shapes
+
+import androidx.compose.foundation.shape.CornerSize
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.util.fastCoerceAtLeast
+import androidx.compose.ui.util.lerp
+
+@Stable
+fun lerp(
+ start: ContinuousRoundedRectangle,
+ stop: ContinuousRoundedRectangle,
+ fraction: Float
+): ContinuousRoundedRectangle {
+ return LerpContinuousRoundedRectangle(start, stop, fraction)
+}
+
+@Immutable
+private data class LerpContinuousRoundedRectangle(
+ val start: ContinuousRoundedRectangle,
+ val stop: ContinuousRoundedRectangle,
+ val fraction: Float
+) : ContinuousRoundedRectangle(
+ topStart = LerpCornerSize(start.topStart, stop.topStart, fraction),
+ topEnd = LerpCornerSize(start.topEnd, stop.topEnd, fraction),
+ bottomEnd = LerpCornerSize(start.bottomEnd, stop.bottomEnd, fraction),
+ bottomStart = LerpCornerSize(start.bottomStart, stop.bottomStart, fraction),
+ continuity = when (fraction) {
+ 0f -> start.continuity
+ 1f -> stop.continuity
+ else -> start.continuity.lerp(stop.continuity, fraction.toDouble())
+ }
+)
+
+@Immutable
+private data class LerpCornerSize(
+ private val start: CornerSize,
+ private val stop: CornerSize,
+ private val fraction: Float
+) : CornerSize {
+
+ override fun toPx(shapeSize: Size, density: Density): Float {
+ return lerp(
+ start.toPx(shapeSize, density),
+ stop.toPx(shapeSize, density),
+ fraction
+ ).fastCoerceAtLeast(0f)
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/MathUtils.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/MathUtils.kt
new file mode 100644
index 0000000..1b79cca
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/MathUtils.kt
@@ -0,0 +1,14 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/MathUtils.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes
+
+@Suppress("NOTHING_TO_INLINE")
+internal inline fun lerp(start: Double, stop: Double, fraction: Double): Double {
+ return start + (stop - start) * fraction
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G0Continuity.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G0Continuity.kt
new file mode 100644
index 0000000..37e42bf
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G0Continuity.kt
@@ -0,0 +1,57 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/continuities/G0Continuity.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.continuities
+
+import androidx.compose.runtime.Immutable
+import dev.lelonio.square.ui.glass.shapes.Continuity
+import dev.lelonio.square.ui.glass.shapes.path.PathSegments
+import dev.lelonio.square.ui.glass.shapes.path.buildPathSegments
+
+@Immutable
+data object G0Continuity : Continuity {
+
+ override fun createRoundedRectanglePathSegments(
+ width: Double,
+ height: Double,
+ topLeft: Double,
+ topRight: Double,
+ bottomRight: Double,
+ bottomLeft: Double
+ ): PathSegments {
+ return buildPathSegments {
+ moveTo(0.0, topLeft)
+ if (topLeft > 0.0) {
+ lineTo(topLeft, 0.0)
+ }
+ lineTo(width - topRight, 0.0)
+ if (topRight > 0.0) {
+ lineTo(width, topRight)
+ }
+ lineTo(width, height - bottomRight)
+ if (bottomRight > 0.0) {
+ lineTo(width - bottomRight, height)
+ }
+ lineTo(bottomLeft, height)
+ if (bottomLeft > 0.0) {
+ lineTo(0.0, height - bottomLeft)
+ }
+ close()
+ }
+ }
+
+ override fun lerp(stop: Continuity, fraction: Double): Continuity {
+ return when (stop) {
+ is G0Continuity,
+ is G1Continuity,
+ is G2Continuity -> if (fraction < 0.5) this else stop
+
+ else -> stop.lerp(this, 1f - fraction)
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G1Continuity.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G1Continuity.kt
new file mode 100644
index 0000000..4c4cea5
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G1Continuity.kt
@@ -0,0 +1,105 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/continuities/G1Continuity.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.continuities
+
+import androidx.compose.runtime.Immutable
+import androidx.compose.ui.geometry.CornerRadius
+import androidx.compose.ui.geometry.Rect
+import androidx.compose.ui.geometry.RoundRect
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.Outline
+import dev.lelonio.square.ui.glass.shapes.Continuity
+import dev.lelonio.square.ui.glass.shapes.core.Point
+import dev.lelonio.square.ui.glass.shapes.path.PathSegments
+import dev.lelonio.square.ui.glass.shapes.path.buildPathSegments
+import kotlin.math.PI
+
+@Immutable
+data object G1Continuity : Continuity {
+
+ override fun createRoundedRectanglePathSegments(
+ width: Double,
+ height: Double,
+ topLeft: Double,
+ topRight: Double,
+ bottomRight: Double,
+ bottomLeft: Double
+ ): PathSegments {
+ return buildPathSegments {
+ moveTo(0.0, topLeft)
+ if (topLeft > 0.0) {
+ arcTo(
+ center = Point(topLeft, topLeft),
+ radius = topLeft,
+ startAngle = PI,
+ sweepAngle = PI * 0.5
+ )
+ }
+ lineTo(width - topRight, 0.0)
+ if (topRight > 0.0) {
+ arcTo(
+ center = Point(width - topRight, topRight),
+ radius = topRight,
+ startAngle = -PI * 0.5,
+ sweepAngle = PI * 0.5
+ )
+ }
+ lineTo(width, height - bottomRight)
+ if (bottomRight > 0.0) {
+ arcTo(
+ center = Point(width - bottomRight, height - bottomRight),
+ radius = bottomRight,
+ startAngle = 0.0,
+ sweepAngle = PI * 0.5
+ )
+ }
+ lineTo(bottomLeft, height)
+ if (bottomLeft > 0.0) {
+ arcTo(
+ center = Point(bottomLeft, height - bottomLeft),
+ radius = bottomLeft,
+ startAngle = PI * 0.5,
+ sweepAngle = PI * 0.5
+ )
+ }
+ close()
+ }
+ }
+
+ override fun createRoundedRectangleOutline(
+ size: Size,
+ topLeft: Float,
+ topRight: Float,
+ bottomRight: Float,
+ bottomLeft: Float
+ ): Outline {
+ return Outline.Rounded(
+ RoundRect(
+ rect = Rect(0f, 0f, size.width, size.height),
+ topLeft = CornerRadius(topLeft),
+ topRight = CornerRadius(topRight),
+ bottomRight = CornerRadius(bottomRight),
+ bottomLeft = CornerRadius(bottomLeft)
+ )
+ )
+ }
+
+ override fun lerp(stop: Continuity, fraction: Double): Continuity {
+ return when (stop) {
+ is G1Continuity -> this
+ is G2Continuity ->
+ G2Continuity(
+ profile = lerp(G2ContinuityProfile.G1Equivalent, stop.profile, fraction),
+ capsuleProfile = lerp(G2ContinuityProfile.G1Equivalent, stop.capsuleProfile, fraction)
+ )
+
+ else -> stop.lerp(this, 1f - fraction)
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G2Continuity.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G2Continuity.kt
new file mode 100644
index 0000000..c095d79
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G2Continuity.kt
@@ -0,0 +1,505 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/continuities/G2Continuity.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.continuities
+
+import androidx.compose.runtime.Immutable
+import androidx.compose.ui.util.fastCoerceAtLeast
+import androidx.compose.ui.util.fastCoerceIn
+import dev.lelonio.square.ui.glass.shapes.AdvancedContinuity
+import dev.lelonio.square.ui.glass.shapes.Continuity
+import dev.lelonio.square.ui.glass.shapes.core.Point
+import dev.lelonio.square.ui.glass.shapes.lerp
+import dev.lelonio.square.ui.glass.shapes.path.PathSegments
+import dev.lelonio.square.ui.glass.shapes.path.PathSegmentsBuilder
+import dev.lelonio.square.ui.glass.shapes.path.buildPathSegments
+import kotlin.math.PI
+import kotlin.math.cos
+import kotlin.math.min
+import kotlin.math.sin
+
+@Immutable
+data class G2Continuity(
+ val profile: G2ContinuityProfile = G2ContinuityProfile.RoundedRectangle,
+ val capsuleProfile: G2ContinuityProfile = G2ContinuityProfile.Capsule
+) : AdvancedContinuity() {
+
+ private fun resolveBezier(profile: G2ContinuityProfile) =
+ when (profile) {
+ this.profile -> this.profile.bezier
+ this.capsuleProfile -> this.capsuleProfile.bezier
+ else -> profile.bezier
+ }
+
+ override fun createStandardRoundedRectanglePathSegments(
+ width: Double,
+ height: Double,
+ topLeft: Double,
+ topRight: Double,
+ bottomRight: Double,
+ bottomLeft: Double
+ ): PathSegments {
+ val centerX = width * 0.5
+ val centerY = height * 0.5
+
+ // mnemonics:
+ // T: top, R: right, B: bottom, L: left
+ // H: horizontal Bezier, V: vertical Bezier, C: arc, I: line
+
+ // non-capsule ratios of each half corner
+ // 0: full capsule, 1: safe rounded rectangle, (0, 1): progressive capsule
+ val ratioTLV = ((centerY / topLeft - 1.0) / profile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val ratioTLH = ((centerX / topLeft - 1.0) / profile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val ratioTRH = ((centerX / topRight - 1.0) / profile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val ratioTRV = ((centerY / topRight - 1.0) / profile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val ratioBRV = ((centerY / bottomRight - 1.0) / profile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val ratioBRH = ((centerX / bottomRight - 1.0) / profile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val ratioBLH = ((centerX / bottomLeft - 1.0) / profile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val ratioBLV = ((centerY / bottomLeft - 1.0) / profile.extendedFraction).fastCoerceIn(0.0, 1.0)
+
+ // constrained non-capsule ratios of each corner
+ val ratioTL = min(ratioTLV, ratioTLH)
+ val ratioTR = min(ratioTRH, ratioTRV)
+ val ratioBR = min(ratioBRV, ratioBRH)
+ val ratioBL = min(ratioBLH, ratioBLV)
+
+ // Bezier stuffs
+
+ // extended fractions of each corner
+ val extFracTL = lerp(capsuleProfile.extendedFraction, profile.extendedFraction, ratioTL)
+ val extFracTR = lerp(capsuleProfile.extendedFraction, profile.extendedFraction, ratioTR)
+ val extFracBR = lerp(capsuleProfile.extendedFraction, profile.extendedFraction, ratioBR)
+ val extFracBL = lerp(capsuleProfile.extendedFraction, profile.extendedFraction, ratioBL)
+
+ // resolved extended fractions of each half corner
+ val extFracTLV = extFracTL * ratioTLV
+ val extFracTLH = extFracTL * ratioTLH
+ val extFracTRH = extFracTR * ratioTRH
+ val extFracTRV = extFracTR * ratioTRV
+ val extFracBRV = extFracBR * ratioBRV
+ val extFracBRH = extFracBR * ratioBRH
+ val extFracBLH = extFracBL * ratioBLH
+ val extFracBLV = extFracBL * ratioBLV
+
+ // offsets of each half corner
+ val offsetTLV = -topLeft * extFracTLV
+ val offsetTLH = -topLeft * extFracTLH
+ val offsetTRH = -topRight * extFracTRH
+ val offsetTRV = -topRight * extFracTRV
+ val offsetBRV = -bottomRight * extFracBRV
+ val offsetBRH = -bottomRight * extFracBRH
+ val offsetBLH = -bottomLeft * extFracBLH
+ val offsetBLV = -bottomLeft * extFracBLV
+
+ // Bezier curvature scales of each half corner
+ val bezKScaleTLV = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioTLV)
+ val bezKScaleTLH = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioTLH)
+ val bezKScaleTRH = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioTRH)
+ val bezKScaleTRV = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioTRV)
+ val bezKScaleBRV = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioBRV)
+ val bezKScaleBRH = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioBRH)
+ val bezKScaleBLH = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioBLH)
+ val bezKScaleBLV = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioBLV)
+
+ // arc stuffs
+
+ // arc fractions of each corner
+ val arcFracTL = lerp(capsuleProfile.arcFraction, profile.arcFraction, ratioTL)
+ val arcFracTR = lerp(capsuleProfile.arcFraction, profile.arcFraction, ratioTR)
+ val arcFracBR = lerp(capsuleProfile.arcFraction, profile.arcFraction, ratioBR)
+ val arcFracBL = lerp(capsuleProfile.arcFraction, profile.arcFraction, ratioBL)
+
+ // arc curvature scales of each corner
+ val arcKScaleTL = 1.0 + (profile.arcCurvatureScale - 1.0) * ratioTL
+ val arcKScaleTR = 1.0 + (profile.arcCurvatureScale - 1.0) * ratioTR
+ val arcKScaleBR = 1.0 + (profile.arcCurvatureScale - 1.0) * ratioBR
+ val arcKScaleBL = 1.0 + (profile.arcCurvatureScale - 1.0) * ratioBL
+
+ // base Beziers of each half corner
+ val bezierTLV = resolveBezier(G2ContinuityProfile(extFracTLV, arcFracTL, bezKScaleTLV, arcKScaleTL))
+ val bezierTLH = resolveBezier(G2ContinuityProfile(extFracTLH, arcFracTL, bezKScaleTLH, arcKScaleTL))
+ val bezierTRH = resolveBezier(G2ContinuityProfile(extFracTRH, arcFracTR, bezKScaleTRH, arcKScaleTR))
+ val bezierTRV = resolveBezier(G2ContinuityProfile(extFracTRV, arcFracTR, bezKScaleTRV, arcKScaleTR))
+ val bezierBRV = resolveBezier(G2ContinuityProfile(extFracBRV, arcFracBR, bezKScaleBRV, arcKScaleBR))
+ val bezierBRH = resolveBezier(G2ContinuityProfile(extFracBRH, arcFracBR, bezKScaleBRH, arcKScaleBR))
+ val bezierBLH = resolveBezier(G2ContinuityProfile(extFracBLH, arcFracBL, bezKScaleBLH, arcKScaleBL))
+ val bezierBLV = resolveBezier(G2ContinuityProfile(extFracBLV, arcFracBL, bezKScaleBLV, arcKScaleBL))
+
+ return buildPathSegments {
+ var x = 0.0
+ var y = topLeft
+ moveTo(x, y - offsetTLV)
+
+ // TL
+ if (topLeft > 0.0) {
+ // TLV
+ with(bezierTLV) {
+ cubicTo(
+ x + p1.y * topLeft, y - p1.x * topLeft,
+ x + p2.y * topLeft, y - p2.x * topLeft,
+ x + p3.y * topLeft, y - p3.x * topLeft
+ )
+ }
+
+ // TLC
+ arcToWithScaledRadius(
+ center = Point(topLeft, topLeft),
+ radius = topLeft,
+ radiusScale = 1.0 / arcKScaleTL,
+ startAngle = PI + PI * 0.5 * (1.0 - arcFracTL) * 0.5,
+ sweepAngle = PI * 0.5 * arcFracTL
+ )
+
+ // TLH
+ x = topLeft
+ y = 0.0
+ with(bezierTLH) {
+ cubicTo(
+ x - p2.x * topLeft, y + p2.y * topLeft,
+ x - p1.x * topLeft, y + p1.y * topLeft,
+ x - (p0.x * topLeft).fastCoerceAtLeast(offsetTLH), y + p0.y * topLeft
+ )
+ }
+ }
+
+ // TI
+ x = width - topRight
+ y = 0.0
+ lineTo(x + offsetTRH, y)
+
+ // TR
+ if (topRight > 0.0) {
+ // TRH
+ with(bezierTRH) {
+ cubicTo(
+ x + p1.x * topRight, y + p1.y * topRight,
+ x + p2.x * topRight, y + p2.y * topRight,
+ x + p3.x * topRight, y + p3.y * topRight
+ )
+ }
+
+ // TRC
+ arcToWithScaledRadius(
+ center = Point(width - topRight, topRight),
+ radius = topRight,
+ radiusScale = 1.0 / arcKScaleTR,
+ startAngle = -PI * 0.5 + PI * 0.5 * (1.0 - arcFracTR) * 0.5,
+ sweepAngle = PI * 0.5 * arcFracTR
+ )
+
+ // TRV
+ x = width
+ y = topRight
+ with(bezierTRV) {
+ cubicTo(
+ x - p2.y * topRight, y - p2.x * topRight,
+ x - p1.y * topRight, y - p1.x * topRight,
+ x - p0.y * topRight, y - (p0.x * topRight).fastCoerceAtLeast(offsetTRV)
+ )
+ }
+ }
+
+ // RI
+ x = width
+ y = height - bottomRight
+ lineTo(x, y + offsetBRV)
+
+ // BR
+ if (bottomRight > 0.0) {
+ // BRV
+ with(bezierBRV) {
+ cubicTo(
+ x - p1.y * bottomRight, y + p1.x * bottomRight,
+ x - p2.y * bottomRight, y + p2.x * bottomRight,
+ x - p3.y * bottomRight, y + p3.x * bottomRight
+ )
+ }
+
+ // BRC
+ arcToWithScaledRadius(
+ center = Point(width - bottomRight, height - bottomRight),
+ radius = bottomRight,
+ radiusScale = 1.0 / arcKScaleBR,
+ startAngle = 0.0 + PI * 0.5 * (1.0 - arcFracBR) * 0.5,
+ sweepAngle = PI * 0.5 * arcFracBR
+ )
+
+ // BRH
+ x = width - bottomRight
+ y = height
+ with(bezierBRH) {
+ cubicTo(
+ x + p2.x * bottomRight, y - p2.y * bottomRight,
+ x + p1.x * bottomRight, y - p1.y * bottomRight,
+ x + (p0.x * bottomRight).fastCoerceAtLeast(offsetBRH), y - p0.y * bottomRight
+ )
+ }
+ }
+
+ // BI
+ x = bottomLeft
+ y = height
+ lineTo(x - offsetBLH, y)
+
+ // BL
+ if (bottomLeft > 0.0) {
+ // BLH
+ with(bezierBLH) {
+ cubicTo(
+ x - p1.x * bottomLeft, y - p1.y * bottomLeft,
+ x - p2.x * bottomLeft, y - p2.y * bottomLeft,
+ x - p3.x * bottomLeft, y - p3.y * bottomLeft
+ )
+ }
+
+ // BLC
+ arcToWithScaledRadius(
+ center = Point(bottomLeft, height - bottomLeft),
+ radius = bottomLeft,
+ radiusScale = 1.0 / arcKScaleBL,
+ startAngle = PI * 0.5 + PI * 0.5 * (1.0 - arcFracBL) * 0.5,
+ sweepAngle = PI * 0.5 * arcFracBL
+ )
+
+ // BLV
+ x = 0.0
+ y = height - bottomLeft
+ with(bezierBLV) {
+ cubicTo(
+ x + p2.y * bottomLeft, y + p2.x * bottomLeft,
+ x + p1.y * bottomLeft, y + p1.x * bottomLeft,
+ x + p0.y * bottomLeft, y + (p0.x * bottomLeft).fastCoerceAtLeast(offsetBLV)
+ )
+ }
+ }
+
+ // LI
+ close()
+ }
+ }
+
+ override fun createHorizontalCapsulePathSegments(width: Double, height: Double): PathSegments {
+ val radius = height * 0.5
+ val centerX = width * 0.5
+
+ val ratioH = ((centerX / radius - 1.0) / capsuleProfile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val extFrac = capsuleProfile.extendedFraction
+ val extFracH = extFrac * ratioH
+ val offsetH = -radius * extFracH
+ val bezKScaleH = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioH)
+ val arcFrac = capsuleProfile.arcFraction
+ val bezierH =
+ resolveBezier(
+ G2ContinuityProfile(
+ extendedFraction = extFracH,
+ arcFraction = arcFrac,
+ bezierCurvatureScale = bezKScaleH,
+ arcCurvatureScale = 1.0
+ )
+ ) * radius
+
+ val arcRad = PI * 0.5 * arcFrac
+ val bezRad = (PI * 0.5 - arcRad) * 0.5
+ val sweepRad = (bezRad + arcRad) * 2.0
+
+ return buildPathSegments {
+ var x = 0.0
+ var y = radius
+ moveTo(x, y)
+
+ // LC
+ arcTo(
+ center = Point(radius, radius),
+ radius = radius,
+ startAngle = PI * 0.5 + bezRad,
+ sweepAngle = sweepRad
+ )
+
+ // TLH
+ x = radius
+ y = 0.0
+ with(bezierH) {
+ cubicTo(
+ x - p2.x, y + p2.y,
+ x - p1.x, y + p1.y,
+ x - p0.x.fastCoerceAtLeast(offsetH), y + p0.y
+ )
+ }
+
+ // TI
+ x = width - radius
+ y = 0.0
+ lineTo(x + offsetH, y)
+
+ // TRH
+ with(bezierH) {
+ cubicTo(
+ x + p1.x, y + p1.y,
+ x + p2.x, y + p2.y,
+ x + p3.x, y + p3.y
+ )
+ }
+
+ // RC
+ arcTo(
+ center = Point(width - radius, radius),
+ radius = radius,
+ startAngle = -(PI * 0.5 - bezRad),
+ sweepAngle = sweepRad
+ )
+
+ // BRH
+ x = width - radius
+ y = height
+ with(bezierH) {
+ cubicTo(
+ x + p2.x, y - p2.y,
+ x + p1.x, y - p1.y,
+ x + p0.x.fastCoerceAtLeast(offsetH), y - p0.y
+ )
+ }
+
+ // BI
+ x = radius
+ y = height
+ lineTo(x - offsetH, y)
+
+ // BLH
+ with(bezierH) {
+ cubicTo(
+ x - p1.x, y - p1.y,
+ x - p2.x, y - p2.y,
+ x - p3.x, y - p3.y
+ )
+ }
+ }
+ }
+
+ override fun createVerticalCapsulePathSegments(width: Double, height: Double): PathSegments {
+ val radius = width * 0.5
+ val centerY = height * 0.5
+
+ val ratioV = ((centerY / radius - 1.0) / capsuleProfile.extendedFraction).fastCoerceIn(0.0, 1.0)
+ val extFrac = capsuleProfile.extendedFraction
+ val extFracV = extFrac * ratioV
+ val offsetV = -radius * extFracV
+ val bezKScaleV = lerp(capsuleProfile.bezierCurvatureScale, profile.bezierCurvatureScale, ratioV)
+ val arcFrac = capsuleProfile.arcFraction
+ val bezierV =
+ resolveBezier(
+ G2ContinuityProfile(
+ extendedFraction = extFracV,
+ arcFraction = arcFrac,
+ bezierCurvatureScale = bezKScaleV,
+ arcCurvatureScale = 1.0
+ )
+ ) * radius
+
+ val arcRad = PI * 0.5 * arcFrac
+ val bezRad = (PI * 0.5 - arcRad) * 0.5
+ val sweepRad = (bezRad + arcRad) * 2.0
+
+ return buildPathSegments {
+ var x = 0.0
+ var y = radius
+ moveTo(x, y - offsetV)
+
+ // TLV
+ with(bezierV) {
+ cubicTo(
+ x + p1.y, y - p1.x,
+ x + p2.y, y - p2.x,
+ x + p3.y, y - p3.x
+ )
+ }
+
+ // TC
+ arcTo(
+ center = Point(radius, radius),
+ radius = radius,
+ startAngle = -(PI - bezRad),
+ sweepAngle = sweepRad
+ )
+
+ // TRV
+ x = width
+ y = radius
+ with(bezierV) {
+ cubicTo(
+ x - p2.y, y - p2.x,
+ x - p1.y, y - p1.x,
+ x - p0.y, y - p0.x.fastCoerceAtLeast(offsetV)
+ )
+ }
+
+ // RI
+ x = width
+ y = height - radius
+ lineTo(x, y + offsetV)
+
+ // BRV
+ with(bezierV) {
+ cubicTo(
+ x - p1.y, y + p1.x,
+ x - p2.y, y + p2.x,
+ x - p3.y, y + p3.x
+ )
+ }
+
+ // BC
+ arcTo(
+ center = Point(width - radius, height - radius),
+ radius = radius,
+ startAngle = bezRad,
+ sweepAngle = sweepRad
+ )
+
+ // BLV
+ x = 0.0
+ y = height - radius
+ with(bezierV) {
+ cubicTo(
+ x + p2.y, y + p2.x,
+ x + p1.y, y + p1.x,
+ x + p0.y, y + p0.x.fastCoerceAtLeast(offsetV)
+ )
+ }
+
+ // LI
+ close()
+ }
+ }
+
+ override fun lerp(stop: Continuity, fraction: Double): Continuity {
+ return when (stop) {
+ is G2Continuity ->
+ G2Continuity(
+ profile = lerp(this.profile, stop.profile, fraction),
+ capsuleProfile = lerp(this.capsuleProfile, stop.capsuleProfile, fraction)
+ )
+
+ else -> stop.lerp(this, 1f - fraction)
+ }
+ }
+}
+
+private fun PathSegmentsBuilder.arcToWithScaledRadius(
+ center: Point,
+ radius: Double,
+ radiusScale: Double,
+ startAngle: Double,
+ sweepAngle: Double
+) {
+ val centerAngle = startAngle + sweepAngle * 0.5
+ return arcTo(
+ center = center + Point(cos(centerAngle), sin(centerAngle)) * radius * (1.0 - radiusScale),
+ radius = radius * radiusScale,
+ startAngle = startAngle,
+ sweepAngle = sweepAngle
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G2ContinuityProfile.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G2ContinuityProfile.kt
new file mode 100644
index 0000000..d87a36a
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/continuities/G2ContinuityProfile.kt
@@ -0,0 +1,128 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/continuities/G2ContinuityProfile.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.continuities
+
+import androidx.annotation.FloatRange
+import androidx.compose.runtime.Immutable
+import androidx.compose.ui.util.fastCoerceAtLeast
+import dev.lelonio.square.ui.glass.shapes.core.CubicBezier
+import dev.lelonio.square.ui.glass.shapes.core.Point
+import dev.lelonio.square.ui.glass.shapes.lerp
+import kotlin.math.PI
+import kotlin.math.cos
+import kotlin.math.sin
+import kotlin.math.sqrt
+
+@Immutable
+data class G2ContinuityProfile(
+ @param:FloatRange(from = 0.0) val extendedFraction: Double,
+ @param:FloatRange(from = 0.0, to = 1.0) val arcFraction: Double,
+ @param:FloatRange(from = 0.0) val bezierCurvatureScale: Double,
+ @param:FloatRange(from = 0.0, fromInclusive = false) val arcCurvatureScale: Double
+) {
+
+ private var _bezier: CubicBezier? = null
+ internal val bezier: CubicBezier
+ get() = _bezier ?: createBaseBezier().also { _bezier = it }
+
+ private fun createBaseBezier(): CubicBezier {
+ val arcRadians = PI * 0.5 * arcFraction
+ val bezierRadians = (PI * 0.5 - arcRadians) * 0.5
+ val sin = sin(bezierRadians)
+ val cos = cos(bezierRadians)
+
+ return if (bezierCurvatureScale == 1.0 && arcCurvatureScale == 1.0) {
+ val halfTan = sin / (1.0 + cos)
+ CubicBezier(
+ Point(-extendedFraction, 0.0),
+ Point((1.0 - 1.5 / (1.0 + cos)) * halfTan, 0.0),
+ Point(halfTan, 0.0),
+ Point(sin, 1.0 - cos)
+ )
+ } else {
+ val radiusScale = 1.0 / arcCurvatureScale
+ val arcCenter = Point(0.0, 1.0) + Point(1.0 / sqrt(2.0), -1.0 / sqrt(2.0)) * (1.0 - radiusScale)
+ val arcStartPoint = arcCenter + Point(sin, -cos) * radiusScale
+ return generateG2ContinuousBezierWithZeroStartCurvature(
+ start = Point(-extendedFraction, 0.0),
+ end = arcStartPoint,
+ startTangent = Point(1.0, 0.0),
+ endTangent = Point(cos, sin),
+ endCurvature = bezierCurvatureScale
+ )
+ }
+ }
+
+ companion object {
+
+ val RoundedRectangle: G2ContinuityProfile =
+ G2ContinuityProfile(
+ extendedFraction = 0.5286651,
+ arcFraction = 5.0 / 9.0,
+ bezierCurvatureScale = 1.0732051,
+ arcCurvatureScale = 1.0732051
+ )
+
+ val Capsule: G2ContinuityProfile =
+ G2ContinuityProfile(
+ extendedFraction = 0.5286651 * 0.75,
+ arcFraction = 0.0,
+ bezierCurvatureScale = 1.0,
+ arcCurvatureScale = 1.0
+ )
+
+ val G1Equivalent: G2ContinuityProfile =
+ G2ContinuityProfile(
+ extendedFraction = 0.0,
+ arcFraction = 1.0,
+ bezierCurvatureScale = 1.0,
+ arcCurvatureScale = 1.0
+ )
+ }
+}
+
+fun lerp(start: G2ContinuityProfile, stop: G2ContinuityProfile, fraction: Double): G2ContinuityProfile {
+ return G2ContinuityProfile(
+ extendedFraction = lerp(start.extendedFraction, stop.extendedFraction, fraction),
+ arcFraction = lerp(start.arcFraction, stop.arcFraction, fraction),
+ bezierCurvatureScale = lerp(start.bezierCurvatureScale, stop.bezierCurvatureScale, fraction),
+ arcCurvatureScale = lerp(start.arcCurvatureScale, stop.arcCurvatureScale, fraction)
+ )
+}
+
+private fun generateG2ContinuousBezierWithZeroStartCurvature(
+ start: Point,
+ end: Point,
+ startTangent: Point,
+ endTangent: Point,
+ endCurvature: Double
+): CubicBezier {
+ val a2 = 1.5 * endCurvature
+ val b = startTangent.x * endTangent.y - startTangent.y * endTangent.x
+ val dx = end.x - start.x
+ val dy = end.y - start.y
+ val c1 = -dy * startTangent.x + dx * startTangent.y
+ val c2 = dy * endTangent.x - dx * endTangent.y
+
+ val lambda0 = -c2 / b - a2 * c1 * c1 / b / b / b
+ val lambda3 = -c1 / b
+
+ val p0 = start
+ val p1 = start + Point(
+ (lambda0 * startTangent.x).fastCoerceAtLeast(0.0),
+ (lambda0 * startTangent.y).fastCoerceAtLeast(0.0)
+ )
+ val p2 = end - Point(
+ (lambda3 * endTangent.x).fastCoerceAtLeast(0.0),
+ (lambda3 * endTangent.y).fastCoerceAtLeast(0.0)
+ )
+ val p3 = end
+
+ return CubicBezier(p0, p1, p2, p3)
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/core/CubicBezier.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/core/CubicBezier.kt
new file mode 100644
index 0000000..97e5fce
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/core/CubicBezier.kt
@@ -0,0 +1,31 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/core/CubicBezier.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.core
+
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+
+@Immutable
+data class CubicBezier(
+ val p0: Point,
+ val p1: Point,
+ val p2: Point,
+ val p3: Point
+) {
+
+ @Stable
+ operator fun times(operand: Double): CubicBezier {
+ return CubicBezier(
+ p0 * operand,
+ p1 * operand,
+ p2 * operand,
+ p3 * operand
+ )
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/core/Point.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/core/Point.kt
new file mode 100644
index 0000000..0ba7ad5
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/core/Point.kt
@@ -0,0 +1,63 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/core/Point.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.core
+
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.Stable
+import dev.lelonio.square.ui.glass.shapes.lerp
+import kotlin.math.sqrt
+
+@Immutable
+data class Point(val x: Double, val y: Double) {
+
+ @Stable
+ operator fun unaryMinus(): Point {
+ return Point(-x, -y)
+ }
+
+ @Stable
+ operator fun minus(other: Point): Point {
+ return Point(x - other.x, y - other.y)
+ }
+
+ @Stable
+ operator fun plus(other: Point): Point {
+ return Point(x + other.x, y + other.y)
+ }
+
+ @Stable
+ operator fun times(operand: Double): Point {
+ return Point(x * operand, y * operand)
+ }
+
+ @Stable
+ operator fun div(operand: Double): Point {
+ return Point(x / operand, y / operand)
+ }
+
+ @Stable
+ fun normalized(): Point {
+ val length = sqrt(x * x + y * y)
+ return if (length != 0.0) this / length else Zero
+ }
+
+ companion object {
+
+ @Stable
+ val Zero: Point = Point(0.0, 0.0)
+ }
+}
+
+@Stable
+fun lerp(start: Point, stop: Point, fraction: Double): Point {
+ return Point(
+ lerp(start.x, stop.x, fraction),
+ lerp(start.y, stop.y, fraction)
+ )
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegment.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegment.kt
new file mode 100644
index 0000000..75532d2
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegment.kt
@@ -0,0 +1,113 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/path/PathSegment.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.path
+
+import android.graphics.RectF
+import androidx.compose.runtime.Immutable
+import androidx.compose.ui.graphics.Path
+import androidx.compose.ui.graphics.asAndroidPath
+import dev.lelonio.square.ui.glass.shapes.core.Point
+import java.lang.Math.PI
+import kotlin.math.cos
+import kotlin.math.sin
+
+@Immutable
+sealed interface PathSegment {
+
+ val from: Point
+ val to: Point
+
+ fun drawTo(path: Path)
+
+ data class Line(
+ override val from: Point,
+ override val to: Point
+ ) : PathSegment {
+
+ override fun drawTo(path: Path) {
+ path.lineTo(to.x.toFloat(), to.y.toFloat())
+ }
+ }
+
+ data class Arc(
+ val center: Point,
+ val radius: Double,
+ val startAngle: Double,
+ val sweepAngle: Double
+ ) : PathSegment {
+
+ override val from: Point
+ get() = Point(
+ center.x + cos(startAngle) * radius,
+ center.y + sin(startAngle) * radius
+ )
+
+ override val to: Point
+ get() = Point(
+ center.x + cos(startAngle + sweepAngle) * radius,
+ center.y + sin(startAngle + sweepAngle) * radius
+ )
+
+ override fun drawTo(path: Path) {
+ path.asAndroidPath().arcTo(
+ RectF(
+ (center.x - radius).toFloat(),
+ (center.y - radius).toFloat(),
+ (center.x + radius).toFloat(),
+ (center.y + radius).toFloat()
+ ),
+ (startAngle * (180.0 / PI)).toFloat(),
+ (sweepAngle * (180.0 / PI)).toFloat()
+ )
+ }
+ }
+
+ data class Circle(
+ val center: Point,
+ val radius: Double
+ ) : PathSegment {
+
+ override val from: Point
+ get() = Point(center.x + radius, center.y)
+
+ override val to: Point
+ get() = from
+
+ override fun drawTo(path: Path) {
+ path.asAndroidPath().addCircle(
+ center.x.toFloat(),
+ center.y.toFloat(),
+ radius.toFloat(),
+ android.graphics.Path.Direction.CW
+ )
+ }
+ }
+
+ data class Cubic(
+ val p0: Point,
+ val p1: Point,
+ val p2: Point,
+ val p3: Point
+ ) : PathSegment {
+
+ override val from: Point
+ get() = p0
+
+ override val to: Point
+ get() = p3
+
+ override fun drawTo(path: Path) {
+ path.cubicTo(
+ p1.x.toFloat(), p1.y.toFloat(),
+ p2.x.toFloat(), p2.y.toFloat(),
+ p3.x.toFloat(), p3.y.toFloat()
+ )
+ }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegments.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegments.kt
new file mode 100644
index 0000000..5f70f06
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegments.kt
@@ -0,0 +1,22 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/path/PathSegments.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.path
+
+import androidx.compose.ui.graphics.Path
+
+typealias PathSegments = List<PathSegment>
+
+fun PathSegments.toPath(): Path {
+ return Path().apply {
+ if (isEmpty()) return@apply
+ val startPoint = first().from
+ moveTo(startPoint.x.toFloat(), startPoint.y.toFloat())
+ forEach { it.drawTo(this) }
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegmentsBuilder.kt b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegmentsBuilder.kt
new file mode 100644
index 0000000..b588362
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/shapes/path/PathSegmentsBuilder.kt
@@ -0,0 +1,70 @@
+/*
+ * Vendored from Kyant0/Capsule
+ * https://github.com/Kyant0/Capsule — Copyright 2025 Kyant0, Apache License 2.0
+ * capsule/src/main/java/com/kyant/capsule/path/PathSegmentsBuilder.kt
+ *
+ * Vendored so the shape ships as source with this app. Package renamed
+ * accordingly (com.kyant.capsule -> dev.lelonio.square.ui.glass.shapes).
+ */
+package dev.lelonio.square.ui.glass.shapes.path
+
+import dev.lelonio.square.ui.glass.shapes.core.Point
+
+inline fun buildPathSegments(block: PathSegmentsBuilder.() -> Unit): PathSegments {
+ return PathSegmentsBuilder().apply(block).build()
+}
+
+fun buildCirclePathSegments(center: Point, radius: Double): PathSegments {
+ return listOf(PathSegment.Circle(center, radius))
+}
+
+class PathSegmentsBuilder {
+
+ private var startPoint = Point.Zero
+ private var currentPoint = Point.Zero
+ private var didMove = false
+
+ private var segments = mutableListOf<PathSegment>()
+
+ fun moveTo(x: Double, y: Double) {
+ if (didMove) {
+ throw IllegalStateException("moveTo can only be called once at the beginning of the path")
+ }
+ didMove = true
+ startPoint = Point(x, y)
+ currentPoint = startPoint
+ }
+
+ fun lineTo(x: Double, y: Double) {
+ val segment = PathSegment.Line(currentPoint, Point(x, y))
+ segments += segment
+ currentPoint = segment.to
+ }
+
+ fun arcTo(center: Point, radius: Double, startAngle: Double, sweepAngle: Double) {
+ val segment = PathSegment.Arc(center, radius, startAngle, sweepAngle)
+ segments += segment
+ currentPoint = segment.to
+ }
+
+ fun cubicTo(x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double) {
+ val segment = PathSegment.Cubic(
+ currentPoint,
+ Point(x1, y1),
+ Point(x2, y2),
+ Point(x3, y3)
+ )
+ segments += segment
+ currentPoint = segment.to
+ }
+
+ fun close() {
+ val segment = PathSegment.Line(currentPoint, startPoint)
+ segments += segment
+ currentPoint = segment.to
+ }
+
+ fun build(): PathSegments {
+ return segments.toList()
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt b/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
index 9233b7f..6553066 100644
--- a/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
@@ -55,7 +55,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.lerp
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.SpotifyLogo
@@ -668,13 +668,14 @@ private fun FilterRow(selected: Feed, backdrop: Backdrop, onSelect: (Feed) -> Un
LiquidButton(
onClick = { onSelect(entry) },
backdrop = backdrop,
+ // Scrolls with the page; see LiquidButton's `flat`.
+ flat = true,
contentHeight = 38.dp,
contentPadding = 18.dp,
- blurRadius = 8.dp,
// The selected chip is the same glass, filled a little harder.
// A tinted fill would put the artwork's colour on a control
// whose whole job is to be legible over any artwork.
- surfaceColor = if (isSelected) SelectedFilm else GlassFilm,
+ surfaceColor = if (isSelected) SelectedFilm else Color.Unspecified,
) {
Text(
stringResource(entry.label),
@@ -1030,8 +1031,6 @@ private fun GlassAction(label: String, backdrop: Backdrop, onClick: () -> Unit)
backdrop = backdrop,
contentHeight = 50.dp,
contentPadding = 26.dp,
- blurRadius = 8.dp,
- surfaceColor = GlassFilm,
) {
Text(label, style = MaterialTheme.typography.titleMedium, color = Ink)
}
diff --git a/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt b/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt
index 3f3c93b..b3cfd49 100644
--- a/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt
@@ -39,7 +39,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.R
import dev.lelonio.square.data.CatalogPlaylist
import dev.lelonio.square.data.sortedByRecentlyOpened
@@ -271,8 +271,6 @@ private fun Header(
.size(42.dp),
contentHeight = 42.dp,
contentPadding = 0.dp,
- blurRadius = 8.dp,
- surfaceColor = GlassFilm,
) {
Icon(
PhosphorIcons.Regular.Plus,
@@ -292,8 +290,6 @@ private fun Header(
modifier = Modifier.size(42.dp),
contentHeight = 42.dp,
contentPadding = 0.dp,
- blurRadius = 8.dp,
- surfaceColor = GlassFilm,
) {
Icon(
if (layout == Layout.GRID) PhosphorIcons.Regular.ListBullets
@@ -318,10 +314,10 @@ private fun Header(
LiquidButton(
onClick = { onOrder(entry) },
backdrop = backdrop,
+ flat = true,
contentHeight = 36.dp,
contentPadding = 14.dp,
- blurRadius = 8.dp,
- surfaceColor = if (selected) SelectedFilm else GlassFilm,
+ surfaceColor = if (selected) SelectedFilm else Color.Unspecified,
) {
Text(
stringResource(entry.label),
@@ -431,8 +427,6 @@ private fun GlassAction(label: String, backdrop: Backdrop, onClick: () -> Unit)
backdrop = backdrop,
contentHeight = 50.dp,
contentPadding = 26.dp,
- blurRadius = 8.dp,
- surfaceColor = GlassFilm,
) {
Text(label, style = MaterialTheme.typography.titleMedium, color = Ink)
}
diff --git a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
index 7ca06d5..3bcb6ab 100644
--- a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
@@ -4,6 +4,9 @@ import androidx.annotation.StringRes
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
+import androidx.compose.foundation.layout.RowScope
+import dev.lelonio.square.ui.glass.liquidGlass
+import dev.lelonio.square.ui.player.GlassFilm
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.border
@@ -69,10 +72,10 @@ import androidx.compose.foundation.layout.BoxScope
import dev.lelonio.square.R
import dev.lelonio.square.data.CatalogTrack
import dev.lelonio.square.ui.MainViewModel
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.backdrops.layerBackdrop
-import com.kyant.backdrop.backdrops.rememberCombinedBackdrop
-import com.kyant.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
import dev.lelonio.square.ui.components.Artwork
import dev.lelonio.square.ui.components.CHOICE_MENU_WIDTH
import dev.lelonio.square.ui.components.GlassChoiceItem
@@ -89,6 +92,7 @@ import java.util.concurrent.TimeUnit
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Fill
import com.adamglin.phosphoricons.Regular
+import com.adamglin.phosphoricons.fill.Check
import com.adamglin.phosphoricons.fill.MagnifyingGlass
import com.adamglin.phosphoricons.fill.Play
import com.adamglin.phosphoricons.fill.Waveform
@@ -144,6 +148,8 @@ fun PlaylistScreen(
onShare: () -> Unit = {},
/** Opens the sheet with everything else this page can do. */
onMenu: () -> Unit = {},
+ /** Keeps the page in the library, or lets it go. */
+ onToggleSaved: () -> Unit = {},
/** The remembered track order, and where a change to it is stored. */
storedSort: String? = null,
onSortChange: (String) -> Unit = {},
@@ -284,6 +290,8 @@ fun PlaylistScreen(
kind = state.kind,
description = state.description,
pageColor = pageColor,
+ saved = state.saved,
+ onToggleSaved = onToggleSaved,
trackCount = state.tracks.size,
totalMs = state.tracks.sumOf { it.durationMs },
backdrop = pageBackdrop,
@@ -500,43 +508,32 @@ fun PlaylistScreen(
// Two round buttons side by side would have read as two destinations;
// one pane with a divide down it reads as what it is, a place where the
// page's own actions live.
- Row(
- Modifier
+ // One pane of glass with a line down it, not two buttons side by side.
+ // Two would have read as two destinations; one capsule reads as what it
+ // is, the place the page's own actions live.
+ GlassCapsule(
+ backdrop = pageBackdrop,
+ modifier = Modifier
.padding(top = contentPadding.calculateTopPadding() + 8.dp, end = 14.dp)
.align(Alignment.TopEnd)
.graphicsLayer { alpha = 1f - collapseFraction() },
- horizontalArrangement = Arrangement.spacedBy(2.dp),
) {
- LiquidButton(
+ CapsuleAction(
+ icon = PhosphorIcons.Regular.Export,
+ description = stringResource(R.string.copy_link),
onClick = onShare,
- backdrop = pageBackdrop,
- modifier = Modifier.size(42.dp),
- contentHeight = 42.dp,
- contentPadding = 0.dp,
- blurRadius = 8.dp,
- ) {
- Icon(
- PhosphorIcons.Regular.Export,
- contentDescription = stringResource(R.string.copy_link),
- tint = Color.White,
- modifier = Modifier.size(18.dp),
- )
- }
- LiquidButton(
+ )
+ Box(
+ Modifier
+ .height(20.dp)
+ .width(1.dp)
+ .background(Color.White.copy(alpha = 0.22f)),
+ )
+ CapsuleAction(
+ icon = PhosphorIcons.Regular.DotsThree,
+ description = stringResource(R.string.more),
onClick = onMenu,
- backdrop = pageBackdrop,
- modifier = Modifier.size(42.dp),
- contentHeight = 42.dp,
- contentPadding = 0.dp,
- blurRadius = 8.dp,
- ) {
- Icon(
- PhosphorIcons.Regular.DotsThree,
- contentDescription = stringResource(R.string.more),
- tint = Color.White,
- modifier = Modifier.size(20.dp),
- )
- }
+ )
}
// Floating rather than a top bar: the list scrolls under it, so the
@@ -552,7 +549,6 @@ fun PlaylistScreen(
.graphicsLayer { alpha = 1f - collapseFraction() },
contentHeight = 42.dp,
contentPadding = 0.dp,
- blurRadius = 8.dp,
) {
Icon(
PhosphorIcons.Regular.ArrowLeft,
@@ -611,6 +607,9 @@ private fun DetailHeader(
description: String,
/** The page's own colour; the solid Play button prints its label in it. */
pageColor: Color,
+ /** Whether the page is kept in the library; null hides the button. */
+ saved: Boolean?,
+ onToggleSaved: () -> Unit,
trackCount: Int,
totalMs: Long,
backdrop: Backdrop,
@@ -710,13 +709,21 @@ private fun DetailHeader(
color = pageColor,
)
}
- CircleAction(
- icon = if (searching) PhosphorIcons.Regular.X else PhosphorIcons.Fill.MagnifyingGlass,
- description = stringResource(R.string.search_in_tracks),
- size = 52.dp,
- backdrop = backdrop,
- onClick = onToggleSearch,
- )
+ // Keeping the page, which is what the reference puts here.
+ // Absent while the answer is unknown and on the pages the
+ // question does not apply to: a button that cannot say whether
+ // it is on or off is worse than no button.
+ if (saved != null) {
+ CircleAction(
+ icon = if (saved) PhosphorIcons.Fill.Check else PhosphorIcons.Regular.Plus,
+ description = stringResource(
+ if (saved) R.string.remove_from_library else R.string.add_to_library,
+ ),
+ size = 52.dp,
+ backdrop = backdrop,
+ onClick = onToggleSaved,
+ )
+ }
}
// What the list is, in its own words. Only the sources that carry
@@ -863,6 +870,64 @@ private fun Modifier.heroCollapse(
}
}.clipToBounds()
+/**
+ * A pane of glass shaped like a capsule, for actions that belong together.
+ *
+ * Refraction alone is invisible here. The page under these controls is a flat
+ * colour taken from the cover, and bending a flat colour gives the same flat
+ * colour back: the buttons came out as plain discs, which is the note in the
+ * layer above about glass having nothing to bend. What makes glass read against
+ * a flat field is its edge, so this adds the two things an edge has — a film so
+ * the pane is a shade lighter than what it lies on, and a bright rim where the
+ * light would catch it.
+ */
+@Composable
+private fun GlassCapsule(
+ backdrop: Backdrop,
+ modifier: Modifier = Modifier,
+ content: @Composable RowScope.() -> Unit,
+) {
+ val shape = RoundedCornerShape(percent = 50)
+ Row(
+ modifier
+ .height(42.dp)
+ .clip(shape)
+ .liquidGlass(
+ config = dev.lelonio.square.ui.glass.LocalGlassEffectConfig.current,
+ shape = shape,
+ blurRadiusDp = dev.lelonio.square.ui.glass.LocalGlassEffectConfig.current.blurRadius,
+ ownBackdrop = backdrop,
+ )
+ // The rim comes with the material now; this is the drawn edge that
+ // separates the two halves' pane from the artwork behind it.
+ .border(0.6.dp, Color.White.copy(alpha = 0.30f), shape),
+ verticalAlignment = Alignment.CenterVertically,
+ content = content,
+ )
+}
+
+/** One half of [GlassCapsule], sized so the two halves are the same target. */
+@Composable
+private fun CapsuleAction(
+ icon: androidx.compose.ui.graphics.vector.ImageVector,
+ description: String,
+ onClick: () -> Unit,
+) {
+ Box(
+ Modifier
+ .size(width = 46.dp, height = 42.dp)
+ .pressable(onClick, pressedScale = 0.92f),
+ contentAlignment = Alignment.Center,
+ ) {
+ Icon(
+ icon,
+ contentDescription = description,
+ tint = Color.White,
+ modifier = Modifier.size(19.dp),
+ )
+ }
+}
+
@Composable
private fun CircleAction(
icon: androidx.compose.ui.graphics.vector.ImageVector,
@@ -874,10 +939,13 @@ private fun CircleAction(
LiquidButton(
onClick = onClick,
backdrop = backdrop,
- modifier = Modifier.size(size),
+ // See GlassCapsule: over the page's flat colour the refraction has
+ // nothing to bend, and only the film and the rim say this is glass.
+ modifier = Modifier
+ .size(size)
+ .border(0.6.dp, Color.White.copy(alpha = 0.30f), CircleShape),
contentHeight = size,
contentPadding = 0.dp,
- blurRadius = 8.dp,
) {
Icon(
icon,
diff --git a/app/src/main/java/dev/lelonio/square/ui/onboarding/OnboardingScreen.kt b/app/src/main/java/dev/lelonio/square/ui/onboarding/OnboardingScreen.kt
index d8ce313..d17e372 100644
--- a/app/src/main/java/dev/lelonio/square/ui/onboarding/OnboardingScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/onboarding/OnboardingScreen.kt
@@ -54,7 +54,7 @@ import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.ArrowLeft
import com.adamglin.phosphoricons.regular.ArrowUpRight
import com.adamglin.phosphoricons.regular.Check
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.R
import dev.lelonio.square.ui.MainViewModel
import dev.lelonio.square.ui.components.AppIcon
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/AddToPlaylistSheet.kt b/app/src/main/java/dev/lelonio/square/ui/player/AddToPlaylistSheet.kt
index 8a108c3..9ad7eba 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/AddToPlaylistSheet.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/AddToPlaylistSheet.kt
@@ -1,8 +1,8 @@
package dev.lelonio.square.ui.player
import androidx.compose.foundation.background
-import com.kyant.backdrop.effects.blur
-import com.kyant.backdrop.drawBackdrop
+import dev.lelonio.square.ui.glass.backdrop.effects.blur
+import dev.lelonio.square.ui.glass.backdrop.drawBackdrop
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.slideInVertically
@@ -38,7 +38,7 @@ import androidx.compose.ui.unit.dp
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.Check
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.R
import dev.lelonio.square.data.CatalogPlaylist
import dev.lelonio.square.ui.MainViewModel
@@ -100,7 +100,7 @@ fun AddToPlaylistSheet(
// Heavier than the page behind it: the panel samples the unblurred
// layer, so at the usual radius the rows underneath came through
// sharper inside the sheet than outside it.
- blurRadius = 46.dp,
+ blurScale = 23.0f,
modifier = Modifier
.padding(16.dp)
.fillMaxWidth()
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/DevicePicker.kt b/app/src/main/java/dev/lelonio/square/ui/player/DevicePicker.kt
index 452576c..432918b 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/DevicePicker.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/DevicePicker.kt
@@ -27,7 +27,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.R
import dev.lelonio.square.ui.MainViewModel
import com.adamglin.PhosphorIcons
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/FloatingMiniPlayer.kt b/app/src/main/java/dev/lelonio/square/ui/player/FloatingMiniPlayer.kt
new file mode 100644
index 0000000..aa2abd5
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/player/FloatingMiniPlayer.kt
@@ -0,0 +1,259 @@
+/*
+ * Adapted from Convx (GPL-3.0), ui/player/FloatingMiniPlayer.kt.
+ * https://github.com/cosmictaserdev-creator/Convx
+ *
+ * Their accessory strip, with their sizes, their press response, their glow and
+ * their swipe-to-skip, driven by this app's own playback state instead of
+ * Convx's PlayerConnection. What is gone is what belonged to their app and not
+ * to the shape of the thing: listen-together, the tablet pill that scales with
+ * its height, the queue and lyrics buttons, and the preference keys behind the
+ * gesture. The rest is theirs.
+ */
+
+package dev.lelonio.square.ui.player
+
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.Spring
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.animation.core.spring
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.gestures.detectHorizontalDragGestures
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.interaction.collectIsPressedAsState
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.offset
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.State
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clipToBounds
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.platform.LocalLayoutDirection
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.IntOffset
+import androidx.compose.ui.unit.LayoutDirection
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.adamglin.PhosphorIcons
+import com.adamglin.phosphoricons.Fill
+import com.adamglin.phosphoricons.fill.Pause
+import com.adamglin.phosphoricons.fill.Play
+import com.adamglin.phosphoricons.fill.SkipForward
+import dev.lelonio.square.R
+import dev.lelonio.square.ui.glass.InteractiveHighlight
+import dev.lelonio.square.ui.glass.ScrollingWaveformSeekBar
+import dev.lelonio.square.ui.components.Artwork
+import kotlinx.coroutines.launch
+import kotlin.math.abs
+import kotlin.math.roundToInt
+
+/** Their numbers: a 40dp thumbnail, 40dp controls, 12 by 8 of padding. */
+private val ArtSize = 40.dp
+private val ControlSize = 40.dp
+
+/**
+ * What is playing, as the bar's accessory.
+ *
+ * The pill above the tabs when the bar is open and one of the three things on
+ * the row when it has folded — the bar decides which, this only draws it.
+ */
+@Composable
+fun FloatingMiniPlayer(
+ state: PlaybackState,
+ positionMs: State<Long>,
+ modifier: Modifier = Modifier,
+ contentColor: androidx.compose.ui.graphics.Color = MiniPlayerInk,
+ /** Folded: the strip has room for the song and one button, nothing else. */
+ inline: Boolean = false,
+ onClick: () -> Unit,
+ onTogglePlay: () -> Unit,
+ onNext: () -> Unit,
+ onPrevious: () -> Unit,
+ onSeek: (Long) -> Unit,
+) {
+ val scope = rememberCoroutineScope()
+ val layoutDirection = LocalLayoutDirection.current
+
+ // iOS 26 style press response: the whole glass pill grows slightly while
+ // touched.
+ val pressInteractionSource = remember { MutableInteractionSource() }
+ val isPressed by pressInteractionSource.collectIsPressedAsState()
+ val pressScale by animateFloatAsState(
+ targetValue = if (isPressed) 1.04f else 1f,
+ animationSpec = spring(stiffness = Spring.StiffnessMediumLow),
+ label = "accessoryPressScale",
+ )
+
+ // The same finger-tracking glow the tab bar's puck has. Its gesture tracking
+ // never consumes pointer events, so it is safe stacked alongside the swipe
+ // detector and the click below.
+ val glow = remember(scope) { InteractiveHighlight(animationScope = scope) }
+
+ val offsetX = remember { Animatable(0f) }
+ var dragStart by remember { mutableStateOf(0L) }
+ var dragged by remember { mutableStateOf(0f) }
+ val settle = remember { spring<Float>(stiffness = Spring.StiffnessMediumLow) }
+
+ Box(
+ contentAlignment = Alignment.CenterStart,
+ modifier = Modifier
+ .graphicsLayer {
+ scaleX = pressScale
+ scaleY = pressScale
+ }
+ .then(modifier)
+ .then(glow.modifier)
+ .clipToBounds()
+ .then(glow.gestureModifier)
+ .pointerInput(state.hasNext, state.hasPrevious) {
+ detectHorizontalDragGestures(
+ onDragStart = {
+ dragStart = System.currentTimeMillis()
+ dragged = 0f
+ },
+ onDragCancel = { scope.launch { offsetX.animateTo(0f, settle) } },
+ onHorizontalDrag = { _, amount ->
+ val delta = if (layoutDirection == LayoutDirection.Rtl) -amount else amount
+ val goingBack = delta > 0
+ val allowed =
+ (goingBack && state.hasPrevious) || (!goingBack && state.hasNext)
+ // Or on the way home: a pill dragged where it cannot go
+ // still has to be able to come back.
+ val returning = (goingBack && offsetX.value < 0) || (!goingBack && offsetX.value > 0)
+ if (allowed || returning) {
+ dragged += abs(delta)
+ scope.launch { offsetX.snapTo(offsetX.value + delta) }
+ }
+ },
+ onDragEnd = {
+ val ms = System.currentTimeMillis() - dragStart
+ // Mean velocity over the gesture, px/ms: a short fast
+ // throw should not have to cross the whole distance.
+ val velocity = if (ms > 0) dragged / ms else 0f
+ val threshold = size.width * 0.28f
+ val far = abs(offsetX.value)
+ if (far > threshold || (velocity > 0.55f && far > threshold * 0.25f)) {
+ if (offsetX.value > 0 && state.hasPrevious) onPrevious()
+ else if (offsetX.value <= 0 && state.hasNext) onNext()
+ }
+ scope.launch { offsetX.animateTo(0f, settle) }
+ },
+ )
+ },
+ ) {
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ modifier = Modifier
+ .fillMaxWidth()
+ .offset { IntOffset(offsetX.value.roundToInt(), 0) }
+ .clickable(
+ interactionSource = pressInteractionSource,
+ indication = null,
+ onClick = onClick,
+ )
+ .padding(
+ horizontal = if (inline) 10.dp else 12.dp,
+ vertical = if (inline) 6.dp else 8.dp,
+ ),
+ ) {
+ Artwork(
+ url = state.artworkUrl,
+ title = state.title,
+ modifier = Modifier.size(if (inline) 36.dp else ArtSize),
+ corner = 9.dp,
+ decodeSize = ArtSize,
+ )
+
+ Spacer(Modifier.width(if (inline) 8.dp else 10.dp))
+
+ Column(Modifier.weight(1f)) {
+ Text(
+ text = state.title,
+ style = if (inline) {
+ MaterialTheme.typography.bodySmall
+ } else {
+ MaterialTheme.typography.bodyMedium
+ },
+ color = contentColor,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ Text(
+ text = state.artist,
+ style = if (inline) {
+ MaterialTheme.typography.bodySmall.copy(fontSize = 10.sp)
+ } else {
+ MaterialTheme.typography.bodySmall
+ },
+ color = contentColor.copy(alpha = 0.7f),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ }
+
+ // Skip first and play second, which is the order asked for: the
+ // button that starts the music is the one nearest the thumb.
+ if (!inline) {
+ IconButton(onClick = onNext, modifier = Modifier.size(ControlSize)) {
+ Icon(
+ PhosphorIcons.Fill.SkipForward,
+ contentDescription = stringResource(R.string.next),
+ tint = contentColor,
+ modifier = Modifier.size(22.dp),
+ )
+ }
+ }
+
+ IconButton(
+ onClick = onTogglePlay,
+ modifier = Modifier.size(if (inline) 36.dp else ControlSize),
+ ) {
+ Icon(
+ if (state.isPlaying) PhosphorIcons.Fill.Pause else PhosphorIcons.Fill.Play,
+ contentDescription = stringResource(
+ if (state.isPlaying) R.string.pause else R.string.play,
+ ),
+ tint = contentColor,
+ modifier = Modifier.size(if (inline) 20.dp else 24.dp),
+ )
+ }
+ }
+
+ // The old bar's own hairline, back where the wave was: a coloured line
+ // along the bottom of the pill. It says where the track is without
+ // asking to be read, which on a strip this size is the whole job.
+ androidx.compose.material3.LinearProgressIndicator(
+ progress = {
+ val duration = state.durationMs
+ if (duration > 0) (positionMs.value.toFloat() / duration).coerceIn(0f, 1f) else 0f
+ },
+ modifier = Modifier
+ .align(Alignment.BottomStart)
+ .fillMaxWidth()
+ .padding(horizontal = 14.dp)
+ .height(2.dp),
+ color = MaterialTheme.colorScheme.primary,
+ trackColor = contentColor.copy(alpha = 0.18f),
+ drawStopIndicator = {},
+ )
+ }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/GlassSurface.kt b/app/src/main/java/dev/lelonio/square/ui/player/GlassSurface.kt
index 474153e..d52861d 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/GlassSurface.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/GlassSurface.kt
@@ -2,6 +2,7 @@ package dev.lelonio.square.ui.player
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.shape.CornerBasedShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -9,25 +10,17 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.isSpecified
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.backdrop.effects.blur
-import com.kyant.backdrop.effects.lens
-import com.kyant.backdrop.effects.vibrancy
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.liquidGlass
/**
* A pane of glass over [backdrop].
*
- * Wraps the one call every glass surface in this screen makes, so the numbers
- * that decide what the material *is* — how far it blurs, how hard it bends light
- * at the edge — live in one place instead of being re-picked per component.
- *
- * The three effects are ordered deliberately and are not interchangeable:
- * `vibrancy` lifts the colour of what shows through so it does not go grey under
- * the blur, `blur` is the frosting, and `lens` is the refraction that makes the
- * edge read as a thick slab rather than as a translucent rectangle. Without the
- * lens this is just a blurred panel, which is the thing most "glass" UIs
- * actually are.
+ * One call for every glass surface outside the bottom bar: the sheets, the
+ * menus, the cards a link opens, the player's own panels. What it is made of is
+ * not decided here any more — it defers to the bar's [liquidGlass], so there is
+ * a single answer in the app to what glass looks like, and changing it changes
+ * everything at once.
*
* Everything degrades on its own below Android 13: the library checks for
* RuntimeShader support and skips the refraction, leaving the blur, and below
@@ -50,17 +43,23 @@ fun GlassSurface(
backdrop: Backdrop,
shape: Shape,
modifier: Modifier = Modifier,
- blurRadius: Dp = 8.dp,
- /** How far in from the edge the refraction reaches. */
- refractionHeight: Dp = 24.dp,
- /** How hard light bends there. */
- refractionAmount: Dp = 24.dp,
/**
- * A film drawn over the refracted backdrop.
+ * How thick this pane is, as a multiple of the app's own frost.
*
- * Without it a pane is pure refraction and reads darker than the buttons
- * beside it, which do draw one — the surfaces stop looking like the same
- * material. Unspecified leaves the glass clear.
+ * The one thing a caller still decides, and it is a ratio rather than a
+ * number of dp on purpose: a panel covering half the screen has to hide what
+ * is under it in a way a pill the size of a word does not, but both have to
+ * answer the setting. Fixed dp here is what made the player's surfaces stop
+ * listening to it — a hardcoded 8 next to a bar on 2 is a different
+ * material, whatever the slider says.
+ */
+ blurScale: Float = 1f,
+ /**
+ * The film, for the surfaces that do not get real glass.
+ *
+ * Where they do, the film comes from the shared recipe with everything else
+ * about the material. This is what an unsupported device, a shape the
+ * refraction cannot follow, or a moving player falls back to.
*/
surfaceColor: Color = Color.Unspecified,
content: @Composable () -> Unit,
@@ -77,30 +76,61 @@ fun GlassSurface(
return
}
+ // The same material the bottom bar is made of, so one app has one glass.
+ //
+ // The bar came from elsewhere and brought its own recipe with it, and next
+ // to it every other pane in this app read as a different substance: a
+ // different saturation, a different bend at the edge, and a thin white film
+ // where the bar has a lit grey one. Asking both recipes to agree by hand was
+ // the previous attempt and it changed nothing anybody could see, so there is
+ // only one recipe now — [Modifier.liquidGlass], the bar's own — and the
+ // parameters below are what a pane is still allowed to choose.
+ //
+ // Only how thick it is, in other words. How far it blurs is a real
+ // difference between a small pill and a panel covering half the screen; what
+ // the material *is* is not.
+ val config = dev.lelonio.square.ui.glass.LocalGlassEffectConfig.current
+ // The refraction is part of that recipe now, and it is the reason this takes
+ // a shape it can bend light along. Anything else keeps the film below.
+ val blurDp = (config.blurRadius * blurScale).coerceAtLeast(0f)
+ val cornerShape = shape as? CornerBasedShape
+ if (cornerShape == null) {
+ Box(
+ modifier.background(
+ color = if (surfaceColor.isSpecified) surfaceColor else FallbackFilm,
+ shape = shape,
+ ),
+ ) {
+ content()
+ }
+ return
+ }
+
Box(
- modifier.drawBackdrop(
- backdrop = backdrop,
- shape = { shape },
- effects = {
- vibrancy()
- blur(blurRadius.toPx())
- // Deliberately the same numbers LiquidBottomTabs uses. They were
- // tuned by eye at first and came out a different material — a
- // shallower, harder edge than the bar and the buttons beside
- // it, which is exactly what "the player doesn't look like the
- // rest" was.
- lens(refractionHeight.toPx(), refractionAmount.toPx())
- },
- onDrawSurface = if (surfaceColor.isSpecified) {
- { drawRect(surfaceColor) }
- } else {
- null
- },
+ modifier.liquidGlass(
+ config = config,
+ shape = cornerShape,
+ blurRadiusDp = blurDp,
+ // The bar's rim, not the library's default: the app's chrome is one
+ // material and the edge light is most of what says so.
+ highlightAlpha = BarHighlightAlpha,
+ // Panes sit over their own backdrop: the player's is the artwork
+ // behind it rather than the page under that.
+ ownBackdrop = backdrop,
),
) {
content()
}
}
+/**
+ * The rim every surface in this app is lit with.
+ *
+ * The bottom bar picked this when it arrived and everything else kept the
+ * library's brighter default, which is why the player read as a different
+ * material even once the rest of the recipe was shared.
+ */
+internal const val BarHighlightAlpha = 0.3f
+
/** What a pane looks like with the refraction switched off. */
private val FallbackFilm = Color.White.copy(alpha = 0.12f)
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/MiniPlayer.kt b/app/src/main/java/dev/lelonio/square/ui/player/MiniPlayer.kt
index ab26507..9a05291 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/MiniPlayer.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/MiniPlayer.kt
@@ -35,7 +35,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.R
import dev.lelonio.square.ui.components.Artwork
import dev.lelonio.square.ui.glass.LiquidButton
@@ -163,16 +163,19 @@ fun MiniPlayer(
Row(
Modifier
.fillMaxWidth()
- .padding(10.dp),
+ // The reference's own numbers for the phone strip: a 36dp
+ // thumbnail with a 9dp corner, 36dp controls, and 10 by 6 of
+ // padding round the lot.
+ .padding(horizontal = 10.dp, vertical = 6.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Artwork(
state.artworkUrl,
state.title,
Modifier
- .size(42.dp)
+ .size(36.dp)
.sharedArtwork(sharedScope, animatedScope),
- corner = 12.dp,
+ corner = 9.dp,
)
// Slides up on a track change, so an auto-advance is visible
@@ -185,13 +188,13 @@ fun MiniPlayer(
},
label = "nowPlaying",
modifier = Modifier
- .padding(horizontal = 14.dp)
+ .padding(start = 8.dp, end = 8.dp)
.weight(1f),
) { (title, artist) ->
Column {
Text(
title,
- style = MaterialTheme.typography.titleMedium,
+ style = MaterialTheme.typography.titleSmall,
color = MiniPlayerInk,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
@@ -237,10 +240,9 @@ fun MiniPlayer(
LiquidButton(
onClick = onTogglePlay,
backdrop = backdrop,
- surfaceColor = GlassFilm,
- contentHeight = 42.dp,
+ contentHeight = 36.dp,
contentPadding = 0.dp,
- modifier = Modifier.size(42.dp),
+ modifier = Modifier.size(36.dp),
) {
// Same ring as the player's; see the note there.
Box(contentAlignment = Alignment.Center) {
@@ -287,8 +289,8 @@ fun MiniPlayer(
* Fixed light, like everything else on the glass: what sits behind this bar is
* the darkened artwork, not a page colour.
*/
-private val MiniPlayerInk = Color(0xFFF7F8FA)
-private val MiniPlayerInkDim = Color(0xFFF7F8FA).copy(alpha = 0.66f)
+internal val MiniPlayerInk = Color(0xFFF7F8FA)
+internal val MiniPlayerInkDim = Color(0xFFF7F8FA).copy(alpha = 0.66f)
/**
* The green everyone already reads as "this is coming out of something else".
@@ -304,7 +306,12 @@ fun progressOf(positionMs: Long, durationMs: Long): Float =
if (durationMs <= 0) 0f else (positionMs.toFloat() / durationMs).coerceIn(0f, 1f)
/** Spacer height so lists can scroll clear of the mini player. */
-val MiniPlayerHeight = 74.dp
+/**
+ * 52dp, measured off the reference: the pill above the tabs is shorter than the
+ * tab capsule under it, and a mini player as tall as the bar made the two read
+ * as one slab.
+ */
+val MiniPlayerHeight = 48.dp
@Composable
fun MiniPlayerSpacer() = Box(Modifier.height(MiniPlayerHeight))
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/NowPlayingSheet.kt b/app/src/main/java/dev/lelonio/square/ui/player/NowPlayingSheet.kt
index 8c1e88c..c60a2af 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/NowPlayingSheet.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/NowPlayingSheet.kt
@@ -4,32 +4,20 @@ import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
-import androidx.compose.foundation.gestures.Orientation
-import androidx.compose.foundation.gestures.draggable
-import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
-import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
-import androidx.compose.ui.layout.layout
-import androidx.compose.ui.platform.LocalDensity
-import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
-import kotlin.math.abs
/**
* The now-playing bar and the player, as one surface.
@@ -58,14 +46,20 @@ import kotlin.math.abs
* The same value is what a drag writes to, which is why dragging down works at
* any point and can be released anywhere: expansion is a position, not an event.
*
+ * There is no collapsed half any more. There used to be one — a bar the width of
+ * the screen, carrying what was playing and the drag that opened the player — and
+ * once the tab bar grew its own now-playing pill it stayed behind as an empty
+ * strip: invisible, sixty-odd dp tall, sitting across the bottom of every page
+ * and still listening for a vertical drag. An upward swipe over the last of a
+ * list opened the player, from a thing nobody could see. What opens it now is the
+ * pill itself, which is where what is playing actually is.
+ *
* @param progress 0 while collapsed, 1 while expanded. Hoisted because the tab
* bar has to fade out against it.
*/
@Composable
fun NowPlayingSheet(
progress: Animatable<Float, *>,
- /** Space the collapsed bar leaves for the tab bar beneath it. */
- bottomInset: Dp,
/**
* Drawn under the player, fading in with it.
*
@@ -75,11 +69,9 @@ fun NowPlayingSheet(
* Canvas to cover it.
*/
background: @Composable () -> Unit,
- collapsedContent: @Composable () -> Unit,
expandedContent: @Composable () -> Unit,
) {
val scope = rememberCoroutineScope()
- val density = LocalDensity.current
// Nothing here reads `progress.value` during composition, and that is the
// whole performance story of this file.
@@ -98,17 +90,12 @@ fun NowPlayingSheet(
val settled by remember {
derivedStateOf { progress.value <= 0.001f || progress.value >= 0.999f }
}
- val collapsedVisible by remember { derivedStateOf { progress.value < 0.999f } }
-
- BoxWithConstraints(Modifier.fillMaxSize()) {
- val fullHeight = maxHeight
- val collapsedHeight = MiniPlayerHeight
- val travelPx = with(density) { (fullHeight - collapsedHeight).toPx() }
+ Box(Modifier.fillMaxSize()) {
// One spec for both directions, and the same one the tap uses: closing
// is meant to be the opening played backwards, so nothing about the
// motion may depend on which way it is going.
- fun settle(target: Float, initialVelocity: Float = 0f) {
+ fun settle(target: Float) {
scope.launch {
progress.animateTo(
target,
@@ -116,20 +103,12 @@ fun NowPlayingSheet(
// settle rather than stopping dead, which is what makes a
// panel this size feel like it has weight.
spring(dampingRatio = 0.86f, stiffness = Spring.StiffnessMediumLow),
- initialVelocity = initialVelocity,
)
}
}
BackHandler(enabled = expandedVisible) { settle(0f) }
- val draggable = rememberDraggableState { delta ->
- scope.launch {
- // Dragging up is negative, and up means expanding.
- progress.snapTo((progress.value - delta / travelPx).coerceIn(0f, 1f))
- }
- }
-
// The player, full size from the first frame to the last. Nothing about
// the travel touches measure or layout any more: the growing container
// that used to drive it re-ran a layout pass on the whole player every
@@ -171,69 +150,13 @@ fun NowPlayingSheet(
}
}
}
-
- // The bar stays where it is and fades under the arriving player. It used
- // to be the same surface, stretched — which is the effect this is
- // giving up, and with it the stutter that came from stretching it.
- if (collapsedVisible) {
- Box(
- Modifier
- .align(Alignment.BottomCenter)
- .padding(horizontal = SIDE_MARGIN)
- .padding(bottom = bottomInset)
- .height(collapsedHeight)
- .fillMaxWidth()
- .graphicsLayer { alpha = collapsedAlpha(progress.value) }
- .draggable(
- state = draggable,
- orientation = Orientation.Vertical,
- onDragStopped = { velocity ->
- // Velocity decides when the gesture was a flick;
- // otherwise the halfway point does. Without the
- // velocity test a fast short flick would snap back,
- // which reads as the gesture having been ignored.
- val target = when {
- abs(velocity) > FLING_VELOCITY -> if (velocity < 0) 1f else 0f
- progress.value > 0.5f -> 1f
- else -> 0f
- }
- // Handed to the spring rather than dropped.
- settle(target, initialVelocity = -velocity / travelPx)
- },
- ),
- ) {
- collapsedContent()
- }
- }
}
}
-/**
- * The bar is gone by a third of the way up, and the player starts there.
- *
- * They hand over rather than overlap: with both half-visible you see two sets
- * of controls at once, which is what the cross-dissolve version looked like.
- * They also hand over at exactly the same point in both directions — the two
- * used to leave a sliver of travel where the bar had gone and the player had
- * not arrived, and running that backwards is not the same as running it
- * forwards.
- */
-private fun collapsedAlpha(fraction: Float): Float =
- (1f - fraction / HANDOVER).coerceIn(0f, 1f)
-
-/** Where the bar has finished leaving and the player begins to arrive. */
-private const val HANDOVER = 0.3f
-
/** How small the player starts, growing to its own size as it arrives. */
private const val ENTER_SCALE = 0.92f
/** How far below its place it starts, as a fraction of its height. */
private const val ENTER_TRAVEL = 0.06f
-/** Margin the collapsed bar keeps from the edges of the window. */
-private val SIDE_MARGIN = 16.dp
-
private val SHEET_CORNER = 22.dp
-
-/** Past this, a drag is a flick and its direction decides where it lands. */
-private const val FLING_VELOCITY = 900f
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt
index e83fd68..97d214e 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt
@@ -100,7 +100,7 @@ fun PlayerPanelSection(
onSavePreset: (String) -> Unit,
onDeletePreset: (String) -> Unit,
/** The layer the panel refracts; see the liquid-glass note in PlayerScreen. */
- backdrop: com.kyant.backdrop.Backdrop,
+ backdrop: dev.lelonio.square.ui.glass.backdrop.Backdrop,
) {
Column(
Modifier.fillMaxWidth(),
@@ -245,7 +245,7 @@ internal fun EffectsPanel(
onApplyPreset: (EffectPreset) -> Unit,
onSavePreset: (String) -> Unit,
onDeletePreset: (String) -> Unit,
- backdrop: com.kyant.backdrop.Backdrop,
+ backdrop: dev.lelonio.square.ui.glass.backdrop.Backdrop,
) {
var naming by remember { mutableStateOf(false) }
@@ -474,7 +474,7 @@ private fun EffectSlider(
* answer to "what am I choosing?" until it had already been chosen.
*/
reading: (Float) -> String,
- backdrop: com.kyant.backdrop.Backdrop,
+ backdrop: dev.lelonio.square.ui.glass.backdrop.Backdrop,
onChange: (Float) -> Unit,
onReset: () -> Unit,
) {
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt
index 06c3edb..05145b1 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt
@@ -73,10 +73,10 @@ import androidx.compose.ui.unit.dp
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import coil.compose.AsyncImage
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.backdrops.layerBackdrop
-import com.kyant.backdrop.backdrops.rememberCombinedBackdrop
-import com.kyant.backdrop.backdrops.rememberLayerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdrop
+import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
import dev.lelonio.square.R
import dev.lelonio.square.ui.MainViewModel
import dev.lelonio.square.ui.components.Artwork
@@ -1348,13 +1348,11 @@ private fun RoundGlassButton(
// Dimmed rather than removed when there is nowhere to go: a control
// that disappears makes the whole row jump.
.graphicsLayer { alpha = if (enabled) 1f else 0.4f },
- surfaceColor = GlassFilm,
contentHeight = size,
contentPadding = 0.dp,
// Matched to the bottom bar and the mini player. At the upstream 2dp
// these were the one place in the app where the glass barely frosted
// what was behind it.
- blurRadius = 8.dp,
) {
content()
}
diff --git a/app/src/main/java/dev/lelonio/square/ui/search/SearchScreen.kt b/app/src/main/java/dev/lelonio/square/ui/search/SearchScreen.kt
index b49fd2d..c688539 100644
--- a/app/src/main/java/dev/lelonio/square/ui/search/SearchScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/search/SearchScreen.kt
@@ -17,8 +17,6 @@ import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
-import androidx.compose.foundation.text.BasicTextField
-import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
@@ -31,13 +29,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
-import androidx.compose.ui.graphics.SolidColor
-import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.R
import dev.lelonio.square.data.CatalogTrack
import dev.lelonio.square.data.SearchItem
@@ -53,9 +50,7 @@ import dev.lelonio.square.ui.theme.InkDim
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Fill
import com.adamglin.phosphoricons.Regular
-import com.adamglin.phosphoricons.fill.MagnifyingGlass
import com.adamglin.phosphoricons.regular.DotsThree
-import com.adamglin.phosphoricons.regular.X
/** Which kind of result the page is showing. */
private enum class Kind(@StringRes val label: Int) {
@@ -81,7 +76,6 @@ fun SearchScreen(
webApi: MainViewModel.WebApiState,
contentPadding: PaddingValues,
nowPlayingUri: String?,
- onQueryChange: (String) -> Unit,
onClientIdChange: (String) -> Unit,
onConnectWebApi: () -> Unit,
onPlayTrack: (List<CatalogTrack>, Int) -> Unit,
@@ -98,17 +92,11 @@ fun SearchScreen(
remember(query) { kind = Kind.ALL }
LazyColumn(Modifier.fillMaxSize(), contentPadding = contentPadding) {
- item(contentType = "field") {
- Column(Modifier.padding(start = 24.dp, end = 24.dp, top = 36.dp)) {
- Text(stringResource(R.string.search), style = MaterialTheme.typography.displayLarge)
- SearchField(
- query = state.query,
- enabled = !state.needsSetup,
- backdrop = backdrop,
- onQueryChange = onQueryChange,
- )
- }
- }
+ // No field, and no title over it. Both are in the bottom bar now: the
+ // search button there grows into the box you type in, which is the whole
+ // point of that control, and a page that answers it by drawing a second
+ // box asks which of the two is listening. What is left here is the
+ // answer, which is what the page was ever for.
if (!state.results.isEmpty && !state.loading) {
item(contentType = "chips") {
@@ -184,75 +172,6 @@ fun SearchScreen(
}
}
-/**
- * The query box, in the app's own glass rather than Material's outline.
- *
- * Built from [BasicTextField] because an `OutlinedTextField` carries a label, a
- * container colour and a border that belong to a design this app does not use —
- * every other control on the page is a pane of glass over the artwork.
- */
-@Composable
-private fun SearchField(
- query: String,
- enabled: Boolean,
- backdrop: Backdrop,
- onQueryChange: (String) -> Unit,
-) {
- LiquidButton(
- onClick = {},
- backdrop = backdrop,
- surfaceColor = GlassFilm,
- contentHeight = 52.dp,
- contentPadding = 18.dp,
- modifier = Modifier
- .fillMaxWidth()
- .padding(top = 16.dp),
- ) {
- Icon(
- PhosphorIcons.Fill.MagnifyingGlass,
- contentDescription = null,
- tint = InkDim,
- modifier = Modifier.size(18.dp),
- )
- Box(
- Modifier
- .padding(start = 12.dp)
- .weight(1f),
- contentAlignment = Alignment.CenterStart,
- ) {
- if (query.isEmpty()) {
- Text(
- stringResource(R.string.search_placeholder),
- style = MaterialTheme.typography.bodyLarge,
- color = InkDim,
- maxLines = 1,
- )
- }
- BasicTextField(
- value = query,
- onValueChange = onQueryChange,
- enabled = enabled,
- singleLine = true,
- textStyle = MaterialTheme.typography.bodyLarge.copy(color = Ink),
- cursorBrush = SolidColor(Ink),
- keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
- modifier = Modifier.fillMaxWidth(),
- )
- }
- if (query.isNotEmpty()) {
- Icon(
- PhosphorIcons.Regular.X,
- contentDescription = stringResource(R.string.clear),
- tint = InkDim,
- modifier = Modifier
- .clip(RoundedCornerShape(50))
- .pressable({ onQueryChange("") }, pressedScale = 0.88f)
- .size(20.dp),
- )
- }
- }
-}
-
/** The same chips the home page filters with; see the note there. */
@Composable
private fun KindRow(selected: Kind, backdrop: Backdrop, onSelect: (Kind) -> Unit) {
@@ -266,10 +185,10 @@ private fun KindRow(selected: Kind, backdrop: Backdrop, onSelect: (Kind) -> Unit
LiquidButton(
onClick = { onSelect(entry) },
backdrop = backdrop,
+ flat = true,
contentHeight = 38.dp,
contentPadding = 18.dp,
- blurRadius = 8.dp,
- surfaceColor = if (isSelected) SelectedFilm else GlassFilm,
+ surfaceColor = if (isSelected) SelectedFilm else Color.Unspecified,
) {
Text(
stringResource(entry.label),
diff --git a/app/src/main/java/dev/lelonio/square/ui/settings/WebApiSetup.kt b/app/src/main/java/dev/lelonio/square/ui/settings/WebApiSetup.kt
index 9b278e7..a42602f 100644
--- a/app/src/main/java/dev/lelonio/square/ui/settings/WebApiSetup.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/settings/WebApiSetup.kt
@@ -19,7 +19,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
-import com.kyant.backdrop.Backdrop
+import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.R
import dev.lelonio.square.ui.MainViewModel
import dev.lelonio.square.ui.glass.LiquidButton
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 92eeb35..c3466ed 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -130,6 +130,8 @@
<string name="scope_private_playlists">Zu privaten Playlists hinzufügen</string>
<string name="scope_public_playlists">Zu öffentlichen Playlists hinzufügen</string>
<string name="enter_client_id">Gib die Client ID ein.</string>
+ <string name="add_to_library">Zur Bibliothek hinzufügen</string>
+ <string name="remove_from_library">Aus der Bibliothek entfernen</string>
<string name="artist_playlists">Playlists mit diesem Künstler</string>
<string name="singles_and_eps">Singles und EPs</string>
<string name="appears_on">Mit dabei auf</string>
@@ -241,7 +243,7 @@
<string name="page_app">App</string>
<string name="page_account_summary">Ihr Konto, die Web-API-Anwendung und das Abmelden</string>
<string name="page_playback_summary">Woher die Musik kommt, Qualität und Überblendung</string>
- <string name="page_app_summary">Sprache</string>
+ <string name="page_app_summary">Sprache, Glas und untere Leiste</string>
<string name="page_about_summary">Version, Berechtigungen, Lizenzen und Entwickler</string>
<string name="playing_on">Wiedergabe auf %1$s</string>
<string name="switching">Wechsel…</string>
@@ -256,4 +258,34 @@
<string name="pin">Oben anheften</string>
<string name="unpin">Lösen</string>
<string name="radio">Radio</string>
+
+ <string name="glass">Glas</string>
+ <string name="glass_performance">Am schnellsten</string>
+ <string name="glass_performance_note">Ein getönter Film, ohne etwas dahinter abzutasten. Kostet etwa so viel wie ein gezeichnetes Rechteck.</string>
+ <string name="glass_balanced">Ausgewogen</string>
+ <string name="glass_balanced_note">Milchglas und Brechung, in der Stärke, für die die App gestaltet wurde.</string>
+ <string name="glass_quality">Qualität</string>
+ <string name="glass_quality_note">Tieferes Milchglas, stärkere Brechung und Farbaufspaltung an den Kanten. Das Erste, was auf einem ausgelasteten Telefon Bilder kostet.</string>
+ <string name="glass_unsupported">Dieses Telefon hat keine Hardware-Unschärfe, daher nutzen alle Flächen den getönten Film.</string>
+ <string name="glass_advanced">Selbst einstellen</string>
+ <string name="glass_vibrancy">Farbe</string>
+ <string name="glass_blur">Milchglas</string>
+ <string name="glass_refraction_depth">Kantentiefe</string>
+ <string name="glass_refraction_amount">Krümmung</string>
+ <string name="glass_rim">Kantenlicht</string>
+ <string name="glass_film">Film</string>
+ <string name="glass_dispersion">Farbaufspaltung</string>
+ <string name="glass_dispersion_note">Licht, das sich an den Kanten in Farben zerlegt, wie in dickem Glas.</string>
+ <string name="glass_depth">Tiefe</string>
+ <string name="glass_depth_note">Lässt die Fläche wie eine dickere Platte wirken. Bei kleinen Bedienelementen kostet es mehr, als man sieht.</string>
+ <string name="glass_where_bar">Glas in der unteren Leiste</string>
+ <string name="glass_where_mini_player">Glas in der Wiedergabeleiste</string>
+ <string name="glass_where_player">Glas im Player</string>
+ <string name="glass_reset">Zurück zum Profil</string>
+
+ <string name="bar_folds">Leiste klappt ein</string>
+ <string name="bar_folds_note">Die untere Leiste schrumpft beim Scrollen zu einer Pille. Die teuerste Animation der App: ausgeschaltet läuft es auf älteren Telefonen runder.</string>
+ <string name="delete_playlist_title">Diese Playlist löschen?</string>
+ <string name="delete_playlist_message">%1$s verschwindet von allen Geräten dieses Kontos, und es gibt keinen Weg zurück.</string>
+ <string name="glass_indicator">Aktiver Tab</string>
</resources>
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 67387f6..14cbef9 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -130,6 +130,8 @@
<string name="scope_private_playlists">Añadir a playlists privadas</string>
<string name="scope_public_playlists">Añadir a playlists públicas</string>
<string name="enter_client_id">Introduce el client ID.</string>
+ <string name="add_to_library">Añadir a la biblioteca</string>
+ <string name="remove_from_library">Quitar de la biblioteca</string>
<string name="artist_playlists">Listas con este artista</string>
<string name="singles_and_eps">Sencillos y EP</string>
<string name="appears_on">Aparece en</string>
@@ -241,7 +243,7 @@
<string name="page_app">Aplicación</string>
<string name="page_account_summary">Tu cuenta, la aplicación de la Web API y cerrar sesión</string>
<string name="page_playback_summary">De dónde viene la música, calidad y fundido</string>
- <string name="page_app_summary">Idioma</string>
+ <string name="page_app_summary">Idioma, cristal y barra inferior</string>
<string name="page_about_summary">Versión, permisos, licencias y desarrollador</string>
<string name="playing_on">Reproduciendo en %1$s</string>
<string name="switching">Cambiando…</string>
@@ -256,4 +258,34 @@
<string name="pin">Fijar arriba</string>
<string name="unpin">Quitar de arriba</string>
<string name="radio">Radio</string>
+
+ <string name="glass">Cristal</string>
+ <string name="glass_performance">Más rápido</string>
+ <string name="glass_performance_note">Una película teñida, sin muestrear nada de lo que hay detrás. Cuesta lo que dibujar un rectángulo.</string>
+ <string name="glass_balanced">Equilibrado</string>
+ <string name="glass_balanced_note">Escarcha y refracción, con la intensidad para la que se diseñó la aplicación.</string>
+ <string name="glass_quality">Calidad</string>
+ <string name="glass_quality_note">Más escarcha, más refracción y color que se separa en los bordes. Lo primero que cuesta fotogramas en un teléfono ocupado.</string>
+ <string name="glass_unsupported">Este teléfono no tiene desenfoque por hardware, así que todas las superficies usan la película teñida.</string>
+ <string name="glass_advanced">Ajústalo tú</string>
+ <string name="glass_vibrancy">Color</string>
+ <string name="glass_blur">Escarcha</string>
+ <string name="glass_refraction_depth">Profundidad del borde</string>
+ <string name="glass_refraction_amount">Curvatura</string>
+ <string name="glass_rim">Luz del borde</string>
+ <string name="glass_film">Película</string>
+ <string name="glass_dispersion">Separación de color</string>
+ <string name="glass_dispersion_note">La luz que se descompone en colores en los bordes, como en el vidrio grueso.</string>
+ <string name="glass_depth">Profundidad</string>
+ <string name="glass_depth_note">Hace que la superficie parezca una lámina más gruesa. En controles pequeños cuesta más de lo que se ve.</string>
+ <string name="glass_where_bar">Cristal en la barra inferior</string>
+ <string name="glass_where_mini_player">Cristal en la barra de reproducción</string>
+ <string name="glass_where_player">Cristal en el reproductor</string>
+ <string name="glass_reset">Volver al perfil</string>
+
+ <string name="bar_folds">La barra se pliega</string>
+ <string name="bar_folds_note">La barra inferior se encoge en una píldora al desplazarte. Es la animación más costosa de la aplicación: desactivarla va más fluido en teléfonos antiguos.</string>
+ <string name="delete_playlist_title">¿Eliminar esta lista?</string>
+ <string name="delete_playlist_message">%1$s desaparecerá de todos los dispositivos de esta cuenta, y no hay vuelta atrás.</string>
+ <string name="glass_indicator">Pestaña activa</string>
</resources>
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index cbfb3fb..429ddac 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -130,6 +130,8 @@
<string name="scope_private_playlists">Ajouter aux playlists privées</string>
<string name="scope_public_playlists">Ajouter aux playlists publiques</string>
<string name="enter_client_id">Saisissez le client ID.</string>
+ <string name="add_to_library">Ajouter à la bibliothèque</string>
+ <string name="remove_from_library">Retirer de la bibliothèque</string>
<string name="artist_playlists">Playlists avec cet artiste</string>
<string name="singles_and_eps">Singles et EP</string>
<string name="appears_on">Apparaît sur</string>
@@ -241,7 +243,7 @@
<string name="page_app">Application</string>
<string name="page_account_summary">Votre compte, l’application Web API et la déconnexion</string>
<string name="page_playback_summary">D’où vient la musique, qualité et fondu enchaîné</string>
- <string name="page_app_summary">Langue</string>
+ <string name="page_app_summary">Langue, verre et barre du bas</string>
<string name="page_about_summary">Version, autorisations, licences et développeur</string>
<string name="playing_on">Lecture sur %1$s</string>
<string name="switching">Transfert…</string>
@@ -256,4 +258,34 @@
<string name="pin">Épingler en haut</string>
<string name="unpin">Désépingler</string>
<string name="radio">Radio</string>
+
+ <string name="glass">Verre</string>
+ <string name="glass_performance">Le plus rapide</string>
+ <string name="glass_performance_note">Un film teinté, sans rien prélever derrière. Coûte à peu près autant que dessiner un rectangle.</string>
+ <string name="glass_balanced">Équilibré</string>
+ <string name="glass_balanced_note">Givre et réfraction, aux intensités pour lesquelles l\'application a été conçue.</string>
+ <string name="glass_quality">Qualité</string>
+ <string name="glass_quality_note">Givre plus profond, réfraction plus forte et couleurs qui se séparent sur les bords. La première chose qui coûte des images sur un téléphone chargé.</string>
+ <string name="glass_unsupported">Ce téléphone n\'a pas de flou matériel : toutes les surfaces utilisent le film teinté.</string>
+ <string name="glass_advanced">Régler soi-même</string>
+ <string name="glass_vibrancy">Couleur</string>
+ <string name="glass_blur">Givre</string>
+ <string name="glass_refraction_depth">Profondeur du bord</string>
+ <string name="glass_refraction_amount">Courbure</string>
+ <string name="glass_rim">Lumière du bord</string>
+ <string name="glass_film">Film</string>
+ <string name="glass_dispersion">Séparation des couleurs</string>
+ <string name="glass_dispersion_note">La lumière qui se décompose en couleurs sur les bords, comme dans le verre épais.</string>
+ <string name="glass_depth">Profondeur</string>
+ <string name="glass_depth_note">Donne à la surface l\'épaisseur d\'une dalle. Sur les petits contrôles, coûte plus qu\'il ne se voit.</string>
+ <string name="glass_where_bar">Verre sur la barre du bas</string>
+ <string name="glass_where_mini_player">Verre sur la barre de lecture</string>
+ <string name="glass_where_player">Verre dans le lecteur</string>
+ <string name="glass_reset">Revenir au profil</string>
+
+ <string name="bar_folds">La barre se replie</string>
+ <string name="bar_folds_note">La barre du bas se réduit en pastille quand vous faites défiler. C\'est l\'animation la plus coûteuse de l\'application : la désactiver est plus fluide sur les téléphones anciens.</string>
+ <string name="delete_playlist_title">Supprimer cette playlist ?</string>
+ <string name="delete_playlist_message">%1$s disparaîtra de tous les appareils de ce compte, sans retour possible.</string>
+ <string name="glass_indicator">Onglet actif</string>
</resources>
diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml
index 0485f32..feb9bbb 100644
--- a/app/src/main/res/values-hi/strings.xml
+++ b/app/src/main/res/values-hi/strings.xml
@@ -142,6 +142,8 @@
<string name="scope_private_playlists">निजी प्लेलिस्ट में जोड़ना</string>
<string name="scope_public_playlists">सार्वजनिक प्लेलिस्ट में जोड़ना</string>
<string name="enter_client_id">क्लाइंट आईडी डालें।</string>
+ <string name="add_to_library">लाइब्रेरी में जोड़ें</string>
+ <string name="remove_from_library">लाइब्रेरी से हटाएँ</string>
<string name="artist_playlists">इस कलाकार की प्लेलिस्ट</string>
<string name="singles_and_eps">सिंगल और EP</string>
<string name="appears_on">इनमें शामिल</string>
@@ -256,7 +258,7 @@
<string name="page_app">ऐप</string>
<string name="page_account_summary">आपका खाता, Web API ऐप्लिकेशन और साइन आउट</string>
<string name="page_playback_summary">संगीत का स्रोत, गुणवत्ता और क्रॉसफ़ेड</string>
- <string name="page_app_summary">भाषा</string>
+ <string name="page_app_summary">भाषा, काँच और नीचे की पट्टी</string>
<string name="page_about_summary">संस्करण, अनुमतियाँ, लाइसेंस और डेवलपर</string>
<string name="playing_on">%1$s पर चल रहा है</string>
<string name="switching">बदला जा रहा है…</string>
@@ -271,4 +273,34 @@
<string name="pin">ऊपर पिन करें</string>
<string name="unpin">पिन हटाएँ</string>
<string name="radio">रेडियो</string>
+
+ <string name="glass">काँच</string>
+ <string name="glass_performance">सबसे तेज़</string>
+ <string name="glass_performance_note">एक रंगी हुई परत, पीछे से कुछ भी लिए बिना। लागत बस एक आयत बनाने जितनी।</string>
+ <string name="glass_balanced">संतुलित</string>
+ <string name="glass_balanced_note">धुंध और अपवर्तन, उसी मात्रा में जिसके लिए ऐप बनाया गया है।</string>
+ <string name="glass_quality">गुणवत्ता</string>
+ <string name="glass_quality_note">गहरी धुंध, तेज़ अपवर्तन और किनारों पर रंगों का बँटवारा। व्यस्त फ़ोन पर सबसे पहले यही फ़्रेम खाता है।</string>
+ <string name="glass_unsupported">इस फ़ोन में हार्डवेयर ब्लर नहीं है, इसलिए हर सतह रंगी हुई परत का उपयोग करती है।</string>
+ <string name="glass_advanced">खुद समायोजित करें</string>
+ <string name="glass_vibrancy">रंग</string>
+ <string name="glass_blur">धुंध</string>
+ <string name="glass_refraction_depth">किनारे की गहराई</string>
+ <string name="glass_refraction_amount">मोड़</string>
+ <string name="glass_rim">किनारे की रोशनी</string>
+ <string name="glass_film">परत</string>
+ <string name="glass_dispersion">रंगों का बँटवारा</string>
+ <string name="glass_dispersion_note">मोटे काँच की तरह, किनारों पर रोशनी का रंगों में टूटना।</string>
+ <string name="glass_depth">गहराई</string>
+ <string name="glass_depth_note">सतह को मोटी पट्टी जैसा दिखाता है। छोटे नियंत्रणों पर दिखने से ज़्यादा खर्च करता है।</string>
+ <string name="glass_where_bar">नीचे की पट्टी पर काँच</string>
+ <string name="glass_where_mini_player">चल रही पट्टी पर काँच</string>
+ <string name="glass_where_player">प्लेयर में काँच</string>
+ <string name="glass_reset">प्रोफ़ाइल पर लौटें</string>
+
+ <string name="bar_folds">पट्टी सिमटती है</string>
+ <string name="bar_folds_note">स्क्रॉल करने पर नीचे की पट्टी सिकुड़कर गोली बन जाती है। यह ऐप का सबसे महँगा एनिमेशन है: बंद रखने पर पुराने फ़ोन पर ज़्यादा सहज चलता है।</string>
+ <string name="delete_playlist_title">यह प्लेलिस्ट हटाएँ?</string>
+ <string name="delete_playlist_message">%1$s इस खाते के हर डिवाइस से चली जाएगी, और वापस लाने का कोई तरीका नहीं है।</string>
+ <string name="glass_indicator">सक्रिय टैब</string>
</resources>
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index 1dd8c57..57f7755 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -131,6 +131,8 @@
<string name="scope_private_playlists">Aggiungi a playlist private</string>
<string name="scope_public_playlists">Aggiungi a playlist pubbliche</string>
<string name="enter_client_id">Inserisci il client id.</string>
+ <string name="add_to_library">Aggiungi alla libreria</string>
+ <string name="remove_from_library">Togli dalla libreria</string>
<string name="artist_playlists">Playlist con questo artista</string>
<string name="singles_and_eps">Singoli ed EP</string>
<string name="appears_on">Compare in</string>
@@ -242,7 +244,7 @@
<string name="page_app">App</string>
<string name="page_account_summary">Il tuo account, l’applicazione Web API e la disconnessione</string>
<string name="page_playback_summary">Da dove arriva la musica, qualità e dissolvenza</string>
- <string name="page_app_summary">Lingua</string>
+ <string name="page_app_summary">Lingua, vetro e barra in basso</string>
<string name="page_about_summary">Versione, permessi, licenze e sviluppatore</string>
<string name="playing_on">In riprod. su %1$s</string>
<string name="switching">Passaggio in corso…</string>
@@ -257,4 +259,34 @@
<string name="pin">Fissa in alto</string>
<string name="unpin">Togli dall\'alto</string>
<string name="radio">Radio</string>
+
+ <string name="glass">Vetro</string>
+ <string name="glass_performance">Più veloce</string>
+ <string name="glass_performance_note">Una pellicola colorata, senza niente campionato da dietro. Costa quanto disegnare un rettangolo.</string>
+ <string name="glass_balanced">Bilanciato</string>
+ <string name="glass_balanced_note">Brina e rifrazione, alle intensità per cui l\'app è stata disegnata.</string>
+ <string name="glass_quality">Qualità</string>
+ <string name="glass_quality_note">Brina più profonda, rifrazione più forte e colore che si separa ai bordi. La prima cosa che costa fotogrammi su un telefono impegnato.</string>
+ <string name="glass_unsupported">Questo telefono non ha la sfocatura hardware, quindi ogni superficie usa la pellicola colorata.</string>
+ <string name="glass_advanced">Regolalo tu</string>
+ <string name="glass_vibrancy">Colore</string>
+ <string name="glass_blur">Brina</string>
+ <string name="glass_refraction_depth">Profondità del bordo</string>
+ <string name="glass_refraction_amount">Curvatura</string>
+ <string name="glass_rim">Luce sul bordo</string>
+ <string name="glass_film">Pellicola</string>
+ <string name="glass_dispersion">Separazione dei colori</string>
+ <string name="glass_dispersion_note">La luce che si scompone in colori ai bordi, come nel vetro spesso.</string>
+ <string name="glass_depth">Profondità</string>
+ <string name="glass_depth_note">Fa sembrare la superficie una lastra più spessa. Sui controlli piccoli costa più di quanto si veda.</string>
+ <string name="glass_where_bar">Vetro nella barra in basso</string>
+ <string name="glass_where_mini_player">Vetro nella barra di riproduzione</string>
+ <string name="glass_where_player">Vetro nel player</string>
+ <string name="glass_reset">Torna al profilo</string>
+
+ <string name="bar_folds">La barra si richiude</string>
+ <string name="bar_folds_note">La barra in basso si stringe in una pillola mentre scorri. È l\'animazione più costosa dell\'app: disattivarla è più fluido sui telefoni vecchi.</string>
+ <string name="delete_playlist_title">Eliminare questa playlist?</string>
+ <string name="delete_playlist_message">%1$s sparirà da ogni dispositivo di questo account, e non si può tornare indietro.</string>
+ <string name="glass_indicator">Tab attiva</string>
</resources>
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index f6425fe..6791cba 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -130,6 +130,8 @@
<string name="scope_private_playlists">Adicionar a playlists privadas</string>
<string name="scope_public_playlists">Adicionar a playlists públicas</string>
<string name="enter_client_id">Informe o client ID.</string>
+ <string name="add_to_library">Adicionar à biblioteca</string>
+ <string name="remove_from_library">Remover da biblioteca</string>
<string name="artist_playlists">Playlists com este artista</string>
<string name="singles_and_eps">Singles e EP</string>
<string name="appears_on">Aparece em</string>
@@ -241,7 +243,7 @@
<string name="page_app">Aplicativo</string>
<string name="page_account_summary">Sua conta, o aplicativo da Web API e sair</string>
<string name="page_playback_summary">De onde vem a música, qualidade e transição</string>
- <string name="page_app_summary">Idioma</string>
+ <string name="page_app_summary">Idioma, vidro e barra inferior</string>
<string name="page_about_summary">Versão, permissões, licenças e desenvolvedor</string>
<string name="playing_on">Reproduzindo em %1$s</string>
<string name="switching">Trocando…</string>
@@ -256,4 +258,34 @@
<string name="pin">Fixar no topo</string>
<string name="unpin">Desafixar</string>
<string name="radio">Rádio</string>
+
+ <string name="glass">Vidro</string>
+ <string name="glass_performance">Mais rápido</string>
+ <string name="glass_performance_note">Uma película colorida, sem amostrar nada por trás. Custa o mesmo que desenhar um retângulo.</string>
+ <string name="glass_balanced">Equilibrado</string>
+ <string name="glass_balanced_note">Fosco e refração, nas intensidades para que a aplicação foi desenhada.</string>
+ <string name="glass_quality">Qualidade</string>
+ <string name="glass_quality_note">Fosco mais profundo, refração mais forte e cor a separar-se nas bordas. A primeira coisa a custar fotogramas num telemóvel ocupado.</string>
+ <string name="glass_unsupported">Este telemóvel não tem desfoque por hardware, por isso todas as superfícies usam a película colorida.</string>
+ <string name="glass_advanced">Ajustar manualmente</string>
+ <string name="glass_vibrancy">Cor</string>
+ <string name="glass_blur">Fosco</string>
+ <string name="glass_refraction_depth">Profundidade da borda</string>
+ <string name="glass_refraction_amount">Curvatura</string>
+ <string name="glass_rim">Luz da borda</string>
+ <string name="glass_film">Película</string>
+ <string name="glass_dispersion">Separação de cor</string>
+ <string name="glass_dispersion_note">A luz a decompor-se em cores nas bordas, como no vidro espesso.</string>
+ <string name="glass_depth">Profundidade</string>
+ <string name="glass_depth_note">Faz a superfície parecer uma placa mais espessa. Em controlos pequenos custa mais do que se vê.</string>
+ <string name="glass_where_bar">Vidro na barra inferior</string>
+ <string name="glass_where_mini_player">Vidro na barra de reprodução</string>
+ <string name="glass_where_player">Vidro no reprodutor</string>
+ <string name="glass_reset">Voltar ao perfil</string>
+
+ <string name="bar_folds">A barra recolhe-se</string>
+ <string name="bar_folds_note">A barra inferior encolhe para uma cápsula enquanto percorre. É a animação mais cara da aplicação: desligada é mais fluida em telemóveis antigos.</string>
+ <string name="delete_playlist_title">Eliminar esta playlist?</string>
+ <string name="delete_playlist_message">%1$s vai desaparecer de todos os dispositivos desta conta, e não há forma de voltar atrás.</string>
+ <string name="glass_indicator">Separador ativo</string>
</resources>
diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml
index 4a2fcae..f8f1ff0 100644
--- a/app/src/main/res/values-tr/strings.xml
+++ b/app/src/main/res/values-tr/strings.xml
@@ -142,6 +142,8 @@
<string name="scope_private_playlists">Özel çalma listelerine ekleme</string>
<string name="scope_public_playlists">Herkese açık listelere ekleme</string>
<string name="enter_client_id">İstemci kimliğini gir.</string>
+ <string name="add_to_library">Kitaplığa ekle</string>
+ <string name="remove_from_library">Kitaplıktan kaldır</string>
<string name="artist_playlists">Bu sanatçının çalma listeleri</string>
<string name="singles_and_eps">Single ve EP</string>
<string name="appears_on">Yer aldığı albümler</string>
@@ -256,7 +258,7 @@
<string name="page_app">Uygulama</string>
<string name="page_account_summary">Hesabın, Web API uygulaması ve çıkış</string>
<string name="page_playback_summary">Müziğin kaynağı, kalite ve çapraz geçiş</string>
- <string name="page_app_summary">Dil</string>
+ <string name="page_app_summary">Dil, cam ve alt çubuk</string>
<string name="page_about_summary">Sürüm, izinler, lisanslar ve geliştirici</string>
<string name="playing_on">%1$s cihazında çalıyor</string>
<string name="switching">Geçiliyor…</string>
@@ -271,4 +273,34 @@
<string name="pin">Yukarı sabitle</string>
<string name="unpin">Sabitlemeyi kaldır</string>
<string name="radio">Radyo</string>
+
+ <string name="glass">Cam</string>
+ <string name="glass_performance">En hızlı</string>
+ <string name="glass_performance_note">Renkli bir film; arkasından hiçbir şey örneklenmez. Bir dikdörtgen çizmek kadar maliyetli.</string>
+ <string name="glass_balanced">Dengeli</string>
+ <string name="glass_balanced_note">Buzlanma ve kırılma, uygulamanın tasarlandığı şiddetlerde.</string>
+ <string name="glass_quality">Kalite</string>
+ <string name="glass_quality_note">Daha derin buzlanma, daha güçlü kırılma ve kenarlarda renk ayrışması. Yoğun bir telefonda kare kaybettiren ilk şey.</string>
+ <string name="glass_unsupported">Bu telefonda donanımsal bulanıklık yok, bu yüzden tüm yüzeyler renkli filmi kullanıyor.</string>
+ <string name="glass_advanced">Kendin ayarla</string>
+ <string name="glass_vibrancy">Renk</string>
+ <string name="glass_blur">Buzlanma</string>
+ <string name="glass_refraction_depth">Kenar derinliği</string>
+ <string name="glass_refraction_amount">Bükülme</string>
+ <string name="glass_rim">Kenar ışığı</string>
+ <string name="glass_film">Film</string>
+ <string name="glass_dispersion">Renk ayrışması</string>
+ <string name="glass_dispersion_note">Kalın camda olduğu gibi, kenarlarda ışığın renklere ayrılması.</string>
+ <string name="glass_depth">Derinlik</string>
+ <string name="glass_depth_note">Yüzeyi daha kalın bir levha gibi gösterir. Küçük denetimlerde göründüğünden fazlasına mal olur.</string>
+ <string name="glass_where_bar">Alt çubukta cam</string>
+ <string name="glass_where_mini_player">Çalma çubuğunda cam</string>
+ <string name="glass_where_player">Oynatıcıda cam</string>
+ <string name="glass_reset">Profile dön</string>
+
+ <string name="bar_folds">Çubuk katlanır</string>
+ <string name="bar_folds_note">Alt çubuk kaydırdıkça bir hapa küçülür. Uygulamanın en pahalı animasyonu: kapalıyken eski telefonlarda daha akıcı.</string>
+ <string name="delete_playlist_title">Bu çalma listesi silinsin mi?</string>
+ <string name="delete_playlist_message">%1$s bu hesaptaki tüm cihazlardan kaybolacak ve geri dönüşü yok.</string>
+ <string name="glass_indicator">Etkin sekme</string>
</resources>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 50057c6..7af7c3e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -148,6 +148,8 @@
<string name="scope_private_playlists">Add to private playlists</string>
<string name="scope_public_playlists">Add to public playlists</string>
<string name="enter_client_id">Enter the client ID.</string>
+ <string name="add_to_library">Add to library</string>
+ <string name="remove_from_library">Remove from library</string>
<string name="artist_playlists">Playlists with this artist</string>
<string name="singles_and_eps">Singles and EPs</string>
<string name="appears_on">Appears on</string>
@@ -262,7 +264,7 @@
<string name="page_app">App</string>
<string name="page_account_summary">Your account, the Web API application and signing out</string>
<string name="page_playback_summary">Where music comes from, quality and crossfade</string>
- <string name="page_app_summary">Language</string>
+ <string name="page_app_summary">Language, glass and the bottom bar</string>
<string name="page_about_summary">Version, permissions, licences and the developer</string>
<string name="playing_on">Playing on %1$s</string>
<string name="switching">Switching…</string>
@@ -277,4 +279,34 @@
<string name="pin">Pin to the top</string>
<string name="unpin">Unpin</string>
<string name="radio">Radio</string>
+
+ <string name="glass">Glass</string>
+ <string name="glass_performance">Fastest</string>
+ <string name="glass_performance_note">A tinted film, with nothing sampled from behind it. Costs about as much as drawing a rectangle.</string>
+ <string name="glass_balanced">Balanced</string>
+ <string name="glass_balanced_note">Frost and refraction, at the strengths the app was designed against.</string>
+ <string name="glass_quality">Quality</string>
+ <string name="glass_quality_note">Deeper frost, stronger refraction and colour splitting at the edges. The first thing to cost frames on a busy phone.</string>
+ <string name="glass_unsupported">This phone has no hardware blur, so every surface uses the tinted film.</string>
+ <string name="glass_advanced">Adjust it yourself</string>
+ <string name="glass_vibrancy">Colour</string>
+ <string name="glass_blur">Frost</string>
+ <string name="glass_refraction_depth">Edge depth</string>
+ <string name="glass_refraction_amount">Bend</string>
+ <string name="glass_rim">Edge light</string>
+ <string name="glass_film">Film</string>
+ <string name="glass_dispersion">Colour splitting</string>
+ <string name="glass_dispersion_note">Light breaking into colour at the edges, as thick glass does.</string>
+ <string name="glass_depth">Depth</string>
+ <string name="glass_depth_note">Makes the surface read as a thicker slab. Costs more than it shows on small controls.</string>
+ <string name="glass_where_bar">Glass on the bottom bar</string>
+ <string name="glass_where_mini_player">Glass on the playing bar</string>
+ <string name="glass_where_player">Glass in the player</string>
+ <string name="glass_reset">Back to the profile</string>
+
+ <string name="bar_folds">Bar folds away</string>
+ <string name="bar_folds_note">The bottom bar shrinks to a pill as you scroll. The app\'s most expensive animation: off is smoother on older phones.</string>
+ <string name="delete_playlist_title">Delete this playlist?</string>
+ <string name="delete_playlist_message">%1$s will be gone from every device on this account, and there is no way back.</string>
+ <string name="glass_indicator">Active tab</string>
</resources>