Tomas Škarnulis
09/23/2023, 10:30 AMBottomSheetScaffold
and NavHost
App is using NavHost
that has nested navigation inside where few screens will be attached to main NavHost
, and other smaller one - to BottomSheetScaffold
NavHost
In first init of the screen bottom sheet can not be hidden on swipe.
Then, if we navigate from nav graph that has bottom sheet to other navigation - on back BottomSheetScaffold
can be hidden. 😄
Other thing, if we leave screen with BottomSheetScaffold
expanded - on back we will get :
IllegalStateException - If the offset has not been initialized yet
I am assuming that NavHost
somehow recreates screen maybe, and rememberStandardBottomSheetState
initialised again... Still figuring this out, just wanted to share maybe someone already solved similar situation to this and can give some tips where to lookLaunchedEffect(Unit)
show that states is really recreated on back:
MapAndBottomSheet: creation
MapAndBottomSheet: botSheet 131380672
MapAndBottomSheet: scaffold: 124916473
....
MapAndBottomSheet: creation
MapAndBottomSheet: botSheet 195691014
MapAndBottomSheet: scaffold: 178577607
rememberStandardBottomSheetState
set skipHiddenState to false - this will always let bottom sheet to be hidden on swipe
Than use rememberSaveable
to save last know SheetValue
on confirmValueChange
in rememberStandardBottomSheetState
than I use LaunchedEffect(lastBootomSheetState)
and check last and current sheet value, and if its not a same - I use last value to move bottom sheet + save last = current
Hacky, so will check if it has any issues herePatrick Steiger
09/23/2023, 10:11 PMjossiwolf
09/25/2023, 1:47 PMTomas Škarnulis
09/25/2023, 2:46 PMandroidx.compose.material3:material3:1.2.0-alpha08
androidx.navigation:navigation-compose:2.7.0-beta02
Kotlin version: 1.8.20
jossiwolf
09/25/2023, 2:56 PM