避免任何BTN意外重复点击的最佳方法是什么?

发布于 2025-01-25 19:22:42 字数 1144 浏览 4 评论 0原文

我的问题是在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绻影浮沉 2025-02-01 19:22:42

导航框架提供了应用程序中导航状态的最新和同步视图,因此防止多次点击的最安全方法是检查您是否仍在导航目标中,通过使用

navController.currentDestination

并将其与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

navController.currentDestination

and comparing that against the LazyList screen identifier.

我的痛♀有谁懂 2025-02-01 19:22:42
​fun​ NavController.​safeNavigate​(​direction​:​ ​NavDirections​) {​    
       currentDestination?.getAction(direction.actionId)?.​run​ { navigate(direction) }
​}

而不是navcontroller.navigate,使用navcontroller.safenavigate带有相同的参数。

​fun​ NavController.​safeNavigate​(​direction​:​ ​NavDirections​) {​    
       currentDestination?.getAction(direction.actionId)?.​run​ { navigate(direction) }
​}

And instead of navController.navigate, use navController.safeNavigate with the same arguments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文