我在撰写时遇到问题。我尝试实现简单的日历。我已经显示了月份,并启用了通过箭头更改月份。
现在我想通过滑动添加更改月份。我尝试过.swipeable
这是示例:
val size = remember { mutableStateOf(Size.Zero) }
val swipeableState = rememberSwipeableState(0)
val width = if (size.value.width == 0f) 1f else size.value.width - 60.dp.value * 2
Box(
modifier = Modifier
.fillMaxWidth()
.onSizeChanged { size.value = Size(it.width.toFloat(), it.height.toFloat()) }
.swipeable(
state = swipeableState,
anchors = mapOf(0f to 0, width to 1),
thresholds = { _, _ -> FractionalThreshold(0.3f) },
orientation = Orientation.Horizontal
)
.background(Color.LightGray)
) {
Box(
Modifier
.offset { IntOffset(swipeableState.offset.value.roundToInt(), 0) }
.size(60.dp)
.background(Color.DarkGray)
)
}
Run Code Online (Sandbox Code Playgroud)
但这并不完美。我需要保留在日历区域之外,并且我不知道如何更改月份状态(响应显示日历)。 …