Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.
Rust androiddocument-scannerdocximage-editorjetpack-composekotlinliquid-glassofflineopen-sourcepdfpdf-compressorpdf-editorpdf-mergerpdf-readerpdf-splitterpdf-toolspdf-viewerpptxspreadsheet-editorxlsx
iOS 27-style jelly press and menu unfold
chethan616eaabf853f873
diff --git a/DESIGN.md b/DESIGN.mdindex f0bf49a..f5dc6c6 100644--- a/DESIGN.md+++ b/DESIGN.md@@ -87,9 +87,23 @@ Use the shared springs in `GlassMotion` (or springs close to them):|---|---|| `GlassMotion.morph()` (0.58, 420) | Things that spring open: capsules, chevrons, thumbs || `GlassMotion.pop()` (0.45, 500) | Small things landing (icons, beads, toasts) |-| `GlassMotion.press()` (0.42, Medium) | Press down and back |+| `GlassMotion.press()` (0.5, 700) | Value-driven press (prefer `rememberJellyPress`) |+| `GlassMotion.pressIn()` / `pressOut()` | Finger down (0.72, 900) / finger up (0.46, 420): one small overshoot past rest |+| `GlassMotion.wobble()` (0.42, 420) | The release jiggle on glass: X and Y squash out of phase, one visible swing |+| `GlassMotion.unfold()` / `unfoldLag()` / `fold()` | Menus: width (0.68, 420), height a beat behind (0.6, 340), close (1, 900) || `GlassMotion.settle()` / `fade()` | Alpha and layout. Critically damped, never bouncy |+**Press jelly (the iOS 27 feel).**+- Glass buttons (`LiquidButton`, `LiquidIconButton`) share `liquidPressTransform`. The button swells+ ~4 dp under the finger and leans toward a dragging finger. On release it springs back and jiggles once,+ about 2.5 dp, with X and Y out of phase.+- Flat pressables (rows, chips, toolbar items, menu actions) use `rememberJellyPress(interaction)` and+ read `jelly.scale` in `graphicsLayer`. Never use `animateFloatAsState(if (pressed) ...)`: in a scrolling+ list a quick tap's Press and Release arrive together, so the dip never shows.+- A tap shorter than `GlassMotion.MinPressMillis` (90 ms) still plays the whole press before releasing.+- Menus unfold from their anchor with anisotropic scale (the width first, then the height) and fold back+ fast without a bounce. Rows cascade in behind the unfold.+- **Alpha never bounces.** Clamp it (`coerceIn(0f, 1f)`) or drive it with `settle`.- Stagger lists about 20–30 ms per item, and cap the stagger so long lists don't trail.- Use **one animation per element**. Derive scale, offset and alpha from one progress value ratherdiff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassCapsuleMenu.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassCapsuleMenu.ktindex d0a2bed..40cd4ec 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassCapsuleMenu.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassCapsuleMenu.kt@@ -1,12 +1,10 @@package com.chethan616.clearpdf.ui.components-import androidx.compose.animation.core.Spring-import androidx.compose.animation.core.animateFloatAsState+import androidx.compose.runtime.getValueimport androidx.compose.animation.core.springimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.clickableimport androidx.compose.foundation.interaction.MutableInteractionSource-import androidx.compose.foundation.interaction.collectIsPressedAsStateimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Row@@ -15,7 +13,6 @@ import androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.shape.CircleShapeimport androidx.compose.material3.Iconimport androidx.compose.runtime.Composable-import androidx.compose.runtime.getValueimport androidx.compose.runtime.rememberimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifier@@ -34,8 +31,6 @@ import com.kyant.backdrop.effects.lensimport com.kyant.backdrop.effects.vibrancyimport com.kyant.backdrop.highlight.Highlightimport com.kyant.backdrop.highlight.HighlightStyle-import com.kyant.backdrop.shadow.InnerShadow-import com.kyant.backdrop.shadow.Shadowimport com.kyant.shapes.Capsule/** One circular action inside a [GlassCapsuleMenu]. */@@ -117,18 +112,13 @@ fun GlassCapsuleMenu(@Composableprivate fun CapsuleAction(action: GlassMenuAction, local: Float) {val interaction = remember { MutableInteractionSource() }- val pressed by interaction.collectIsPressedAsState()- val press by animateFloatAsState(- if (pressed) 0.90f else 1f,- spring(dampingRatio = 0.6f, stiffness = Spring.StiffnessMedium),- label = "capsuleActionPress"- )+ val jelly = rememberJellyPress(interaction, pressedScale = 0.90f)Box(Modifier.size(ActionSize).graphicsLayer {- val s = lerp(0.4f, 1f, local) * press+ val s = lerp(0.4f, 1f, local) * jelly.scalescaleX = sscaleY = salpha = localdiff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassMotion.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassMotion.ktindex 42999cf..de7ac02 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassMotion.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassMotion.kt@@ -14,6 +14,11 @@ import androidx.compose.animation.core.spring* which forces `drawBackdrop` to re-run its blur and lens at a new size. So [morph] is used for* scale, [settle] for anything that changes real size, and [fade] for alpha — a bouncing alpha just* reads as a flicker.+ *+ * Press physics (iOS 26/27 Liquid Glass): the finger lands on [pressIn] (fast, barely overshoots, so+ * the press reads instantly), lifts on [pressOut] (springs once past rest, then settles), and glass+ * controls add a [wobble] (X and Y squash out of phase, one visible swing). A tap shorter than+ * [MinPressMillis] still shows the full press before it springs back.*/object GlassMotion {@@ -29,9 +34,30 @@ object GlassMotion {/** Alias of [settle], named for intent at call sites that animate opacity. */fun <T> fade(): SpringSpec<T> = settle()- /** Press-down and bounce-back, matching LiquidButton's deformation. */- fun <T> press(): SpringSpec<T> = spring(dampingRatio = 0.42f, stiffness = Spring.StiffnessMedium)+ /** Press-down and bounce-back for value-driven presses (prefer [rememberJellyPress]). */+ fun <T> press(): SpringSpec<T> = spring(dampingRatio = 0.5f, stiffness = 700f)++ /** Finger down: quick and nearly critically damped, so the press lands in ~80 ms. */+ fun <T> pressIn(): SpringSpec<T> = spring(dampingRatio = 0.72f, stiffness = 900f)++ /** Finger up: springs back past rest once (~2 % of the dip) and settles. */+ fun <T> pressOut(): SpringSpec<T> = spring(dampingRatio = 0.46f, stiffness = 420f)++ /** Release jiggle for glass: one visible out-of-phase squash, the second swing is ~20 %. */+ fun <T> wobble(): SpringSpec<T> = spring(dampingRatio = 0.42f, stiffness = 420f)++ /** Menus and popovers unfolding from their anchor: ~5 % overshoot, settled in ~350 ms. */+ fun <T> unfold(): SpringSpec<T> = spring(dampingRatio = 0.68f, stiffness = 420f)++ /** The trailing axis of an unfold: a touch softer, so the panel lands like a drop of gel. */+ fun <T> unfoldLag(): SpringSpec<T> = spring(dampingRatio = 0.6f, stiffness = 340f)++ /** Folding away: fast and critically damped. Dismissals never bounce. */+ fun <T> fold(): SpringSpec<T> = spring(dampingRatio = 1f, stiffness = 900f)/** Uniform pressed scale for tiles, rows and morphing buttons. */const val PressedScale = 0.94f++ /** A tap shorter than this still shows the whole press before releasing. */+ const val MinPressMillis = 90L}diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassToolbar.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassToolbar.ktindex c03c010..a9425e4 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassToolbar.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassToolbar.kt@@ -1,12 +1,11 @@package com.chethan616.clearpdf.ui.components+import androidx.compose.runtime.getValueimport androidx.compose.animation.animateColorAsState-import androidx.compose.animation.core.animateFloatAsStateimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.clickableimport androidx.compose.foundation.horizontalScrollimport androidx.compose.foundation.interaction.MutableInteractionSource-import androidx.compose.foundation.interaction.collectIsPressedAsStateimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column@@ -21,7 +20,6 @@ import androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.foundation.text.BasicTextimport androidx.compose.material3.Iconimport androidx.compose.runtime.Composable-import androidx.compose.runtime.getValueimport androidx.compose.runtime.rememberimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifier@@ -51,8 +49,6 @@ import com.kyant.backdrop.effects.blurimport com.kyant.backdrop.effects.lensimport com.kyant.backdrop.effects.vibrancyimport com.kyant.backdrop.highlight.Highlight-import com.kyant.backdrop.shadow.InnerShadow-import com.kyant.backdrop.shadow.Shadowimport com.kyant.shapes.Capsule/**@@ -137,12 +133,7 @@ fun GlassToolButton(val isDark = LocalIsDarkMode.currentval haptics = LocalHapticFeedback.currentval interaction = remember { MutableInteractionSource() }- val pressed by interaction.collectIsPressedAsState()- val scale by animateFloatAsState(- if (pressed) GlassMotion.PressedScale else 1f,- GlassMotion.press(),- label = "toolPress"- )+ val jelly = rememberJellyPress(interaction)val fg by animateColorAsState(if (selected) accent else LiquidGlassColors.text(isDark),GlassMotion.settle(),@@ -156,8 +147,8 @@ fun GlassToolButton(Column(modifier.graphicsLayer {- scaleX = scale- scaleY = scale+ scaleX = jelly.scale+ scaleY = jelly.scalealpha = if (enabled) 1f else 0.38f}.defaultMinSize(minWidth = 52.dp, minHeight = 48.dp)diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/JellyPress.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/JellyPress.ktnew file mode 100644index 0000000..c61c4d6--- /dev/null+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/JellyPress.kt@@ -0,0 +1,85 @@+package com.chethan616.clearpdf.ui.components++import android.os.SystemClock+import androidx.compose.animation.core.Animatable+import androidx.compose.foundation.interaction.InteractionSource+import androidx.compose.foundation.interaction.PressInteraction+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.Stable+import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberCoroutineScope+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Job+import kotlinx.coroutines.delay+import kotlinx.coroutines.launch++/**+ * The press "jelly" for flat pressables (rows, chips, toolbar items): dips on [GlassMotion.pressIn],+ * springs back on [GlassMotion.pressOut] with one small overshoot, and holds a quick tap for+ * [GlassMotion.MinPressMillis] so it is never swallowed. In a scrolling list Compose reports a quick+ * tap's Press and Release together, which with a plain `animateFloatAsState` showed no dip at all.+ *+ * Read [scale] inside `graphicsLayer {}` so the animation stays in the draw phase.+ */+@Stable+class JellyPress internal constructor(+ private val scope: CoroutineScope,+ private val pressedScale: Float+) {+ private val anim = Animatable(1f, 0.0005f)+ private var downAt = 0L+ private var releaseJob: Job? = null++ val scale: Float get() = anim.value++ fun press() {+ releaseJob?.cancel()+ downAt = SystemClock.uptimeMillis()+ scope.launch { anim.animateTo(pressedScale, GlassMotion.pressIn()) }+ }++ fun release() {+ releaseJob?.cancel()+ releaseJob = scope.launch {+ val held = SystemClock.uptimeMillis() - downAt+ if (held < GlassMotion.MinPressMillis) delay(GlassMotion.MinPressMillis - held)+ anim.animateTo(1f, GlassMotion.pressOut())+ }+ }+}++/** Jelly driven by an [InteractionSource] (the one passed to `clickable`). */+@Composable+fun rememberJellyPress(+ interaction: InteractionSource,+ pressedScale: Float = GlassMotion.PressedScale+): JellyPress {+ val scope = rememberCoroutineScope()+ val jelly = remember(scope, pressedScale) { JellyPress(scope, pressedScale) }+ LaunchedEffect(interaction, jelly) {+ interaction.interactions.collect { i ->+ when (i) {+ is PressInteraction.Press -> jelly.press()+ is PressInteraction.Release, is PressInteraction.Cancel -> jelly.release()+ }+ }+ }+ return jelly+}++/** Jelly driven by a pressed flag, for controls with their own gesture detector. */+@Composable+fun rememberJellyPress(+ pressed: Boolean,+ pressedScale: Float = GlassMotion.PressedScale+): JellyPress {+ val scope = rememberCoroutineScope()+ val jelly = remember(scope, pressedScale) { JellyPress(scope, pressedScale) }+ val first = remember { booleanArrayOf(true) }+ LaunchedEffect(pressed) {+ if (first[0]) { first[0] = false; if (!pressed) return@LaunchedEffect }+ if (pressed) jelly.press() else jelly.release()+ }+ return jelly+}diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidButton.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidButton.ktindex eba0a1d..77499b7 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidButton.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidButton.kt@@ -1,5 +1,6 @@package com.chethan616.clearpdf.ui.components+import androidx.compose.runtime.getValueimport androidx.compose.foundation.clickableimport androidx.compose.foundation.LocalIndicationimport androidx.compose.foundation.layout.Arrangement@@ -8,7 +9,6 @@ import androidx.compose.foundation.layout.RowScopeimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.runtime.Composable-import androidx.compose.runtime.getValueimport androidx.compose.runtime.rememberimport androidx.compose.runtime.rememberCoroutineScopeimport androidx.compose.runtime.rememberUpdatedState@@ -22,20 +22,14 @@ import androidx.compose.ui.platform.LocalHapticFeedbackimport androidx.compose.ui.semantics.Roleimport androidx.compose.ui.unit.Dpimport androidx.compose.ui.unit.dp-import androidx.compose.ui.util.fastCoerceAtMost-import androidx.compose.ui.util.lerpimport com.chethan616.clearpdf.ui.utils.InteractiveHighlight+import com.chethan616.clearpdf.ui.utils.liquidPressTransformimport com.kyant.backdrop.Backdropimport com.kyant.backdrop.drawBackdropimport com.kyant.backdrop.effects.blurimport com.kyant.backdrop.effects.lensimport com.kyant.backdrop.effects.vibrancyimport com.kyant.shapes.Capsule-import kotlin.math.abs-import kotlin.math.atan2-import kotlin.math.cos-import kotlin.math.sin-import kotlin.math.tanhimport androidx.compose.material3.Iconimport androidx.compose.ui.graphics.vector.ImageVectorimport androidx.compose.ui.graphics.vector.PathParser@@ -110,34 +104,7 @@ fun LiquidButton(highlight = { glassHighlight(style) },onDrawBackdrop = if (flat != null) ({ _ -> drawFlatVibrantBackdrop(flat) }) else ({ it() }),layerBlock = if (isInteractive) {- {- val width = size.width- val height = size.height-- val progress = interactiveHighlight.pressProgress- // Long-press bloom: grows by at most ~14 dp along the long side (≤ 12 %), so a- // small chip pops playfully while a full-width button only swells a touch.- val bloom = interactiveHighlight.expandProgress *- (14f.dp.toPx() / size.maxDimension).fastCoerceAtMost(0.12f)- val scale = lerp(1f, 1f + 4f.dp.toPx() / size.height, progress) + bloom-- 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)- }+ { liquidPressTransform(interactiveHighlight) }} else {null},diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidGlassDropdown.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidGlassDropdown.ktindex 3bcfcec..66e5a1e 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidGlassDropdown.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidGlassDropdown.kt@@ -200,19 +200,27 @@ fun <T> LiquidGlassDropdown(modifier = Modifier.align(Alignment.TopStart).offset { menuOffset }) {val uiSensor = rememberUISensor()+ // Unfolds out of the trigger like iOS 27: width lands first, height follows on a+ // softer spring, so the panel settles like a drop of gel (one small overshoot).val reveal by transition.animateFloat(transitionSpec = {- if (targetState == EnterExitState.Visible) GlassMotion.pop() else GlassMotion.settle()+ if (targetState == EnterExitState.Visible) GlassMotion.unfold() else GlassMotion.fold()},label = "dropMenuReveal") { if (it == EnterExitState.Visible) 1f else 0f }+ val revealY by transition.animateFloat(+ transitionSpec = {+ if (targetState == EnterExitState.Visible) GlassMotion.unfoldLag() else GlassMotion.fold()+ },+ label = "dropMenuRevealY"+ ) { if (it == EnterExitState.Visible) 1f else 0f }Column(Modifier.width(menuWidth).graphicsLayer {alpha = reveal.coerceIn(0f, 1f)- translationY = (1f - reveal) * (-14.dp.toPx())- scaleY = 0.9f + 0.1f * reveal+ scaleX = 0.9f + 0.1f * reveal+ scaleY = 0.55f + 0.45f * revealYtransformOrigin = TransformOrigin(0.5f, 0f)// Per-draw alpha: an offscreen layer would clip the panel's shadow// during the fade and snap it in at the end (the flicker).@@ -222,11 +230,18 @@ fun <T> LiquidGlassDropdown(.padding(4.dp),verticalArrangement = Arrangement.spacedBy(2.dp)) {- options.forEach { opt ->+ options.forEachIndexed { i, opt ->val isSelected = opt.value == selectedRow(Modifier.fillMaxWidth()+ .graphicsLayer {+ // Rows cascade in behind the unfold (flat content, so moving is free).+ val head = (i * 0.05f).coerceAtMost(0.3f)+ val l = ((revealY - head) / (1f - head)).coerceIn(0f, 1f)+ alpha = l+ translationY = (1f - l) * (-6).dp.toPx()+ }.clip(RoundedCornerShape(12.dp)).clickable(interactionSource = remember { MutableInteractionSource() },diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidIconButton.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidIconButton.ktindex 0842ffd..d719346 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidIconButton.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidIconButton.kt@@ -1,5 +1,6 @@package com.chethan616.clearpdf.ui.components+import androidx.compose.runtime.getValueimport androidx.compose.foundation.ExperimentalFoundationApiimport androidx.compose.foundation.clickableimport androidx.compose.foundation.combinedClickable@@ -9,7 +10,6 @@ import androidx.compose.runtime.Composableimport androidx.compose.runtime.LaunchedEffectimport androidx.compose.foundation.interaction.MutableInteractionSourceimport androidx.compose.foundation.interaction.PressInteraction-import androidx.compose.runtime.getValueimport androidx.compose.runtime.rememberimport androidx.compose.runtime.rememberCoroutineScopeimport androidx.compose.runtime.rememberUpdatedState@@ -22,20 +22,13 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackTypeimport androidx.compose.ui.platform.LocalHapticFeedbackimport androidx.compose.ui.semantics.Roleimport androidx.compose.ui.unit.dp-import androidx.compose.ui.util.fastCoerceAtMost-import androidx.compose.ui.util.lerpimport com.chethan616.clearpdf.ui.utils.InteractiveHighlight+import com.chethan616.clearpdf.ui.utils.liquidPressTransformimport com.kyant.backdrop.Backdropimport com.kyant.backdrop.drawBackdropimport com.kyant.backdrop.effects.blurimport com.kyant.backdrop.effects.lens-import com.kyant.backdrop.effects.vibrancyimport androidx.compose.foundation.shape.CircleShape-import kotlin.math.abs-import kotlin.math.atan2-import kotlin.math.cos-import kotlin.math.sin-import kotlin.math.tanh/*** Circular variant of LiquidButton, optimized for icons.@@ -97,33 +90,7 @@ fun LiquidIconButton(highlight = { glassHighlight(style) },onDrawBackdrop = if (flat != null) ({ _ -> drawFlatVibrantBackdrop(flat) }) else ({ it() }),layerBlock = if (isInteractive) {- {- val width = size.width- val height = size.height-- val progress = interactiveHighlight.pressProgress- // Long-press bloom, same rule as LiquidButton (≤ ~14 dp, ≤ 12 %).- val bloom = interactiveHighlight.expandProgress *- (14f.dp.toPx() / size.maxDimension).fastCoerceAtMost(0.12f)- val scale = lerp(1f, 1f + 4f.dp.toPx() / size.height, progress) + bloom-- 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)- }+ { liquidPressTransform(interactiveHighlight) }} else {null},diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidRowClick.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidRowClick.ktindex ca44641..4c32de7 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidRowClick.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidRowClick.kt@@ -1,12 +1,9 @@package com.chethan616.clearpdf.ui.components-import androidx.compose.animation.core.animateFloatAsStateimport androidx.compose.foundation.clickableimport androidx.compose.foundation.interaction.MutableInteractionSource-import androidx.compose.foundation.interaction.collectIsPressedAsStateimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.runtime.Composable-import androidx.compose.runtime.getValueimport androidx.compose.runtime.rememberimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clip@@ -31,11 +28,10 @@ fun Modifier.liquidRowClick(onClick: () -> Unit): Modifier {val interaction = remember { MutableInteractionSource() }- val pressed by interaction.collectIsPressedAsState()val haptics = LocalHapticFeedback.current- val scale by animateFloatAsState(if (pressed) 0.97f else 1f, GlassMotion.press(), label = "rowPress")+ val jelly = rememberJellyPress(interaction, pressedScale = 0.97f)return this- .graphicsLayer { scaleX = scale; scaleY = scale }+ .graphicsLayer { scaleX = jelly.scale; scaleY = jelly.scale }.clip(RoundedCornerShape(corner)).liquidPressGlow(interaction, onLight = !LocalIsDarkMode.current).clickable(interactionSource = interaction, indication = null, enabled = enabled, role = Role.Button) {diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/ShareMorphButton.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/ShareMorphButton.ktindex 4e084e7..3a661e3 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/ShareMorphButton.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/ShareMorphButton.kt@@ -1,5 +1,7 @@package com.chethan616.clearpdf.ui.components+import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValueimport androidx.compose.animation.animateColorAsStateimport androidx.compose.animation.core.Animatableimport androidx.compose.animation.core.CubicBezierEasing@@ -29,11 +31,9 @@ import androidx.compose.material.icons.rounded.UploadFileimport androidx.compose.material3.Iconimport androidx.compose.runtime.Composableimport androidx.compose.runtime.LaunchedEffect-import androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableFloatStateOfimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.remember-import androidx.compose.runtime.setValueimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Color@@ -174,17 +174,13 @@ fun ShareMorphButton(}// Presses down firmly and bounces back on release, like LiquidButton's deformation.- val pressScale by animateFloatAsState(- if (pressed && !shareMode) GlassMotion.PressedScale else 1f,- GlassMotion.press(),- label = "shareMorphPress"- )+ val jelly = rememberJellyPress(pressed && !shareMode)Box(modifier.width(52.dp).height(height)- .graphicsLayer { scaleX = pressScale; scaleY = pressScale }+ .graphicsLayer { scaleX = jelly.scale; scaleY = jelly.scale }// The viewer's own chrome material, so this sits beside the back and search circles as one// family rather than as a frostier slab. Capsule, not a 28 dp rounded rectangle, so the// 52 -> 104 dp morph is an actual circle-to-capsule the whole way up.diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.ktindex 199c26a..0da82ae 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt@@ -1062,11 +1062,7 @@ private fun MarkupBarItem() {val interaction = remember { androidx.compose.foundation.interaction.MutableInteractionSource() }val pressed by interaction.collectIsPressedAsState()- val press by androidx.compose.animation.core.animateFloatAsState(- if (pressed) com.chethan616.clearpdf.ui.components.GlassMotion.PressedScale else 1f,- com.chethan616.clearpdf.ui.components.GlassMotion.press(),- label = "markupItemPress"- )+ val jelly = com.chethan616.clearpdf.ui.components.rememberJellyPress(interaction)// A soft tinted well under the finger, like the selection toolbar's items.val wash by androidx.compose.animation.core.animateFloatAsState(if (pressed) 0.12f else 0f,@@ -1080,7 +1076,7 @@ private fun MarkupBarItem(// Draw-time only: sliding a finger across squashes the pill along the drag, like a drop// of the glass it sits on..liquidStretchOnDrag(stretchFactor = 0.18f, minScale = 0.88f, maxScale = 1.12f)- .graphicsLayer { scaleX = press; scaleY = press }+ .graphicsLayer { scaleX = jelly.scale; scaleY = jelly.scale }.clip(com.kyant.shapes.Capsule).drawBehind { if (wash > 0f) drawRect(color.copy(alpha = wash)) }.clickable(interactionSource = interaction, indication = null, onClick = onClick)diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/RecentContextMenu.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/RecentContextMenu.ktindex 3e0fd58..e858179 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/RecentContextMenu.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/RecentContextMenu.kt@@ -1,5 +1,6 @@package com.chethan616.clearpdf.ui.screen+import com.chethan616.clearpdf.ui.components.rememberJellyPressimport android.content.Contextimport android.net.Uriimport android.provider.DocumentsContract@@ -118,18 +119,22 @@ internal fun RecentContextMenu(actions: List<RecentMenuAction>,onDismiss: () -> Unit) {+ // Unfolds from the pressed row like iOS 27: width on [GlassMotion.unfold], height a beat behind+ // on the softer [GlassMotion.unfoldLag], so it lands as one gel-like overshoot. Folds back fast.val progress = remember { Animatable(0f) }+ val stretch = remember { Animatable(0f) }val fade = remember { Animatable(0f) }LaunchedEffect(visible) {val target = if (visible) 1f else 0fcoroutineScope {launch { fade.animateTo(target, GlassMotion.fade()) }- progress.animateTo(target, if (visible) GlassMotion.morph() else GlassMotion.settle())+ launch { stretch.animateTo(target, if (visible) GlassMotion.unfoldLag() else GlassMotion.settle()) }+ progress.animateTo(target, if (visible) GlassMotion.unfold() else GlassMotion.settle())}}BackHandler(enabled = visible, onBack = onDismiss)// derivedStateOf: composition only hears about the 0 crossing, not every animation frame.- val gone by remember { androidx.compose.runtime.derivedStateOf { fade.value <= 0.001f && progress.value <= 0.001f } }+ val gone by remember { androidx.compose.runtime.derivedStateOf { fade.value <= 0.001f && progress.value <= 0.001f && stretch.value <= 0.001f } }if (!visible && gone) returnval isDark = LocalIsDarkMode.current@@ -202,9 +207,8 @@ internal fun RecentContextMenu(val pivotX = ((a.center.x - x) / panelW).coerceIn(0f, 1f)val pivotY = if (placeBelow) 0f else 1fpanel.placeWithLayer(x.roundToInt(), y.roundToInt()) {- val p = progress.value- val s = lerp(0.6f, 1f, p)- scaleX = s; scaleY = s+ scaleX = lerp(0.6f, 1f, progress.value)+ scaleY = lerp(0.5f, 1f, stretch.value)alpha = fade.valuetransformOrigin = TransformOrigin(pivotX, pivotY)}@@ -308,7 +312,7 @@ private fun MenuRow(action: RecentMenuAction, fg: Color, enter: () -> Float) {val interaction = remember { MutableInteractionSource() }val pressed by interaction.collectIsPressedAsState()var armed by remember { mutableStateOf(false) }- val press by animateFloatAsState(if (pressed) 0.97f else 1f, GlassMotion.press(), label = "recentMenuPress")+ val jelly = rememberJellyPress(interaction, pressedScale = 0.97f)val wash by animateFloatAsState(when {armed -> 1f@@ -327,7 +331,7 @@ private fun MenuRow(action: RecentMenuAction, fg: Color, enter: () -> Float) {val e = enter()alpha = etranslationY = (1f - e) * 10.dp.toPx()- scaleX = press; scaleY = press+ scaleX = jelly.scale; scaleY = jelly.scale}.drawBehind {if (wash > 0f) {diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/imageeditor/EditorPanels.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/imageeditor/EditorPanels.ktindex 43fada2..02619b6 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/imageeditor/EditorPanels.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/imageeditor/EditorPanels.kt@@ -1,5 +1,6 @@package com.chethan616.clearpdf.ui.screen.imageeditor+import com.chethan616.clearpdf.ui.components.rememberJellyPressimport android.graphics.Bitmapimport androidx.compose.animation.animateColorAsStateimport androidx.compose.animation.core.animateFloatAsState@@ -122,8 +123,7 @@ internal fun EditorChip(val isDark = LocalIsDarkMode.currentval haptics = LocalHapticFeedback.currentval interaction = remember { MutableInteractionSource() }- val pressed by interaction.collectIsPressedAsState()- val scale by animateFloatAsState(if (pressed) GlassMotion.PressedScale else 1f, GlassMotion.press(), label = "chipPress")+ val jelly = rememberJellyPress(interaction)val bg by animateColorAsState(if (selected) accent.copy(if (isDark) 0.30f else 0.18f) else if (isDark) Color.White.copy(0.08f) else Color.Black.copy(0.05f),GlassMotion.settle(), label = "chipBg"@@ -131,7 +131,7 @@ internal fun EditorChip(val fg by animateColorAsState(if (selected) accent else LiquidGlassColors.text(isDark), GlassMotion.settle(), label = "chipFg")Box(modifier- .graphicsLayer { scaleX = scale; scaleY = scale }+ .graphicsLayer { scaleX = jelly.scale; scaleY = jelly.scale }.defaultMinSize(minHeight = 36.dp).clip(RoundedCornerShape(50)).background(bg)diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/selection/PdfSelectionToolbar.kt b/app/src/main/java/com/chethan616/clearpdf/ui/selection/PdfSelectionToolbar.ktindex 54e8b6e..87f4175 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/selection/PdfSelectionToolbar.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/selection/PdfSelectionToolbar.kt@@ -1,5 +1,6 @@package com.chethan616.clearpdf.ui.selection+import com.chethan616.clearpdf.ui.components.rememberJellyPressimport android.content.ComponentNameimport android.content.Contextimport android.content.Intent@@ -485,7 +486,7 @@ private fun rememberStaggerIn(index: Int): Animatable<Float, *> {private fun ToolbarIconButton(item: ToolbarItem, fg: Color) {val interaction = remember { MutableInteractionSource() }val pressed by interaction.collectIsPressedAsState()- val s by animateFloatAsState(if (pressed) GlassMotion.PressedScale else 1f, GlassMotion.press(), label = "tbPress")+ val jelly = rememberJellyPress(interaction)val wash by animateFloatAsState(if (pressed) 0.10f else 0f, GlassMotion.fade(), label = "tbWash")Box(Modifier@@ -493,7 +494,7 @@ private fun ToolbarIconButton(item: ToolbarItem, fg: Color) {// Draw-time only: a finger sliding across the item squashes it along the drag, like// a drop of the glass it sits on; the press scale adds the tactile dip..liquidStretchOnDrag(stretchFactor = 0.18f, minScale = 0.88f, maxScale = 1.12f)- .graphicsLayer { scaleX = s; scaleY = s }+ .graphicsLayer { scaleX = jelly.scale; scaleY = jelly.scale }.drawBehind { if (wash > 0f) drawCircle(fg.copy(alpha = wash)) }.combinedClickable(interactionSource = interaction,@@ -532,7 +533,7 @@ private fun ItemIcon(item: ToolbarItem, tint: Color, size: androidx.compose.ui.uprivate fun MenuRow(item: ToolbarItem, fg: Color, index: Int, fromBelow: Boolean) {val interaction = remember { MutableInteractionSource() }val pressed by interaction.collectIsPressedAsState()- val s by animateFloatAsState(if (pressed) 0.97f else 1f, GlassMotion.press(), label = "rowPress")+ val jelly = rememberJellyPress(interaction, pressedScale = 0.97f)val wash by animateFloatAsState(if (pressed) 0.08f else 0f, GlassMotion.fade(), label = "rowWash")val enter = rememberStaggerIn(index)val shiftPx = with(LocalDensity.current) { 8.dp.toPx() } * (if (fromBelow) 1f else -1f)@@ -544,7 +545,7 @@ private fun MenuRow(item: ToolbarItem, fg: Color, index: Int, fromBelow: Booleanval e = enter.valuealpha = etranslationY = (1f - e) * shiftPx- scaleX = s; scaleY = s+ scaleX = jelly.scale; scaleY = jelly.scale}.drawBehind { if (wash > 0f) drawRect(fg.copy(alpha = wash)) }.combinedClickable(interactionSource = interaction, indication = null, onLongClick = item.onLongClick, onClick = item.onClick)@@ -566,7 +567,7 @@ private fun MenuRow(item: ToolbarItem, fg: Color, index: Int, fromBelow: Booleanprivate fun ColorDot(backdrop: Backdrop, color: Color, selected: Boolean, ring: Color, index: Int, onClick: () -> Unit) {val interaction = remember { MutableInteractionSource() }val pressed by interaction.collectIsPressedAsState()- val s by animateFloatAsState(if (pressed) GlassMotion.PressedScale else 1f, GlassMotion.press(), label = "dotPress")+ val jelly = rememberJellyPress(interaction)val enter = rememberStaggerIn(index)Box(Modifier@@ -575,7 +576,7 @@ private fun ColorDot(backdrop: Backdrop, color: Color, selected: Boolean, ring:.graphicsLayer {val e = enter.valuealpha = e- val k = s * (0.6f + 0.4f * e)+ val k = jelly.scale * (0.6f + 0.4f * e)scaleX = k; scaleY = k}.combinedClickable(interactionSource = interaction, indication = null, onClick = onClick),diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/utils/InteractiveHighlight.kt b/app/src/main/java/com/chethan616/clearpdf/ui/utils/InteractiveHighlight.ktindex 6ca9b89..d366eb4 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/utils/InteractiveHighlight.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/utils/InteractiveHighlight.kt@@ -2,6 +2,7 @@ package com.chethan616.clearpdf.ui.utilsimport android.graphics.RuntimeShaderimport android.os.Build+import android.os.SystemClockimport androidx.compose.animation.core.Animatableimport androidx.compose.animation.core.VectorConverterimport androidx.compose.animation.core.VisibilityThreshold@@ -15,12 +16,26 @@ import androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.ShaderBrushimport androidx.compose.ui.graphics.toArgbimport androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.graphics.GraphicsLayerScope+import androidx.compose.ui.unit.dp+import androidx.compose.ui.util.fastCoerceAtMostimport androidx.compose.ui.util.fastCoerceIn+import androidx.compose.ui.util.lerp+import kotlin.math.abs+import kotlin.math.atan2+import kotlin.math.cos+import kotlin.math.sin+import kotlin.math.tanhimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Jobimport kotlinx.coroutines.delayimport kotlinx.coroutines.launch+private const val MinPressMillis = 90L+// Initial velocities for [InteractiveHighlight.wobble]'s spring: 34 peaks near 1, 10 near 0.3.+private const val WobbleKick = 34f+private const val PressKick = 10f+class InteractiveHighlight(val animationScope: CoroutineScope,val position: (size: Size, offset: Offset) -> Offset = { _, offset -> offset },@@ -33,8 +48,12 @@ class InteractiveHighlight(private val longPressExpand: Boolean = false,private val onLongPressExpand: (() -> Unit)? = null) {- private val pressProgressAnimationSpec = spring(0.5f, 300f, 0.001f)- private val positionAnimationSpec = spring(0.5f, 300f, Offset.VisibilityThreshold)+ // iOS 27 press: the swell lands fast with a small overshoot, the release springs back past rest+ // once, and [wobble] adds one out-of-phase squash on top (see liquidPressTransform).+ private val pressInSpec = spring(0.66f, 620f, 0.001f)+ private val pressOutSpec = spring(0.5f, 380f, 0.001f)+ private val positionAnimationSpec = spring(0.52f, 360f, Offset.VisibilityThreshold)+ private val wobbleSpec = spring(0.42f, 420f, 0.001f)// Bloom in on a soft, slightly slower spring; let go on a livelier one that undershoots rest// a touch before settling — the "boing" that makes the release feel physical.private val expandInSpec = spring(dampingRatio = 0.52f, stiffness = 340f, visibilityThreshold = 0.001f)@@ -43,14 +62,19 @@ class InteractiveHighlight(private val pressProgressAnimation = Animatable(0f, 0.001f)private val positionAnimation = Animatable(Offset.Zero, Offset.VectorConverter, Offset.VisibilityThreshold)private val expandAnimation = Animatable(0f, 0.001f)+ private val wobbleAnimation = Animatable(0f, 0.001f)private var startPosition = Offset.Zeroprivate var positionUpdateJob: Job? = nullprivate var longPressJob: Job? = null+ private var releaseJob: Job? = null+ private var downAt = 0Lval pressProgress: Float get() = pressProgressAnimation.valueval offset: Offset get() = positionAnimation.value - startPosition/** 0 at rest, 1 once a long-press has bloomed; briefly dips below 0 on the release bounce. */val expandProgress: Float get() = expandAnimation.value+ /** Release jiggle, peaking near ±1 and decaying in ~400 ms. Positive = wider and shorter. */+ val wobble: Float get() = wobbleAnimation.value// Built on first press, not at construction. Every LiquidButton / LiquidIconButton / glass card// owns one of these, and `RuntimeShader(...)` compiles its AGSL on the calling thread — so a@@ -107,8 +131,14 @@ half4 main(float2 coord) {private fun release() {positionUpdateJob?.cancel()longPressJob?.cancel()- animationScope.launch {- launch { pressProgressAnimation.animateTo(0f, pressProgressAnimationSpec) }+ releaseJob?.cancel()+ releaseJob = animationScope.launch {+ // A quick tap still shows the whole swell before it lets go.+ val held = SystemClock.uptimeMillis() - downAt+ if (held < MinPressMillis) delay(MinPressMillis - held)+ val kick = WobbleKick * pressProgressAnimation.value.fastCoerceIn(0f, 1.1f)+ launch { wobbleAnimation.animateTo(0f, wobbleSpec, initialVelocity = kick) }+ launch { pressProgressAnimation.animateTo(0f, pressOutSpec) }launch { positionAnimation.animateTo(startPosition, positionAnimationSpec) }if (expandAnimation.value != 0f || expandAnimation.targetValue != 0f) {launch { expandAnimation.animateTo(0f, expandOutSpec) }@@ -123,11 +153,15 @@ half4 main(float2 coord) {inspectDragGestures(onDragStart = { down ->startPosition = down.position+ downAt = SystemClock.uptimeMillis()positionUpdateJob?.cancel()longPressJob?.cancel()+ releaseJob?.cancel()animationScope.launch {- launch { pressProgressAnimation.animateTo(1f, pressProgressAnimationSpec) }+ launch { pressProgressAnimation.animateTo(1f, pressInSpec) }launch { positionAnimation.snapTo(startPosition) }+ // A small taller-first nudge as the glass swells under the finger.+ launch { wobbleAnimation.animateTo(0f, wobbleSpec, initialVelocity = -PressKick) }}if (longPressExpand) {// Same timeout the platform uses for long-click, so a button that also has an@@ -157,3 +191,36 @@ half4 main(float2 coord) {}}}++/**+ * The Liquid Glass press transform shared by LiquidButton and LiquidIconButton (call it from+ * `drawBackdrop`'s `layerBlock`): swells ~4 dp under the finger, leans and stretches toward a+ * dragging finger, blooms on long-press (≤ ~14 dp, ≤ 12 %), and jiggles once on release with X and+ * Y squashing out of phase (~2.5 dp at the first swing, capped for tiny controls).+ */+fun GraphicsLayerScope.liquidPressTransform(h: InteractiveHighlight) {+ val width = size.width+ val height = size.height++ val progress = h.pressProgress+ val bloom = h.expandProgress * (14f.dp.toPx() / size.maxDimension).fastCoerceAtMost(0.12f)+ val scale = lerp(1f, 1f + 4f.dp.toPx() / height, progress) + bloom++ val maxOffset = size.minDimension+ val initialDerivative = 0.05f+ val offset = h.offset+ translationX = maxOffset * tanh(initialDerivative * offset.x / maxOffset)+ translationY = maxOffset * tanh(initialDerivative * offset.y / maxOffset)++ val maxDragScale = 4f.dp.toPx() / height+ val offsetAngle = atan2(offset.y, offset.x)+ val w = h.wobble+ val wobbleX = w * (2.5f.dp.toPx() / width).fastCoerceAtMost(0.045f)+ val wobbleY = w * (2.5f.dp.toPx() / height).fastCoerceAtMost(0.045f)+ scaleX = scale ++ maxDragScale * abs(cos(offsetAngle) * offset.x / size.maxDimension) * (width / height).fastCoerceAtMost(1f) ++ wobbleX+ scaleY = scale ++ maxDragScale * abs(sin(offsetAngle) * offset.y / size.maxDimension) * (height / width).fastCoerceAtMost(1f) -+ wobbleY+}