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
PDF open: first page rendered with the document (no dark wait), paper-sheet placeholder instead of black curtain
Chethan616f49997cda70c
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 e14c073..3115972 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@@ -46,6 +46,8 @@ import androidx.compose.foundation.layout.Spacerimport androidx.compose.foundation.layout.WindowInsetsimport androidx.compose.foundation.layout.imeimport androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.aspectRatio+import androidx.compose.animation.core.animateFloatimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.imeimport androidx.compose.foundation.layout.imePadding@@ -578,7 +580,7 @@ fun PdfViewerScreen(val openingHandedDoc = !askingPassword && state.errorMessage == null && (state.isLoading || pendingLoad)if (openingHandedDoc) {Box(Modifier.fillMaxSize()) {- ViewerLoadingCurtain(isLight = isLight)+ ViewerLoadingCurtain(isLight = isLight, darkPage = darkPageAppearance)// While a password PDF is actually being unlocked, play the padlock "decrypting"// animation over the fill (styled after the onboarding page-5 demos). Plain opening// fills (a normal load) show nothing extra — a lock would be misleading there.@@ -1986,7 +1988,7 @@ fun PdfViewerScreen(// fill and spinner, the hand-off between them is invisible; only when the first bitmap arrives// does this fade away, letting the real document appear underneath. That is what makes tapping// a recent read as "wait a beat, then the PDF fades in" instead of a hard cut to an empty page.- val firstPageRendered = state.pageBitmaps.getOrNull(0) != null+ val firstPageRendered = state.pageBitmaps.getOrNull(state.currentPage) != nullvar revealDocument by remember { mutableStateOf(false) }LaunchedEffect(firstPageRendered) {if (firstPageRendered && !revealDocument) {@@ -2003,7 +2005,7 @@ fun PdfViewerScreen(exit = fadeOut(tween(300, easing = androidx.compose.animation.core.LinearOutSlowInEasing)),modifier = Modifier.fillMaxSize()) {- ViewerLoadingCurtain(isLight = isLight)+ ViewerLoadingCurtain(isLight = isLight, darkPage = darkPageAppearance)}}@@ -2040,9 +2042,28 @@ fun PdfViewerScreen(* "opening" animation — deliberately just a dissolve.*/@Composable-private fun ViewerLoadingCurtain(isLight: Boolean) {+private fun ViewerLoadingCurtain(isLight: Boolean, darkPage: Boolean = false) {val bg = if (isLight) Color(0xFF0A0E14) else Color(0xFF05070B)- Box(Modifier.fillMaxSize().background(bg))+ // A sheet of paper where page 1 will land (same top inset as the page list), so the opening zoom+ // shows a document arriving rather than a black void; the real page fades in over it.+ val sheet = if (darkPage) Color(0xFF16181C) else Color(0xFFF7F7F5)+ val shimmer = androidx.compose.animation.core.rememberInfiniteTransition(label = "sheetShimmer")+ val glow = shimmer.animateFloat(+ initialValue = 0f,+ targetValue = 1f,+ animationSpec = androidx.compose.animation.core.infiniteRepeatable<Float>(tween(1100), androidx.compose.animation.core.RepeatMode.Reverse),+ label = "sheetGlow"+ )+ Box(Modifier.fillMaxSize().background(bg)) {+ Box(+ Modifier+ .padding(top = 10.dp)+ .fillMaxWidth()+ .aspectRatio(1f / 1.414f)+ .graphicsLayer { alpha = 0.92f + 0.08f * glow.value }+ .background(sheet)+ )+ }}/**diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt b/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.ktindex ede774b..7768cc3 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt@@ -279,6 +279,14 @@ class PdfViewerViewModel(private val openPdfUseCase: OpenPdfUseCase) : ViewModel?.currentPage?.coerceIn(0, (doc.pageCount - 1).coerceAtLeast(0))?: 0+ // First paint rides along with the document: the page the reader lands on is+ // rasterised here, at a quick preview width, BEFORE the viewer is told the document+ // exists — so the viewer appears with its page instead of a dark curtain waiting for a+ // compose -> request -> render round trip. The screen re-requests full width next.+ val firstPaint = withContext(AppDispatchers.pdf) {+ runCatching { openPdfUseCase.renderPage(doc, resumePage, MIN_RENDER_WIDTH) }.getOrNull()+ }+ if (firstPaint != null) renderedPageWidths[resumePage] = MIN_RENDER_WIDTH_uiState.value = _uiState.value.copy(fileName = displayName,pageCount = doc.pageCount,@@ -293,7 +301,7 @@ class PdfViewerViewModel(private val openPdfUseCase: OpenPdfUseCase) : ViewModel// password-opened PDF this is still the encrypted original the user picked.originalUri = uri,sizeBytes = doc.sizeBytes,- pageBitmaps = List(doc.pageCount) { null },+ pageBitmaps = List(doc.pageCount) { if (it == resumePage) firstPaint else null },ocrBlocksByPage = emptyMap(),ocrPagesInProgress = emptySet(),isExporting = false,