In Jetpack Compose + MVVM I have a parent screen w...
# compose
p
In Jetpack Compose + MVVM I have a parent screen with 3 child screens (via Navigation). Each child generates a PDF differently (download, local build, etc.), but all need to display, email, and print it. Right now each child stores the PDF in its own
uiState
, then I use
LaunchedEffect
to pass it up to the parent, which also stores it. That duplicates state and breaks Single Source of Truth. Example of my parent section receiving the pdf and storing it in it's own uistate to do actions with it:
Copy code
composable(InfractionsDestinations.Pending.name) {
    PendingScreen(
        infractions = uiState.pendingInfractions,
        onPDFDisplayRequested = { pdf -> vm.storePDFForDisplayingItAndOtherActions(pdf) }
    )
}
Child ViewModel:
Copy code
data class UiState(val loading: Boolean = false, val pdf: PDF? = null)
Child Composable:
Copy code
LaunchedEffect(uiState.pdf) {
    uiState.pdf?.let { onPDFDisplayRequested(it) }
}
👉 Question: What’s the recommended Compose/MVVM strategy to avoid duplicating the PDF in both child and parent state, while still letting each child generate it?
g
hmm looks like you need a singleton to handle that (be it a datasource or a "manager")