https://kotlinlang.org logo
#compose
Title
# compose
s

Shabinder Singh

06/27/2021, 2:05 PM
When Using Nested NavHost with a seperate navController in BottomSheetScaffold' Sheet , it AUTOMATICALLY EXPANDS! on launch , even when started using Collapsed State... Any Idea how to fix this?, Any help will be appreciated... Note: if i comment out navHost and simply use a Composable in Sheet it doesnt Expand automatically and everything works as Expected
n

Nipun Rajput

06/28/2021, 4:10 AM
have you tried the composable with modifier wrapheight for each composable you want to open in bottomsheet? Same happened with me but when i wrapped the screen it worked
s

Shabinder Singh

06/28/2021, 4:23 AM
I havent explicitly applied wrapContent to Modifiers , but the auto Expand only happens when NavHost is in BottomSheet , if I just comment out NavHost and simply add a single Composable there ,like say DockHomeScreen() (being used as Entry Point in NavHost), Bottom Sheet remains in Collapsed State and doesnt automatically expands on app launch.
n

Nipun Rajput

06/28/2021, 4:25 AM
That is why I am saying to apply to each and individual screen and test whether it is work or not
s

Shabinder Singh

06/28/2021, 4:26 AM
Sure , Will do and report back
@Nipun Rajput Nope Your suggestion didn't worked
i

Ian Lake

06/29/2021, 12:22 AM
Did you file an issue for this? https://issuetracker.google.com/issues/new?component=612128 FWIW, I was able to 'fix' your sample by wrapping the
NavHost
in
Box(Modifier.fillMaxSize())
, but adding the same
fillMaxSize()
to the
NavHost
itself doesn't fix it, which leads me to believe something odd is going on in
BottomSheetScaffold
.
And I was able to break your
NormalBottomSheet
by swapping out your
sheetContent
for:
Copy code
sheetContent = {
    var callback by remember { mutableStateOf<(() -> Unit)?>(null) }
    LaunchedEffect(Unit) {
        // Set the callback after the initial composition
        callback = {
            callback = null
        }
    }

    if (callback != null) {
        FirstScreen(callback)
    }
},
I.e., showing no content on the first composition (which is what
NavHost
does, since it internally uses
DisposableEffect
)
(interestingly, tapping the
callback
there to set it to null just hides the drawer entirely, but maybe that's expected if you don't have any content)
I was able to 'fix' my broken
NormalBottomSheet
by again surrounding it with a
Box(Modifier.fillMaxSize())
s

Shabinder Singh

06/29/2021, 3:22 AM
Hey @Ian Lake thanks for the troubleshooting help and explaining it so clearly , I havent filed an issue yet , will do in evening
7 Views