79814419

Date: 2025-11-08 19:58:19
Score: 2
Natty:
Report link

Are you assuming this line would work, magically ?

newFragment.arguments = bundleOf("uri" to uri)

Nevertheless, I am trying to use the PdfViewer composable itself, with "1.0.0-alpha11" dependency, and this minimalist code doesn't work out-of-the-box.

/* dependency-libraries
androidx.pdf:pdf-compose:$version
androidx.pdf:pdf-document-service:$version
*/

@Composable
fun PdfViewerScreen(
    fileUri: android.net.Uri // "content://..."
) {
    val context = LocalContext.current.applicationContext // Just-in-case
    val state = remember { androidx.pdf.compose.PdfViewerState() }
    var doc by remember { mutableStateOf<androidx.pdf.PdfDocument?>(null) }

    LaunchedEffect(fileUri) {
        doc = androidx.pdf.SandboxedLoader(
                context, 
                Dispatchers.IO
            ).openDocument(fileUri)
    }

    DisposableEffect(doc) {
        onDispose { doc?.close() } // Closable PdfDocument
    }

    doc?.also {
        androidx.pdf.compose.PdfViewer(
            modifier = Modifier.fillMaxSize(),
            pdfDocument = doc,
            state = state
        )
    }
}

What also bothers me is that there's no Loading-State callbacks, error callbacks ?

Reasons:
  • Blacklisted phrase (1): I am trying to
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: AndroidRocks