Skip to content

Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.

Back waits a beat for its press, holding it stays in Settings, tab bar keeps up

chethan616985fcda4182f
diff --git a/DESIGN.md b/DESIGN.md
index ebafa32..d08091b 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -124,6 +124,9 @@ by hand must do the same. `settle`, `fade` and layout springs never bounce and i
Back.
- Long-press on a glass button blooms (grows ≤ ~14 dp, glows brighter, one LongPress haptic). A
long-press **action** runs on release, never mid-press.
+- A tapped back button (`GlassBackButton`) leaves after `GlassMotion.BackTapDelayMillis` (140 ms),
+ so the press is seen first, as on iOS. Not longer: it must never read as lag. The system back
+ gesture stays instant, and Reduce glass motion skips the wait.
---
@@ -152,6 +155,10 @@ by hand must do the same. `settle`, `fade` and layout springs never bounce and i
---
## 6. Layout and UX
+- Holding a back button goes to the root of where you are: the library from a tool or document,
+ the Settings index from a Settings page (never past it to Home).
+- The tab bar is rebuilt whenever it reappears, so it must follow the current tab from its first
+ frame; never skip the first selection change it sees.
- Settings is an iOS-style index of rows. Each topic opens its own page with a back button. Keep the
root light: three small panels.
- Use 16 dp screen gutters and 12–16 dp between panels. Rows are 44–48 dp tall. Text is 13–16 sp:
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassMotion.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassMotion.kt
index fe43458..0f1c835 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
@@ -63,4 +63,10 @@ object GlassMotion {
/** A tap shorter than this still shows the whole press before releasing. */
const val MinPressMillis = 90L
+
+ /**
+ * How long a tapped back button waits before leaving: long enough for the swell to land and start
+ * springing back (the press is visible, as on iOS), short enough that it never reads as lag.
+ */
+ const val BackTapDelayMillis = 140L
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassPrimitives.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassPrimitives.kt
index d07154c..6ea59b6 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassPrimitives.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassPrimitives.kt
@@ -1,5 +1,6 @@
package com.chethan616.clearpdf.ui.components
+import kotlinx.coroutines.launch
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
@@ -68,8 +69,29 @@ fun GlassBackButton(
onLongPressBack: (() -> Unit)? = LocalBackToLibraryAction.current,
longPressLabel: String? = null
) {
+ // A tap waits [GlassMotion.BackTapDelayMillis] so the press is seen before the screen goes; it
+ // used to leave on the same frame, before the glass had moved. The system back gesture stays
+ // instant (it is the screen's BackHandler, not this). Further taps while waiting are ignored, and
+ // leaving the screen meanwhile cancels the wait, so Back never fires twice.
+ val scope = androidx.compose.runtime.rememberCoroutineScope()
+ val currentOnBack by androidx.compose.runtime.rememberUpdatedState(onBack)
+ val reduced = com.chethan616.clearpdf.ui.theme.LocalReducedGlassMotion.current
+ val pending = remember { booleanArrayOf(false) }
LiquidIconButton(
- onClick = onBack,
+ onClick = {
+ if (reduced) currentOnBack()
+ else if (!pending[0]) {
+ pending[0] = true
+ scope.launch {
+ try {
+ kotlinx.coroutines.delay(GlassMotion.BackTapDelayMillis)
+ currentOnBack()
+ } finally {
+ pending[0] = false
+ }
+ }
+ }
+ },
onLongClick = onLongPressBack,
onLongClickLabel = onLongPressBack?.let { longPressLabel ?: stringResource(R.string.back_to_library) },
backdrop = backdrop,
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidBottomTabs.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidBottomTabs.kt
index 9c453c7..52b44d7 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidBottomTabs.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidBottomTabs.kt
@@ -54,7 +54,6 @@ import com.kyant.backdrop.shadow.InnerShadow
import com.kyant.backdrop.shadow.Shadow
import com.kyant.shapes.Capsule
import kotlinx.coroutines.flow.collectLatest
-import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.launch
import kotlin.math.abs
import kotlin.math.sign
@@ -142,11 +141,17 @@ fun LiquidBottomTabs(
}
}
LaunchedEffect(dampedDragAnimation) {
+ // No drop(1): the bar is rebuilt every time it reappears (it steps away on Settings pages
+ // and tool screens), and the selection can change between its first frame and this
+ // effect starting. Holding Back on a Settings page did exactly that, and drop(1) threw
+ // the change away, leaving the pill on Settings over Home. Move the pill whenever it is
+ // not where the index says, and report only the bar's own changes (a drag) upward.
snapshotFlow { currentIndex }
- .drop(1)
.collectLatest { index ->
- dampedDragAnimation.animateToValue(index.toFloat())
- onTabSelected(index)
+ if (dampedDragAnimation.targetValue.fastRoundToInt() != index) {
+ dampedDragAnimation.animateToValue(index.toFloat())
+ }
+ if (index != selectedTabIndexState.value()) onTabSelected(index)
}
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
index 6f22e9a..ec86be2 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
@@ -241,6 +241,10 @@ fun SettingsScreen(
title = pageTitle,
backdrop = headerBackdrop,
onBack = if (page != PageIndex) ({ page = PageIndex }) else null,
+ // Holding Back on a Settings page returns to Settings itself. The app-wide
+ // default (back to the library) popped all the way Home from in here.
+ onBackLongPress = if (page != PageIndex) ({ page = PageIndex }) else null,
+ backLongPressLabel = stringResource(R.string.settings_title),
modifier = entrance.sectionFade(0)
)
}