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
Reader+sheets: unify presentation dock, fix navbar/auto-scroll lag and taps
Chethan61605663675971a
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.ktindex 180cb16..933410c 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@@ -17,6 +17,7 @@ import androidx.compose.runtime.derivedStateOfimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableIntStateOfimport androidx.compose.runtime.remember+import androidx.compose.runtime.rememberUpdatedStateimport androidx.compose.runtime.rememberCoroutineScopeimport androidx.compose.runtime.setValueimport androidx.compose.runtime.snapshotFlow@@ -99,7 +100,8 @@ fun LiquidBottomTabs(val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltrval animationScope = rememberCoroutineScope()- var currentIndex by remember(selectedTabIndex) {+ val selectedTabIndexState = rememberUpdatedState(selectedTabIndex)+ var currentIndex by remember {mutableIntStateOf(selectedTabIndex())}val dampedDragAnimation = remember(animationScope) {@@ -133,8 +135,8 @@ fun LiquidBottomTabs(})}- LaunchedEffect(selectedTabIndex) {- snapshotFlow { selectedTabIndex() }+ LaunchedEffect(Unit) {+ snapshotFlow { selectedTabIndexState.value() }.collectLatest { index ->currentIndex = index}diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.ktindex a485435..93d595c 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt@@ -137,6 +137,7 @@ internal fun PdfViewerBottomToolbar(showFindBar: Boolean,showSignaturePad: Boolean,autoScrollActive: Boolean,+ autoScrollSpeed: Float,activeImageId: Long?,currentColor: Color,currentColorLong: Long,@@ -172,6 +173,7 @@ internal fun PdfViewerBottomToolbar(onOpenAnotherPdf: () -> Unit,onShareDocument: () -> Unit,onToggleAutoScroll: () -> Unit,+ onCycleAutoScrollSpeed: () -> Unit,onEditorOpenChanged: (Boolean) -> Unit = {},// Same purpose as [onEditorOpenChanged]: a long-press on the share capsule is a gesture the// viewer cannot see, so without this the 5s chrome auto-hide fires mid-hold and takes the button@@ -202,7 +204,6 @@ internal fun PdfViewerBottomToolbar(// export-feedback strip): those are dense rows of controls that need a plate to sit on, and they// cover the document rather than floating over it.val pillGlass = Color.Transparent- val usePresentationDock = docKind == DocKind.Pptval showDrawTools = drawingToolActiveval showImageTools = activeTool == PdfEditTool.Image && activeImageId != null@@ -238,7 +239,7 @@ internal fun PdfViewerBottomToolbar(// room for the cylinder — the whole pill + its buttons shrink together, so nothing is cut.var shareActive by remember { mutableStateOf(false) }val toolCompress by animateFloatAsState(- if (shareActive) if (usePresentationDock) 0.68f else 0.84f else 1f,+ if (shareActive) 0.84f else 1f,// Bounce, matching the share capsule's own morph — both now run on GlassMotion.morph(), so the// pill springs shut (and back open) with the same weight the cylinder has instead of deflating// limply beside it. Safe to overshoot because this drives `scaleX`, a DRAW-time property: no@@ -735,7 +736,7 @@ internal fun PdfViewerBottomToolbar(}}- // ── Compact reader dock: auto-scroll, annotations, and ShareMorph in one glass capsule.+ // ── Reader actions: editor, auto-scroll, speed, and ShareMorph share one bottom row.AnimatedVisibility(// Same `selectorGate` as the tool chips above, so the controls fade out together// before the focused sub-toolbar arrives.@@ -744,25 +745,26 @@ internal fun PdfViewerBottomToolbar(exit = fadeOut(tween(FaceHandoffMillis)),modifier = Modifier.align(Alignment.CenterHorizontally)) {- if (usePresentationDock) {- Box(- Modifier.widthIn(max = 320.dp).fillMaxWidth(),- contentAlignment = Alignment.BottomCenter- ) {- // Keep the background at its resting height. The morph button is a sibling so its- // capsule can grow upward without clipping the glass or re-blurring a moving panel.- Box(- Modifier- .fillMaxWidth()- .height(64.dp)- .align(Alignment.BottomCenter)- .viewerGlass(backdrop, pillGlass, shape = { com.kyant.shapes.Capsule })- )- Row(- Modifier.fillMaxWidth().height(64.dp).padding(horizontal = 8.dp),- horizontalArrangement = Arrangement.SpaceEvenly,- verticalAlignment = Alignment.CenterVertically- ) {+ Row(+ Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.spacedBy(10.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ Box(Modifier.size(52.dp), contentAlignment = Alignment.Center) {+ LiquidIconButton(+ onClick = {+ editorOpen = !editorOpen+ if (!editorOpen) onSetActiveTool(PdfEditTool.None)+ },+ backdrop = backdrop,+ modifier = Modifier.size(52.dp),+ tint = if (editorOpen) accent else Color.Unspecified,+ surfaceColor = if (!editorOpen && readerTourStep == 0) LiquidGlassColors.Blue.copy(alpha = 0.22f) else Color.Unspecified+ ) {+ Icon(Icons.Rounded.Edit, stringResource(R.string.viewer_editor_tools), Modifier.size(21.dp), if (editorOpen) Color.White else fg)+ }+ }+ Box(Modifier.size(52.dp), contentAlignment = Alignment.Center) {LiquidIconButton(onClick = onToggleAutoScroll,backdrop = backdrop,@@ -772,109 +774,62 @@ internal fun PdfViewerBottomToolbar(Icon(if (autoScrollActive) Icons.Rounded.Pause else Icons.Rounded.PlayArrow,stringResource(if (autoScrollActive) R.string.viewer_auto_scroll_pause else R.string.viewer_auto_scroll_start),- Modifier.size(24.dp),+ Modifier.size(21.dp),if (autoScrollActive) Color.White else fg)}- LiquidIconButton(- onClick = {- editorOpen = !editorOpen- if (!editorOpen) onSetActiveTool(PdfEditTool.None)- },- backdrop = backdrop,- modifier = Modifier.size(52.dp),- tint = if (editorOpen) accent else Color.Unspecified,- surfaceColor = if (!editorOpen && readerTourStep == 0) LiquidGlassColors.Blue.copy(alpha = 0.16f) else Color.Unspecified- ) {- Icon(Icons.Rounded.Comment, stringResource(R.string.viewer_editor_tools), Modifier.size(24.dp), if (editorOpen) Color.White else fg)- }- // Reserve the final slot for the morphing share action layered over this row.- Spacer(Modifier.size(52.dp))}- ShareMorphButton(- backdrop = backdrop,- glass = if (readerTourStep == 1) LiquidGlassColors.Blue.copy(alpha = 0.16f) else pillGlass,- fg = fg,- onOpen = onShareDocument,- onShare = onShareDocument,- onShareModeChanged = { shareActive = it; onShareHoldChanged(it) },- idleIcon = Icons.Rounded.IosShare,- idleContentDesc = stringResource(R.string.viewer_share_document),- modifier = Modifier.align(Alignment.BottomEnd).offset(x = (-33).dp)- )- }- } else {- // Restore the reader controls used by PDFs, Word, and other document types.- Row(- Modifier.fillMaxWidth(),- horizontalArrangement = Arrangement.spacedBy(10.dp),- verticalAlignment = Alignment.Bottom+ Spacer(Modifier.weight(1f))+ AnimatedVisibility(+ visible = autoScrollActive,+ enter = fadeIn(tween(160)),+ exit = fadeOut(tween(120))) {- Box(Modifier.size(52.dp), contentAlignment = Alignment.Center) {- LiquidIconButton(- onClick = {- editorOpen = !editorOpen- if (!editorOpen) onSetActiveTool(PdfEditTool.None)- },- backdrop = backdrop,- modifier = Modifier.size(52.dp),- tint = if (editorOpen) accent else Color.Unspecified,- surfaceColor = if (!editorOpen && readerTourStep == 0) LiquidGlassColors.Blue.copy(alpha = 0.22f) else Color.Unspecified- ) {- Icon(Icons.Rounded.Edit, stringResource(R.string.viewer_editor_tools), Modifier.size(21.dp), if (editorOpen) Color.White else fg)- }- }- Box(Modifier.size(52.dp), contentAlignment = Alignment.Center) {- LiquidIconButton(- onClick = onToggleAutoScroll,- backdrop = backdrop,- modifier = Modifier.size(52.dp),- tint = if (autoScrollActive) LiquidGlassColors.Green else Color.Unspecified- ) {- Icon(- if (autoScrollActive) Icons.Rounded.Pause else Icons.Rounded.PlayArrow,- stringResource(if (autoScrollActive) R.string.viewer_auto_scroll_pause else R.string.viewer_auto_scroll_start),- Modifier.size(21.dp),- if (autoScrollActive) Color.White else fg- )- }+ LiquidButton(+ onClick = onCycleAutoScrollSpeed,+ backdrop = backdrop,+ modifier = Modifier.widthIn(min = 72.dp),+ surfaceColor = Color.Transparent+ ) {+ BasicText(+ text = "${autoScrollSpeed}×",+ style = TextStyle(fg, 13.sp, FontWeight.SemiBold)+ )}- Spacer(Modifier.weight(1f))- Spacer(Modifier.size(52.dp))}+ Spacer(Modifier.weight(1f))+ // Reserve the final slot for ShareMorph, which is layered over this row.+ Spacer(Modifier.size(52.dp))}}}- if (!usePresentationDock) {- // PDFs and the other readers keep the original ShareMorph placement and open-file tap.- AnimatedVisibility(- visible = selectorGate && !showFindBar && !showSignaturePad,- enter = fadeIn(tween(180)),- exit = fadeOut(tween(FaceHandoffMillis)),- modifier = Modifier.align(Alignment.BottomEnd).zIndex(3f)- ) {- ShareMorphButton(- backdrop = backdrop,- glass = if (readerTourStep == 1) LiquidGlassColors.Blue.copy(alpha = 0.2f) else pillGlass,- fg = fg,- onOpen = onOpenAnotherPdf,- onShare = onShareDocument,- onShareModeChanged = { shareActive = it; onShareHoldChanged(it) }- )- }+ // Every document format uses the same ShareMorph position and open/share actions.+ AnimatedVisibility(+ visible = selectorGate && !showFindBar && !showSignaturePad,+ enter = fadeIn(tween(180)),+ exit = fadeOut(tween(FaceHandoffMillis)),+ modifier = Modifier.align(Alignment.BottomEnd).zIndex(3f)+ ) {+ ShareMorphButton(+ backdrop = backdrop,+ glass = if (readerTourStep == 1) LiquidGlassColors.Blue.copy(alpha = 0.2f) else pillGlass,+ fg = fg,+ onOpen = onOpenAnotherPdf,+ onShare = onShareDocument,+ onShareModeChanged = { shareActive = it; onShareHoldChanged(it) }+ )}GlassGuideCallout(visible = readerTourStep == 0,title = stringResource(R.string.tour_reader_tools_title),- message = stringResource(if (usePresentationDock) R.string.tour_reader_tools_ppt_message else R.string.tour_reader_tools_message),+ message = stringResource(R.string.tour_reader_tools_message),backdrop = backdrop,isLastStep = false,onNext = onReaderTourNext,onSkip = onReaderTourDismiss,- modifier = if (usePresentationDock) Modifier.align(Alignment.BottomCenter).padding(start = 12.dp, end = 12.dp, bottom = 116.dp).zIndex(5f)- else Modifier.align(Alignment.BottomStart).padding(start = 12.dp, bottom = 116.dp).zIndex(5f)+ modifier = Modifier.align(Alignment.BottomStart).padding(start = 12.dp, bottom = 116.dp).zIndex(5f))GlassGuideCallout(visible = readerTourStep == 1,@@ -885,8 +840,7 @@ internal fun PdfViewerBottomToolbar(arrowAtEnd = true,onNext = onReaderTourNext,onSkip = onReaderTourDismiss,- modifier = if (usePresentationDock) Modifier.align(Alignment.BottomCenter).padding(start = 12.dp, end = 12.dp, bottom = 116.dp).zIndex(5f)- else Modifier.align(Alignment.BottomEnd).padding(end = 12.dp, bottom = 116.dp).zIndex(5f)+ modifier = Modifier.align(Alignment.BottomEnd).padding(end = 12.dp, bottom = 116.dp).zIndex(5f))}diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.ktindex 8f0f747..d73a91a 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt@@ -990,13 +990,19 @@ fun PdfViewerScreen(else Modifier.pointerInput(Unit) {awaitEachGesture {awaitFirstDown(requireUnconsumed = false)- autoScroll = false+ var accumulatedPan = Offset.Zerodo {val event = awaitPointerEvent()// A selection drag owns the finger: no one-finger pan underneath it.if (textSelection.gestureActive) continueval zoomChange = event.calculateZoom()val panChange = event.calculatePan()+ accumulatedPan += panChange+ // A tap may hide the chrome, but must not stop reading. Stop only+ // after a real drag or pinch takes ownership of the page.+ if (autoScroll && (zoomChange != 1f || accumulatedPan.getDistance() > viewConfiguration.touchSlop)) {+ autoScroll = false+ }val zoomed = scale > 1.001fif (zoomChange != 1f || zoomed) {val cw = size.width.toFloat()@@ -1203,40 +1209,6 @@ fun PdfViewerScreen(pageBitmaps = state.pageBitmaps)- AnimatedVisibility(- visible = controlsVisible && autoScroll && state.document != null && safePageCount > 1 && scale <= 1.01f && activeTool == PdfEditTool.None,- enter = fadeIn(tween(180)) + scaleIn(initialScale = 0.94f),- exit = fadeOut(tween(120)) + scaleOut(targetScale = 0.96f),- modifier = Modifier.align(Alignment.BottomCenter).navigationBarsPadding().padding(bottom = 76.dp)- ) {- Row(- Modifier- // Clear glass like every other floating control; the ink carries contrast.- .viewerGlass(contentBackdrop, Color.Transparent, shape = { com.kyant.shapes.Capsule })- .padding(horizontal = 7.dp, vertical = 6.dp),- verticalAlignment = Alignment.CenterVertically,- horizontalArrangement = Arrangement.spacedBy(2.dp)- ) {- BasicText(- text = "${autoScrollSpeed}×",- modifier = Modifier- .semantics { contentDescription = context.getString(R.string.viewer_auto_scroll_speed) }- .clip(RoundedCornerShape(50))- .clickable {- autoScrollSpeed = when (autoScrollSpeed) {- 0.75f -> 1f- 1f -> 1.5f- 1.5f -> 2f- else -> 0.75f- }- lastInteractionAtMs = System.currentTimeMillis()- }- .padding(horizontal = 12.dp, vertical = 10.dp),- style = TextStyle(bottomFg, 13.sp, FontWeight.SemiBold)- )- }- }-// ── Page scrubber (doubles as the fading scroll indicator) ─────────// Always present on multi-page docs so fast scrubbing is one drag away,// independent of the auto-hiding chrome. It brightens the moment the list@@ -1443,6 +1415,7 @@ fun PdfViewerScreen(showFindBar = showFindBar,showSignaturePad = showSignaturePad,autoScrollActive = autoScroll,+ autoScrollSpeed = autoScrollSpeed,activeImageId = activeImageId,currentColor = currentColor,currentColorLong = currentColorLong,@@ -1525,6 +1498,15 @@ fun PdfViewerScreen(controlsVisible = truelastInteractionAtMs = System.currentTimeMillis()},+ onCycleAutoScrollSpeed = {+ autoScrollSpeed = when (autoScrollSpeed) {+ 0.75f -> 1f+ 1f -> 1.5f+ 1.5f -> 2f+ else -> 0.75f+ }+ lastInteractionAtMs = System.currentTimeMillis()+ },onRecolorSignature = { cl ->activeImageLoc()?.let { (pg, idx, sig) ->if (sig.isSignature) getPageMarks(pg)[idx] = sig.copy(bitmap = recolorSignatureBitmap(sig.bitmap, Color(cl).toArgb()))diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.ktindex 444228f..e49b31e 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt@@ -608,16 +608,6 @@ fun SpreadsheetViewerScreen(modifier = Modifier.align(Alignment.CenterEnd).padding(end = 4.dp))}- SheetTabs(- wb = wb!!,- indices = visibleSheets,- selected = idx,- backdrop = backdrop,- glass = chromeGlass,- text = text, sub = sub, accent = accent,- onSelect = { i -> if (editing) commitDraft(); sheetIndex = i },- modifier = Modifier.align(Alignment.CenterHorizontally).padding(top = 8.dp)- )AnimatedVisibility(visible = editMode,enter = fadeIn(GlassMotion.fade()),@@ -650,6 +640,28 @@ fun SpreadsheetViewerScreen(}}+ // A floating sheet dock sits above the grid and the system gesture area without adding a+ // second plate or stealing height from the spreadsheet viewport.+ AnimatedVisibility(+ visible = sheet != null && visibleSheets.size > 1 && !showSearch,+ enter = fadeIn(GlassMotion.fade()) + slideInVertically { it / 3 },+ exit = fadeOut(GlassMotion.fade()) + slideOutVertically { it / 3 },+ modifier = Modifier.align(Alignment.BottomCenter)+ .navigationBarsPadding()+ .imePadding()+ .padding(bottom = if (editMode) 72.dp else 10.dp)+ ) {+ SheetTabs(+ wb = wb!!,+ indices = visibleSheets,+ selected = idx,+ backdrop = backdrop,+ text = text,+ accent = accent,+ onSelect = { i -> if (editing) commitDraft(); sheetIndex = i }+ )+ }+// Share / export (reading mode): tap = open as PDF, long-press + swipe up = share.if (sheet != null && !showSearch && !editMode) {ShareMorphButton(@@ -898,61 +910,42 @@ private fun SheetTabs(indices: List<Int>,selected: Int,backdrop: LayerBackdrop,- glass: Color,text: Color,- sub: Color,accent: Color,- onSelect: (Int) -> Unit,- modifier: Modifier = Modifier+ onSelect: (Int) -> Unit) {if (indices.isEmpty()) return- val scroll = rememberScrollState()val selectedSlot = indices.indexOf(selected).coerceAtLeast(0)- val density = LocalDensity.current- val compactWidth = (LocalConfiguration.current.screenWidthDp.dp - 32.dp)- .coerceAtMost(320.dp)- .coerceAtLeast(104.dp)- BoxWithConstraints(- modifier.width(compactWidth).height(64.dp),- contentAlignment = Alignment.Center+ val maxWidth = (LocalConfiguration.current.screenWidthDp.dp - 128.dp)+ .coerceAtMost(240.dp)+ .coerceAtLeast(96.dp)+ val compactWidth = (80.dp * indices.size.toFloat() + 8.dp).coerceAtMost(maxWidth).coerceAtLeast(96.dp)++ LiquidBottomTabs(+ selectedTabIndex = { selectedSlot },+ onTabSelected = { slot -> indices.getOrNull(slot)?.let(onSelect) },+ backdrop = backdrop,+ tabsCount = indices.size,+ modifier = Modifier.width(compactWidth).height(44.dp),+ barHeight = 44.dp,+ surfaceColor = Color.Transparent) {- val tabWidth = (maxWidth / 3).coerceIn(104.dp, 136.dp)- val tabWidthPx = with(density) { tabWidth.toPx() }- val viewportPx = with(density) { maxWidth.toPx() }- val contentWidth = tabWidth * indices.size + 8.dp- LaunchedEffect(selectedSlot, tabWidthPx, viewportPx) {- val target = (selectedSlot * tabWidthPx - (viewportPx - tabWidthPx) / 2f)- .coerceIn(0f, (with(density) { contentWidth.toPx() } - viewportPx).coerceAtLeast(0f))- scroll.animateScrollTo(target.roundToInt())- }- Box(Modifier.horizontalScroll(scroll)) {- LiquidBottomTabs(- selectedTabIndex = { selectedSlot },- onTabSelected = { slot -> indices.getOrNull(slot)?.let(onSelect) },- backdrop = backdrop,- tabsCount = indices.size,- modifier = Modifier.width(contentWidth).height(48.dp),- barHeight = 48.dp,- surfaceColor = Color.Transparent- ) {- indices.forEachIndexed { slot, sheetIndex ->- val sheet = wb.sheets[sheetIndex]- val tabColor = sheet.tabColor?.resolve(wb.styles.themeColors, wb.styles.indexedColors)?.let(::Color)- LiquidBottomTab(onClick = { onSelect(sheetIndex) }) {- if (tabColor != null) Box(Modifier.size(5.dp).clip(CircleShape).background(tabColor))- BasicText(- sheet.name,- Modifier.fillMaxWidth().padding(horizontal = 5.dp),- style = TextStyle(- if (slot == selectedSlot) accent else text,- 11.sp,- if (slot == selectedSlot) FontWeight.SemiBold else FontWeight.Medium- ),- maxLines = 1,- overflow = TextOverflow.Ellipsis- )- }- }+ indices.forEachIndexed { slot, sheetIndex ->+ val sheet = wb.sheets[sheetIndex]+ val tabColor = sheet.tabColor?.resolve(wb.styles.themeColors, wb.styles.indexedColors)?.let(::Color)+ LiquidBottomTab(onClick = { onSelect(sheetIndex) }) {+ if (tabColor != null) Box(Modifier.size(5.dp).clip(CircleShape).background(tabColor))+ BasicText(+ sheet.name,+ Modifier.fillMaxWidth().padding(horizontal = 5.dp),+ style = TextStyle(+ if (slot == selectedSlot) accent else text,+ 11.sp,+ if (slot == selectedSlot) FontWeight.SemiBold else FontWeight.Medium+ ),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis+ )}}}