compose-multiplatform
compose-multiplatform copied to clipboard
ModalBottomSheetState.hide() does not change currentValue to Hidden
Describe the bug Calling ModalBottomSheetState.hide() does not change its currentValue property to Hidden after the animation ends.
Affected platforms
- Android, iOS, possibly All
Versions
- Kotlin version*: 1.9.22
- Compose Multiplatform version*: 1.5.12
- OS version(s)* (required for Desktop and iOS issues): iOS 15.4.1
To Reproduce
val sheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
skipHalfExpanded = true
)
CoroutineScope(Dispatchers.Main).launch {
sheetState.show()
println("SheetState: ${sheetState.currentValue}") //prints Expanded
sheetState.hide()
println("SheetState: ${sheetState.currentValue}") //prints Expanded
}
Expected behavior after call to sheetState.hide(), sheetState.currentValue should be Hidden
Hello, thank you for submitting the issue. I can't reproduce it, the provided code snippet works as expected. Could you please try it on the latest version 1.6.0-beta01?
The root of the issue appears to be in the confirmValueChange callback. If one call sheetState.show() or hide() and confirmValueChange returns false, the sheet opens or closes, but the currentValue (as well as isVisible) remains unchanged.
To reproduce :
val sheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
skipHalfExpanded = true,
confirmStateChange = { false }
)
LaunchedEffect(Unit) {
println("CurrentValue -> ${sheetState.currentValue} -> ${Clock.System.now().toEpochMilliseconds()}")
sheetState.show()
println("CurrentValue -> ${sheetState.currentValue} -> ${Clock.System.now().toEpochMilliseconds()}")
sheetState.hide()
println("CurrentValue -> ${sheetState.currentValue} -> ${Clock.System.now().toEpochMilliseconds()}")
}
As far as I'm understanding it, the confirmStateChange callback is optional callback for manual handling of the state changing. So, if you always return false in it, it won't change ModalBottomSheetState values.
I don't see any issues with it, so I consider closing this ticket.
If you don't agree with me, I can suggest opening a new ticket in Jetpack Compose issue tracker because it's behavior common for all the other platforms.