compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

ModalBottomSheetState.hide() does not change currentValue to Hidden

Open mndsl opened this issue 1 year ago • 2 comments
trafficstars

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

mndsl avatar Feb 01 '24 13:02 mndsl

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?

mazunin-v-jb avatar Feb 01 '24 18:02 mazunin-v-jb

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()}")
    }

mndsl avatar Feb 02 '24 09:02 mndsl

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.

mazunin-v-jb avatar Feb 22 '24 12:02 mazunin-v-jb