[英]How can I make a swipeable composable only consume clicks and drags directly on content?
BottomSheetState.Gone
過渡到BottomSheetState.Half
的 FAB。GoogleMap
Composable
。maxHeight
參數是父Composable
的全高(以像素為單位)。@ExperimentalMaterialApi
@Composable
fun AnchoredBottomSheet(
state: BottomSheetState,
maxHeight: Float,
content: @Composable () -> Unit,
) {
val swipeableState = rememberSwipeableState(initialValue = state)
val anchors = mapOf(
BottomSheetState.Gone.toAnchor(maxHeight),
BottomSheetState.Half.toAnchor(maxHeight),
BottomSheetState.Full.toAnchor(maxHeight),
)
Column(
modifier = Modifier
.height(maxHeight.dp)
.swipeable(
enabled = swipeableState.currentValue != BottomSheetState.Gone,
state = swipeableState,
orientation = Orientation.Vertical,
anchors = anchors,
)
.offset {
IntOffset(
0,
swipeableState.offset.value.roundToInt()
)
}
) {
content()
}
}
BottomSheetState.Half
state 或BottomSheetState.Gone
時,GoogleMap
部分,AnchoredBottomSheet
捕獲,並且不會傳遞給可見的( GoogleMap
) Composable
。BottomSheetState.Half
state 中視圖的GoogleMap
部分,它不會收到點擊。 如何使我的底部工作表實現僅消耗底部工作表內容上發生的單擊/拖動?
問題在於Modifier
擴展調用的順序。 Modifier.swipeable()
應該在Modifier.offset()
之后發生。
@ExperimentalMaterialApi
@Composable
fun AnchoredBottomSheet(
state: BottomSheetState,
maxHeight: Float,
content: @Composable () -> Unit,
) {
val swipeableState = rememberSwipeableState(initialValue = state)
val anchors = mapOf(
BottomSheetState.Gone.toAnchor(maxHeight),
BottomSheetState.Half.toAnchor(maxHeight),
BottomSheetState.Full.toAnchor(maxHeight),
)
Column(
modifier = Modifier
.offset {
IntOffset(
x = 0,
y = swipeableState.offset.value.roundToInt(),
)
}
.swipeable(
enabled = swipeableState.currentValue != BottomSheetState.Gone,
state = swipeableState,
orientation = Orientation.Vertical,
anchors = BottomSheetState.getAnchors(maxHeight),
)
) {
content()
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.