raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.23k stars 134 forks source link

Pass/Access ContentPadding in Child-Destinations #663

Closed cwsiteplan closed 4 months ago

cwsiteplan commented 4 months ago

As of Android 15 apps will be drawing under status/navbar per default. So we need to handle insets in the destinations properly.

Scaffold(bottomBar = {
                            BottomBar(
showBottomBar
                            )
                        }) { contentPadding ->
                            DestinationsNavHost(...) {...}

Having a bottomBar that is shown/hidden depending on certain destinations will influence the contentPadding of for the Destinations - so i thought i will just expose a "getter" for the contentPadding as dependency to be accessed in the destinations then.

@Composable
@Destination<PhotosNavGraph>(navArgs = PhotoGalleryNavArgs::class, start = true)
fun PhotoGalleryScreen(
    navigator: DestinationsNavigator,
    getContainerPadding: () -> PaddingValues,
    modifier: Modifier = Modifier,
) {

Problem is now that the contentpadding is only updated after the navigation is finished -> Destination is being rendered before the bottom bar is hidden.

(I do have child-destinations were the bottom bar is shown - woulnd't be a problem if the bottom bar is only visible at the top-level - then i could ignore the inset)

Any Idea to overcome that issue?

cwsiteplan commented 4 months ago

i managed to get it working by using contentWindowInsets on the scaffold of the child destination. not quite sure why this works not, potentially bc. the scaffold is recomposed a few times and by then the parent has adjusted it's insets.