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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744312566a4568019.html
评论列表(0条)