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.

Keep Clean mode floating controls legible over scrolling content

Kzyube Napolesbe5d1e322ae9
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Surfaces.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Surfaces.kt
index c638698..8421762 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Surfaces.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Surfaces.kt
@@ -30,8 +30,25 @@ import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.chethan616.clearpdf.ui.theme.clear
+import com.kyant.backdrop.effects.blur
import com.kyant.backdrop.drawBackdrop
+/** A quiet, theme-tinted backdrop for controls that float over Clean mode content. */
+@Composable
+internal fun Modifier.cleanFloatingSurface(shape: Shape): Modifier {
+ val panel = clear.solidPanel
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S) {
+ return clip(shape).background(panel)
+ }
+ return drawBackdrop(
+ backdrop = LocalBackdrop.current,
+ shape = { shape },
+ effects = { blur(10.dp.toPx()) },
+ highlight = null,
+ shadow = null,
+ ).background(panel.copy(alpha = 0.82f), shape)
+}
+
/**
* A still glass surface (bars, the dock's body, panels, sheets): refracts [LocalBackdrop] through
* [shape], washed with [wash]. No shadow, ever.
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/CreateDock.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/CreateDock.kt
index f16fc40..9672e1c 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/CreateDock.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/CreateDock.kt
@@ -11,6 +11,7 @@ import com.chethan616.clearpdf.ui.glass.GlassPill
import com.chethan616.clearpdf.ui.glass.GlassDialog
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
+import com.chethan616.clearpdf.ui.glass.cleanFloatingSurface
import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.RepeatMode
@@ -346,9 +347,17 @@ fun BoxScope.CreateDock(
}
.onGloballyPositioned { if (into.value == 0f) dockBottom[0] = it.boundsInWindow().bottom }
// the very glass of the Back and menu buttons; the recorder darkens it so its white reads
- .glass(Capsule, c.glass, blur = 3.dp, lensHeight = 14.dp, lensAmount = 26.dp)
+ .then(
+ if (c.clean) Modifier.cleanFloatingSurface(Capsule)
+ else Modifier.glass(Capsule, c.glass, blur = 3.dp, lensHeight = 14.dp, lensAmount = 26.dp),
+ )
.graphicsLayer { clip = true; shape = Capsule }
- .drawBehind { drawRect(if (c.clean && shown != null) DockInk else c.capsule, alpha = lerp(0.5f, 1.9f, morph.value.coerceIn(0f, 1f)).coerceAtMost(1f)) }
+ .drawBehind {
+ if (!c.clean || shown != null) {
+ val opacity = lerp(0.5f, 1.9f, morph.value.coerceIn(0f, 1f)).coerceAtMost(1f)
+ drawRect(if (c.clean) DockInk else c.capsule, alpha = opacity)
+ }
+ }
.padding(6.dp),
) { measurables, constraints ->
val loose = constraints.copy(minWidth = 0, minHeight = 0)
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/HomeScreen.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/HomeScreen.kt
index 3a618f6..6900035 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/HomeScreen.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/HomeScreen.kt
@@ -1,5 +1,10 @@
package com.chethan616.clearpdf.ui.home
+import com.chethan616.clearpdf.ui.glass.cleanFloatingSurface
+import androidx.compose.foundation.layout.offset
+import androidx.compose.ui.unit.IntOffset
+import androidx.compose.ui.graphics.RectangleShape
+import com.chethan616.clearpdf.ui.glass.GlassLayer
import androidx.annotation.StringRes
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.Animatable
@@ -43,6 +48,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
@@ -227,7 +233,8 @@ fun HomeScreen(vm: AppViewModel, desk: DeskState) {
}
}
- CompositionLocalProvider(LocalHomeVm provides vm) {
+ val clean = clear.clean
+ val deskGrid: @Composable () -> Unit = {
LazyVerticalStaggeredGrid(
columns = StaggeredGridCells.Fixed(2),
state = grid,
@@ -261,7 +268,7 @@ fun HomeScreen(vm: AppViewModel, desk: DeskState) {
}
item(key = "title", span = StaggeredGridItemSpan.FullLine) { DeskTitle(filter) }
item(key = "chips", span = StaggeredGridItemSpan.FullLine) {
- FilterChips(filter) { filter = it }
+ if (clean) Spacer(Modifier.height(FilterRowHeight)) else FilterChips(filter) { filter = it }
}
itemsIndexed(items, key = { _, it -> it.key }) { i, item ->
// the others glide aside as a carried card passes; the carried one follows the finger
@@ -319,6 +326,33 @@ fun HomeScreen(vm: AppViewModel, desk: DeskState) {
}
}
+ CompositionLocalProvider(LocalHomeVm provides vm) {
+ if (clean) {
+ val topInset = WindowInsets.statusBars.getTop(density)
+ // The row follows its grid slot until the cards begin to pass beneath it.
+ val filterY by remember(grid, topInset) {
+ derivedStateOf {
+ val layout = grid.layoutInfo
+ layout.visibleItemsInfo.firstOrNull { it.key == "chips" }?.offset?.y
+ ?: if (grid.firstVisibleItemIndex > 1) topInset else layout.viewportEndOffset
+ }
+ }
+ val pinned by remember(grid, topInset) { derivedStateOf { filterY <= topInset } }
+ GlassLayer(Modifier.fillMaxSize(), content = { deskGrid() }, above = {
+ Box(
+ Modifier.offset { IntOffset(0, maxOf(topInset, filterY)) }
+ .fillMaxWidth()
+ .then(if (pinned) Modifier.cleanFloatingSurface(RectangleShape) else Modifier)
+ .padding(horizontal = 16.dp),
+ ) {
+ FilterChips(filter) { filter = it }
+ }
+ })
+ } else {
+ deskGrid()
+ }
+ }
+
actionsFor?.let { n -> NoteActions(vm, n, actionsAnchor, onRename = { desk.naming = n.id }) { actionsFor = null } }
desk.naming?.let { id -> vm.notes.get(id)?.let { n -> NameSheet(vm, n) { desk.naming = null } } }
}
@@ -411,6 +445,8 @@ private fun DeskTitle(filter: DeskFilter) {
}
}
+private val FilterRowHeight = 16.dp + 46.dp + 10.dp
+
/**
* The chips: glass capsules with a white rim; the chosen one is filled lemon. The row runs to the
* screen's edges and fades out at both, so a chip scrolled past slips away instead of being cut.
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
index 20f6dfa..53fcdeb 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
@@ -1,5 +1,6 @@
package com.chethan616.clearpdf.ui.viewer
+import com.chethan616.clearpdf.ui.glass.cleanFloatingSurface
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.border
@@ -375,7 +376,7 @@ fun QuickToolbar(
if (clear.clean) {
Row(
Modifier.fillMaxWidth().height(BottomBarHeight).padding(horizontal = 12.dp, vertical = 4.dp)
- .glassBar(RoundedRectangle(16.dp)).padding(4.dp),
+ .cleanFloatingSurface(RoundedRectangle(16.dp)).padding(4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
for (tool in shown) {