https://kotlinlang.org logo
Title
w

wintersoldier

02/15/2023, 11:55 AM
Hi , Is there a way to make ModalBottomSheetLayout non dismissable.
Doing this is not recommended,
val bottomsheetState =
  rememberModalBottomSheetState(
    initialValue = ModalBottomSheetValue.Hidden,
    confirmStateChange = {false}
  )
Is there a workaround.
Can anyone help on this , is there a workaround
t

Tin Tran

02/16/2023, 3:44 AM
You can override the behavior of the back button with your own logic in this case. Does not fix the case when user click on the outside of the content though
w

wintersoldier

02/16/2023, 3:47 AM
Back button handling is fine, only the main issue is when touched outside the content
t

Tin Tran

02/16/2023, 3:55 AM
Is the bottom sheet general for all screens or just 1 specific screen?
If it’s specific then I think the only way to workaround this is to control the bottom sheet yourself and ditch the bottom sheet navigation
w

wintersoldier

02/16/2023, 3:58 AM
I see my usecase is basically create a wrapper around ModalBottomSheetLayout and expose it for all bottomsheet usecases.
t

Tin Tran

02/16/2023, 4:00 AM
U can still use it in other screens that do not require special logic to dismiss the bottom sheet though. It’d save some effort
With the above approach i was facing unintended behaviours.
t

Tin Tran

02/16/2023, 4:05 AM
Let’s say u have screen A with bottom sheet B Instead of doing this
composable("/a){}
bottomSheet("/b"){}
You can do this
composable("/a)
{
 val bottomsheetState =
  rememberModalBottomSheetState(
    initialValue =   ModalBottomSheetValue.Hidden,
    confirmStateChange = {
       // your logic
   }
  BottomSheetModalLayout{


  }

}
w

wintersoldier

02/16/2023, 4:06 AM
Thanks Tin,I will check for the confirmStatChange logic much more deeper
t

Tin Tran

02/16/2023, 4:09 AM
It’s basically just this
onDismiss = {
                    if (sheetState.confirmStateChange(Hidden)) {
                        scope.launch { sheetState.hide() }
                    }
                },
But you can’t override it in the case of bottom sheet navigator because it has to do some synchronization to control the state of the back stack