状态流导致喷气背包中的导航循环构成
应用中有两个屏幕。屏幕A和屏幕B。屏幕A的UI和导航逻辑基于状态类。
筛选
data class ScreenAState(
val sourceName: String = "",
val navigateToScreenB: Boolean = false
)
如果用户满足要求,navigatetScreenb
的值将更改为true
,并且使用以下代码将用户导航到屏幕B。
if (uiState.navigateToScreenB) {
LaunchedEffect(uiState.navigateToScreenB) {
findNavController().navigate(actionToScreenB)
}
}
现在,当用户按下屏幕B上的后退按钮时,问题就会发生。一旦用户从屏幕B返回到屏幕A,用户再次导航到屏幕B,如果再次按下后退按钮,则循环继续屏幕B。
我不确定是否正确使用启动效果
。任何帮助将不胜感激。谢谢。
There are two screens in the app. Screen A and Screen B. The UI and navigation logic of Screen A is based on the state class.
ScreenAState
data class ScreenAState(
val sourceName: String = "",
val navigateToScreenB: Boolean = false
)
If the user meets the requirements, the value of navigateToScreenB
is changed to true
and the user is navigated to Screen B using the following code.
if (uiState.navigateToScreenB) {
LaunchedEffect(uiState.navigateToScreenB) {
findNavController().navigate(actionToScreenB)
}
}
Now, the problem occurs when the user presses the back button on Screen B. As soon as the user comes back from Screen B to Screen A, the user is again navigated to Screen B and the loop continues if the back button is pressed again on Screen B.
I am not sure if I am using the LaunchedEffect
properly. Any help will be appreciated. Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行导航后,您应该将
navigatetoscreenb
设置为false。在您的视图模型中声明这样的内容。
在您的屏幕上:
You should set
navigateToScreenB
to false after perform the navigation.Declaring something like this in your view model.
and in your screen: