I'm using jetpack compose 1.0.0 and BottomSheetScaffold was working fine, but after I added a feature to change the theme from light to dark with a button, the bottom sheet won't expand after I change the theme. I'm handling the theme state using a property on the Application class. Here's some code:
Screen that's using the bottom sheet, this is on a fragment btw
MyAppTheme(application.isDark.value) {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed)
)
val coroutineScope = rememberCoroutineScope()
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
HomeBottomSheet(
onCancelClick = {
coroutineScope.launch {
bottomSheetScaffoldState.bottomSheetState.collapse()
}
},
onDoneClick = { text ->
Toast.makeText(requireContext(), text, Toast.LENGTH_LONG)
.show()
}
)
},
sheetPeekHeight = 0.dp
) {
HomeScreen(
darkTheme = application.isDark.value,
darkThemeToggleClick = application::toggleDarkTheme,
onHistoryClick = {
findNavController().navigate(R.id.goToHistory)
},
onAddClick = {
coroutineScope.launch {
bottomSheetScaffoldState.bottomSheetState.expand()
}
}
)
}
}
Application:
class MyApp: Application() {
val isDark = mutableStateOf(false)
fun toggleDarkTheme() {
isDark.value = !isDark.value
}
}
Looks like a problem in initialization bottomSheetScaffoldState
Should be
val scaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberBottomSheetState(BottomSheetValue.Collapsed)
)