避免任何BTN意外重复点击的最佳方法是什么?
我的问题是在lazyverticalgrid元素上意外重复单击,该元素通过使用以下方式解决以下问题:
var启用,由可记住的{mutableStateOf(true)}
and code> val scope = locallifecyclelent.current.current.current.current.lifecycyclescope 。
LazyVerticalGrid(
state = lazyVGState,
cells = GridCells.Fixed(3),
contentPadding = PaddingValues(bottom = 100.dp)
) {
items(groupMap.keys.toList().sorted()) { item ->
Column(
modifier = Modifier.clickable(
enabled = enabled,
) {
enabled = false
navController.currentBackStackEntry?.savedStateHandle?.set(
CITY_WEATHER_LIST,
cityList
)
navController.navigate(Screen.CityForecastScreen.route)
scope.launchWhenStarted {
delay(10)
enabled = true
}
},
) {
// some elements
}
}
}
如果我不使用启用状态,则用户可以打开几次元素。 寻找社区意见。 谢谢。
My problem was accidentally repeated clicks on LazyVerticalGrid element which is resolved by using:
var enabled by rememberSaveable { mutableStateOf(true) }
and val scope = LocalLifecycleOwner.current.lifecycleScope
.
LazyVerticalGrid(
state = lazyVGState,
cells = GridCells.Fixed(3),
contentPadding = PaddingValues(bottom = 100.dp)
) {
items(groupMap.keys.toList().sorted()) { item ->
Column(
modifier = Modifier.clickable(
enabled = enabled,
) {
enabled = false
navController.currentBackStackEntry?.savedStateHandle?.set(
CITY_WEATHER_LIST,
cityList
)
navController.navigate(Screen.CityForecastScreen.route)
scope.launchWhenStarted {
delay(10)
enabled = true
}
},
) {
// some elements
}
}
}
If i don't use enabled state, user may open an element for couple times.
Looking for community opinion.
THX.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
导航框架提供了应用程序中导航状态的最新和同步视图,因此防止多次点击的最安全方法是检查您是否仍在导航目标中,通过使用
并将其与Lazylist屏幕进行比较来 托管Lazylist标识符。
The navigation framework provides an up to date and synchronous view of the navigation state in your app, so the safest way to prevent multiple clicks is by checking if you are still in the navigation destination hosting your LazyList by using
and comparing that against the LazyList screen identifier.
而不是
navcontroller.navigate
,使用navcontroller.safenavigate
带有相同的参数。And instead of
navController.navigate
, usenavController.safeNavigate
with the same arguments.