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.

feat: dialog-style settings buttons, sticky editor tools, swipe-to-share, reaction pill

Chethan616d2c2dd7149f9
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/HomeScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/HomeScreen.kt
index 5154643..0540c16 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/HomeScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/HomeScreen.kt
@@ -468,109 +468,66 @@ fun HomeScreen(
selectedRecent?.let { recent ->
val targetY = (selectedRecentAnchorY - recentPopupHeightPx / 2f)
.coerceIn(padPx * 5f, (maxH - recentPopupHeightPx - padPx * 5f).coerceAtLeast(padPx))
- Column(
+ // WhatsApp-style reaction pill: a compact floating capsule of round glass
+ // action buttons that pops up from the long-pressed row.
+ Row(
Modifier
.offset { IntOffset(0, targetY.toInt()) }
.onGloballyPositioned { recentPopupHeightPx = it.size.height }
- .padding(horizontal = 24.dp)
.graphicsLayer {
- val scaleXValue = lerp(0.20f, 1.0f, morphProgress)
- val scaleYValue = lerp(0.15f, 1.0f, morphProgress)
- val translateYValue = lerp(100f, 0f, morphProgress) * density
+ val scaleXValue = lerp(0.30f, 1.0f, morphProgress)
+ val scaleYValue = lerp(0.20f, 1.0f, morphProgress)
+ translationY = lerp(60f, 0f, morphProgress) * density
scaleX = scaleXValue
scaleY = scaleYValue
- translationY = translateYValue
alpha = morphProgress.coerceIn(0f, 1f)
- transformOrigin = TransformOrigin(0.5f, 0.85f)
- shadowElevation = (16f * morphProgress).dp.toPx()
+ transformOrigin = TransformOrigin(0.5f, 0.9f)
+ shadowElevation = (14f * morphProgress).dp.toPx()
}
.liquidGlassPanel(backdrop, uiSensor)
.clickable(
interactionSource = remember { androidx.compose.foundation.interaction.MutableInteractionSource() },
indication = null
) { /* Consume inner taps */ }
- .padding(horizontal = 10.dp, vertical = 12.dp),
- verticalArrangement = Arrangement.spacedBy(2.dp),
- horizontalAlignment = Alignment.Start
+ .padding(horizontal = 8.dp, vertical = 8.dp),
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ verticalAlignment = Alignment.CenterVertically
) {
- // Header: filename + close
- Row(
- Modifier.fillMaxWidth().padding(horizontal = 4.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.SpaceBetween
- ) {
- Row(
- Modifier.weight(1f),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp)
- ) {
- Box(
- Modifier
- .size(32.dp)
- .clip(CircleShape)
- .background(Color(0xFFE53935).copy(alpha = if (isLight) 0.14f else 0.25f)),
- contentAlignment = Alignment.Center
- ) {
- Icon(Icons.Rounded.PictureAsPdf, null, Modifier.size(18.dp), Color(0xFFE53935))
- }
- BasicText(
- recent.name,
- style = TextStyle(text, 14.sp, FontWeight.SemiBold),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier.weight(1f)
- )
- }
-
+ Box(Modifier.graphicsLayer { scaleX = b1Scale; scaleY = b1Scale; alpha = b1Scale.coerceIn(0f, 1f) }) {
LiquidIconButton(
- onClick = { selectedRecent = null },
- backdrop = backdrop,
- surfaceColor = if (isLight) Color.Black.copy(0.06f) else Color.White.copy(0.1f),
- modifier = Modifier.size(28.dp)
- ) {
- CloseCrossIcon(Modifier.size(14.dp), sub)
- }
- }
-
- // Thin divider under the header.
- Box(
- Modifier
- .fillMaxWidth()
- .padding(top = 6.dp, bottom = 2.dp)
- .height(1.dp)
- .background(if (isLight) Color.Black.copy(0.06f) else Color.White.copy(0.08f))
- )
-
- // Clean vertical action list (WhatsApp-style), lightly staggered in.
- Box(Modifier.graphicsLayer { alpha = b1Scale.coerceIn(0f, 1f) }) {
- ActionSheetItem(Icons.Rounded.FileOpen, stringResource(R.string.recents_open), Color(0xFF0088FF), text) {
- selectedRecent = null
- onRecentFileSelected(recent.uri)
- }
+ onClick = { selectedRecent = null; onRecentFileSelected(recent.uri) },
+ backdrop = backdrop, tint = Color(0xFF0088FF), modifier = Modifier.size(46.dp)
+ ) { Icon(Icons.Rounded.FileOpen, stringResource(R.string.recents_open), Modifier.size(21.dp), Color.White) }
}
- Box(Modifier.graphicsLayer { alpha = b2Scale.coerceIn(0f, 1f) }) {
- ActionSheetItem(Icons.Rounded.IosShare, stringResource(R.string.recents_share), Color(0xFF34C759), text) {
- selectedRecent = null
- val shareIntent = Intent(Intent.ACTION_SEND).apply {
- type = "application/pdf"
- putExtra(Intent.EXTRA_STREAM, recent.uri)
- addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
- }
- context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.recents_share_pdf)))
- }
+ Box(Modifier.graphicsLayer { scaleX = b2Scale; scaleY = b2Scale; alpha = b2Scale.coerceIn(0f, 1f) }) {
+ LiquidIconButton(
+ onClick = {
+ selectedRecent = null
+ val shareIntent = Intent(Intent.ACTION_SEND).apply {
+ type = "application/pdf"
+ putExtra(Intent.EXTRA_STREAM, recent.uri)
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+ }
+ context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.recents_share_pdf)))
+ },
+ backdrop = backdrop, tint = Color(0xFF34C759), modifier = Modifier.size(46.dp)
+ ) { Icon(Icons.Rounded.IosShare, stringResource(R.string.recents_share), Modifier.size(20.dp), Color.White) }
}
- Box(Modifier.graphicsLayer { alpha = b3Scale.coerceIn(0f, 1f) }) {
- ActionSheetItem(Icons.Rounded.Info, stringResource(R.string.recents_details), Color(0xFF8E8E93), text) {
- selectedRecent = null
- infoRecent = recent
- }
+ Box(Modifier.graphicsLayer { scaleX = b3Scale; scaleY = b3Scale; alpha = b3Scale.coerceIn(0f, 1f) }) {
+ LiquidIconButton(
+ onClick = { selectedRecent = null; infoRecent = recent },
+ backdrop = backdrop, tint = Color(0xFF8E8E93), modifier = Modifier.size(46.dp)
+ ) { Icon(Icons.Rounded.Info, stringResource(R.string.recents_details), Modifier.size(21.dp), Color.White) }
}
- Box(Modifier.graphicsLayer { alpha = b4Scale.coerceIn(0f, 1f) }) {
- ActionSheetItem(Icons.Rounded.DeleteOutline, stringResource(R.string.recents_remove), redAccent, redAccent) {
- RecentFilesManager.removeRecent(context, recent.uri)
- recents = recents.filterNot { it.uriString == recent.uri.toString() }
- selectedRecent = null
- }
+ Box(Modifier.graphicsLayer { scaleX = b4Scale; scaleY = b4Scale; alpha = b4Scale.coerceIn(0f, 1f) }) {
+ LiquidIconButton(
+ onClick = {
+ RecentFilesManager.removeRecent(context, recent.uri)
+ recents = recents.filterNot { it.uriString == recent.uri.toString() }
+ selectedRecent = null
+ },
+ backdrop = backdrop, tint = Color(0xFFE53935), modifier = Modifier.size(46.dp)
+ ) { Icon(Icons.Rounded.DeleteOutline, stringResource(R.string.recents_remove), Modifier.size(21.dp), Color.White) }
}
}
}
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.kt
index 89e6671..0554a63 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
@@ -5,6 +5,13 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.Crossfade
import androidx.compose.animation.animateColorAsState
+import androidx.compose.animation.core.animateDpAsState
+import androidx.compose.foundation.gestures.detectDragGesturesAfterLongPress
+import androidx.compose.foundation.gestures.detectTapGestures
+import androidx.compose.material.icons.rounded.KeyboardArrowUp
+import androidx.compose.runtime.mutableFloatStateOf
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.platform.LocalDensity
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
@@ -114,6 +121,7 @@ internal fun PdfViewerBottomToolbar(
onOpenExportedFile: () -> Unit,
onOpenAnotherPdf: () -> Unit,
onShareDocument: () -> Unit,
+ onEditorOpenChanged: (Boolean) -> Unit = {},
onRecolorSignature: (Long) -> Unit,
backdrop: LayerBackdrop,
uiSensor: UISensor,
@@ -132,10 +140,8 @@ internal fun PdfViewerBottomToolbar(
// Collapsed by default (just the "Editor Tools" pill + "Open PDF" circle). Tapping
// the pill expands the tool set above it. Image selection auto-expands so its tools show.
var editorOpen by remember { mutableStateOf(false) }
- // Long-press the "Open another PDF" circle to morph it into a Share action; auto-reverts.
- var shareMode by remember { mutableStateOf(false) }
- val haptics = LocalHapticFeedback.current
- LaunchedEffect(shareMode) { if (shareMode) { delay(3500); shareMode = false } }
+ // Tell the viewer when the Editor Tools panel is open so it won't auto-hide the chrome.
+ LaunchedEffect(editorOpen) { onEditorOpenChanged(editorOpen) }
// Any active tool implies the editor is open (survives the chrome auto-hiding/returning).
LaunchedEffect(activeTool, activeImageId) {
if (activeTool != PdfEditTool.None || activeImageId != null) editorOpen = true
@@ -502,32 +508,86 @@ internal fun PdfViewerBottomToolbar(
)
}
}
- // Tap = open another PDF. Long-press morphs it into a Share button (icon
- // cross-fades, surface eases to Apple blue), then a tap shares the doc.
- val shareBlue = Color(0xFF0A84FF)
- val morphSurface by animateColorAsState(
- if (shareMode) shareBlue else glass, tween(220), label = "shareMorphSurface"
+ // Tap = open another PDF. Press-and-hold morphs the circle into a vertical
+ // capsule; swipe up and release to share the current document.
+ ShareMorphButton(
+ backdrop = backdrop,
+ uiSensor = uiSensor,
+ glass = glass,
+ fg = fg,
+ onOpen = onOpenAnotherPdf,
+ onShare = onShareDocument
)
- LiquidIconButton(
- onClick = {
- if (shareMode) { onShareDocument(); shareMode = false } else onOpenAnotherPdf()
- },
- onLongClick = {
- shareMode = !shareMode
+ }
+ }
+ }
+}
+
+/**
+ * The "Open another PDF" circle, upgraded with an Apple-style share gesture: tap opens a new PDF;
+ * press-and-hold morphs the circle into a vertical glass capsule, and swiping up past a threshold
+ * (then releasing) shares the current document. Uses press-then-drag in one motion, so the glass
+ * only re-blurs during the brief height/color morph — never per drag frame.
+ */
+@Composable
+private fun ShareMorphButton(
+ backdrop: LayerBackdrop,
+ uiSensor: UISensor,
+ glass: Color,
+ fg: Color,
+ onOpen: () -> Unit,
+ onShare: () -> Unit
+) {
+ var shareMode by remember { mutableStateOf(false) }
+ var dragUp by remember { mutableFloatStateOf(0f) }
+ val haptics = LocalHapticFeedback.current
+ val density = LocalDensity.current
+ val thresholdPx = with(density) { 44.dp.toPx() }
+ val blue = Color(0xFF0A84FF)
+
+ val height by animateDpAsState(if (shareMode) 104.dp else 52.dp, label = "shareMorphHeight")
+ val surface by animateColorAsState(if (shareMode) blue else glass, tween(200), label = "shareMorphSurface")
+ val progress = (-dragUp / thresholdPx).coerceIn(0f, 1f)
+
+ Box(
+ Modifier
+ .width(52.dp)
+ .height(height)
+ .liquidGlassPanel(backdrop, uiSensor, containerColorOverride = surface)
+ .pointerInput(Unit) {
+ detectTapGestures(onTap = { if (!shareMode) onOpen() })
+ }
+ .pointerInput(Unit) {
+ detectDragGesturesAfterLongPress(
+ onDragStart = {
+ shareMode = true; dragUp = 0f
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
},
- backdrop = backdrop,
- surfaceColor = morphSurface,
- modifier = Modifier.size(52.dp)
- ) {
- Crossfade(targetState = shareMode, animationSpec = tween(200), label = "shareMorphIcon") { sharing ->
- if (sharing) {
- Icon(Icons.Rounded.IosShare, stringResource(R.string.viewer_share_document), Modifier.size(20.dp), Color.White)
- } else {
- Icon(Icons.Rounded.UploadFile, stringResource(R.string.viewer_open_another), Modifier.size(20.dp), fg)
+ onDrag = { change, amount -> change.consume(); dragUp += amount.y },
+ onDragEnd = {
+ if (dragUp < -thresholdPx) {
+ onShare()
+ haptics.performHapticFeedback(HapticFeedbackType.LongPress)
}
- }
+ shareMode = false; dragUp = 0f
+ },
+ onDragCancel = { shareMode = false; dragUp = 0f }
+ )
+ },
+ contentAlignment = Alignment.Center
+ ) {
+ Crossfade(targetState = shareMode, animationSpec = tween(180), label = "shareMorphContent") { sharing ->
+ if (sharing) {
+ Column(
+ horizontalAlignment = Alignment.CenterHorizontally,
+ verticalArrangement = Arrangement.spacedBy(6.dp)
+ ) {
+ // The chevron brightens as you drag toward the release threshold.
+ Icon(Icons.Rounded.KeyboardArrowUp, null, Modifier.size(18.dp), Color.White.copy(alpha = 0.5f + 0.5f * progress))
+ Icon(Icons.Rounded.IosShare, stringResource(R.string.viewer_share_document), Modifier.size(20.dp), Color.White)
}
+ } else {
+ Icon(Icons.Rounded.UploadFile, stringResource(R.string.viewer_open_another), Modifier.size(20.dp), fg)
}
}
}
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.kt
index ce9a970..97a8578 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
@@ -147,6 +147,9 @@ fun PdfViewerScreen(
// ── Local UI state ─────────────────────────────────────────────────────
var controlsVisible by rememberSaveable { mutableStateOf(true) }
var controlsPinned by rememberSaveable { mutableStateOf(false) }
+ // True while the bottom "Editor Tools" panel is expanded — keeps the chrome from auto-hiding
+ // so the user can browse tools without it disappearing.
+ var editorToolsOpen by rememberSaveable { mutableStateOf(false) }
var lastInteractionAtMs by rememberSaveable { mutableStateOf(System.currentTimeMillis()) }
// Adobe-style single-axis reading: the viewer is vertical-only. Horizontal
// panning is still allowed inside a zoomed page (handled in PdfContinuousPage).
@@ -307,13 +310,14 @@ fun PdfViewerScreen(
showFindBar = false; findQuery = ""; viewModel.clearSearch()
}
- LaunchedEffect(state.document, controlsVisible, controlsPinned, activeTool, lastInteractionAtMs) {
- if (state.document != null && controlsVisible && !controlsPinned && scale <= 1.01f && activeTool == PdfEditTool.None) {
+ LaunchedEffect(state.document, controlsVisible, controlsPinned, activeTool, editorToolsOpen, lastInteractionAtMs) {
+ if (state.document != null && controlsVisible && !controlsPinned && scale <= 1.01f && activeTool == PdfEditTool.None && !editorToolsOpen) {
val snap = lastInteractionAtMs
// Comfortable auto-hide window; any interaction bumps lastInteractionAtMs and
- // restarts this, and it never fires while a tool is active (activeTool != None).
+ // restarts this. It never fires while a tool is active (activeTool != None) OR while
+ // the Editor Tools panel is open, so browsing tools won't hide the chrome.
delay(5000)
- if (controlsVisible && !controlsPinned && scale <= 1.01f && activeTool == PdfEditTool.None && snap == lastInteractionAtMs)
+ if (controlsVisible && !controlsPinned && scale <= 1.01f && activeTool == PdfEditTool.None && !editorToolsOpen && snap == lastInteractionAtMs)
controlsVisible = false
}
}
@@ -817,6 +821,7 @@ fun PdfViewerScreen(
onDismissExportFeedback = { viewModel.clearExportFeedback() },
onOpenExportedFile = { state.lastExportedUri?.let { viewModel.openPdf(context, it) } },
onOpenAnotherPdf = { pdfPickerLauncher.launch(arrayOf("*/*")) },
+ onEditorOpenChanged = { editorToolsOpen = it },
onShareDocument = {
val uri = state.document?.uri
if (uri != null) {
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 45eba45..3900aa6 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
@@ -263,8 +263,8 @@ fun SettingsScreen(
LiquidButton(
onClick = { onThemeModeChanged(option.idx) },
backdrop = backdrop,
- tint = if (isSelected) option.activeColor else Color.Transparent,
- surfaceColor = if (isSelected) option.activeColor.copy(0.18f) else (if (isLight) Color.White.copy(0.16f) else Color.White.copy(0.08f)),
+ tint = if (isSelected) option.activeColor else Color.Unspecified,
+ surfaceColor = if (isSelected) Color.Unspecified else (if (isLight) Color.Black.copy(0.06f) else Color.White.copy(0.10f)),
modifier = Modifier.weight(1f)
) {
Row(
@@ -327,8 +327,8 @@ fun SettingsScreen(
LiquidButton(
onClick = { onLocaleChanged(opt.code) },
backdrop = backdrop,
- tint = if (isSelected) accent else Color.Transparent,
- surfaceColor = if (isSelected) accent.copy(0.18f) else (if (isLight) Color.White.copy(0.16f) else Color.White.copy(0.08f)),
+ tint = if (isSelected) accent else Color.Unspecified,
+ surfaceColor = if (isSelected) Color.Unspecified else (if (isLight) Color.Black.copy(0.06f) else Color.White.copy(0.10f)),
modifier = Modifier.weight(1f)
) {
BasicText(