google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.43k stars 598 forks source link

BottomSheetScaffold does not adhere to the Swipeable Anchor Points... #1517

Closed LilMoke closed 1 year ago

LilMoke commented 1 year ago

Describe the bug

The following code is a snippet that creates a BottomSheetScaffold with a swipeable Modifier that as three anchor points, but when moving the bottom sheet up or down it just expands to full screen or collapses to the sheetPeekHeight:

val scaffoldState = rememberBottomSheetScaffoldState()
val swipeableState = rememberSwipeableState(initialValue = 0f)
val coroutineScope = rememberCoroutineScope()
    BottomSheetScaffold(
        scaffoldState = scaffoldState,
        sheetContent = {
            Column(
                Modifier
                    .fillMaxSize()
            ) {
                Text("Sheet content")
            }
        },
        sheetPeekHeight = 92.dp, // start collapsed
        sheetShape = RoundedCornerShape(16.dp),
        sheetBackgroundColor = Color.LightGray,
        sheetGesturesEnabled = true,
        modifier = Modifier
            .fillMaxSize()
            .    val scaffoldState = rememberBottomSheetScaffoldState()
    val swipeableState = rememberSwipeableState(initialValue = 0f)
    val coroutineScope = rememberCoroutineScope()

    BottomSheetScaffold(
        scaffoldState = scaffoldState,
        sheetContent = {
            Column(
                Modifier
                    .fillMaxSize()
            ) {
                Text("Sheet content")
            }
        },
        sheetPeekHeight = 92.dp, // start collapsed
        sheetShape = RoundedCornerShape(16.dp),
        sheetBackgroundColor = Color.LightGray,
        sheetGesturesEnabled = true,
        modifier = Modifier
            .fillMaxSize()
            .swipeable(
                state = swipeableState,
                anchors = mapOf(
                    0f to 0f,
                    0.5f to 0.5f,
                    0.1f to 0.1f
                ), // define stopping points
                orientation = Orientation.Vertical,
                resistance = null
            )
    ) {
        Column(Modifier.fillMaxSize()) {
            TopAppBar(
                title = { Text("Bottom Sheet Example") }
            )
            Text("Content")
        }
    }
(
                state = swipeableState,
                anchors = mapOf(
                    0f to 0f,
                    0.5f to 0.5f,
                    0.1f to 0.1f
                ), // define stopping points
                orientation = Orientation.Vertical,
                resistance = null
            )
    ) {
        Column(Modifier.fillMaxSize()) {
            TopAppBar(
                title = { Text("Bottom Sheet Example") }
            )
            Text("Content")
        }
    }

Expected behavior

Swiping the BottomSheetScaffold should stop at three points, not just fullscreen or sheetpeekheight.

jossiwolf commented 1 year ago

Hi, this is not an Accompanist component. You'd want to file an issue upstream.

However, this is not intended to work. The anchors are not meant to be customized. They are defined internally in the component (https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt;l=426;drc=782309ea04a9712abcfa7e2b8ff8c6187d40a748). If you want custom anchors, we recommend building your own component.