最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Custom bottom sheet height restriction in fullyExpanded state in jetpack compose - Stack Overflow

programmeradmin7浏览0评论

I'm building a fully customized bottom sheet in jetpack compose and i have specific anchor scenarios

enum class BottomSheetValue {
    Hidden,
    Minimum,
    PartiallyExpanded,
    Expanded;

    val draggableSpaceFraction: Float
        get() = when (this) {
            Hidden -> 0f
            Minimum -> 0.2f
            PartiallyExpanded -> 0.7f
            Expanded -> 0.9f
        }
}

and my updateAnchors logic;

fun updateAnchors(layoutHeight: Int, sheetHeight: Int) {
        val maxDragEndPoint = layoutHeight - 32.dp.toPixel
        val newAnchors = DraggableAnchors {
            BottomSheetValue.entries.forEach { anchor ->
                val fractionatedMaxDragEndPoint = maxDragEndPoint * anchor.draggableSpaceFraction
                val dragEndPoint = layoutHeight - min(fractionatedMaxDragEndPoint, sheetHeight.toFloat())

                anchor at dragEndPoint
            }
        }
        draggableState.updateAnchors(newAnchors)
    }

and my custom bottom sheet;

        Box(
            modifier = modifier
                .fillMaxSize()
                .onSizeChanged {
                    layoutHeight = it.height
                    if (layoutHeight > 0 && sheetHeight > 0) {
                        bottomSheetState.updateAnchors(layoutHeight, sheetHeight)
                    }
                }
        ) {
            Box(
                modifier = Modifier
                    .fillMaxSize()
                    .align(Alignment.BottomCenter)
                    .offset {
                        val yOffset = bottomSheetState
                            .requireOffset()
                            .roundToInt()
                        IntOffset(x = 0, y = yOffset)
                    }
                    .anchoredDraggable(
                        state = bottomSheetState.draggableState,
                        orientation = Orientation.Vertical
                    )
                    .nestedScroll(bottomSheetNestedScrollConnection)
                    .background(sheetBackgroundColor, sheetShape)
                    .padding(vertical = 16.dp),
            ) {
                Box(
                    modifier = Modifier
                        .wrapContentSize()
                        .onSizeChanged {
                            sheetHeight = it.height
                            if (layoutHeight > 0 && sheetHeight > 0) {
                                bottomSheetState.updateAnchors(layoutHeight, sheetHeight)
                            }
                        },
                    content = bottomSheetContent
                )
            }
        }

If the expanded state is 1f, the content is fully visible; expanded value -> 1f

but when i set the expanded value to 0.9f, some items are not visible at the end of the content; expanded value -> 0.9f

Thanks for any help on this topic.

发布评论

评论列表(0)

  1. 暂无评论