撰写深层链接导致我的视图模型数据为空
我正在研究一个使用JetPack组成的项目,每当我通过深层链接加载合并时,任何快速加载的数据就会出现,然后丢失。
我的深层链接非常直截了当。
composable(
DestinationScreen.Screen.route + "/{index}",
arguments = listOf(navArgument("index") { type = NavType.StringType }),
deepLinks = listOf(navDeepLink { uriPattern ="pattern/job/{index}" })
) { entry ->
LaunchedEffect(Unit) {
bottomBarState.value = false
}
JobDetails(navController = navController, companyVm = companyViewModel,vm, jobVm,entry.arguments?.getString("index")!! )
}
在我的组合中,我有一个启动效果,该效果调用一个功能来更新ViewModel。
LaunchedEffect(key1 = Unit) {
companyVm.getJob(index) {}
}
我为测试发生的事情所做的只是在视图模型中更改一个值
var job: MutableState<JobModel> = mutableStateOf(JobModel())
fun getJob(jobPostUid: String, onComplete: () -> Unit) {
job.value.jobTitle = "New Title"
}
时,当页面正常通过应用程序加载时,您可以看到新标题,但是当您通过深层链接加载它时,您很快就会看到它出现,然后从日志中消失并从日志中消失。我可以看到它使标题空白。
I am working on a project that uses jetpack compose and whenever i load a composable through deep links, any data that gets loaded quickly appears then goes missing.
My deep link is pretty straight forward.
composable(
DestinationScreen.Screen.route + "/{index}",
arguments = listOf(navArgument("index") { type = NavType.StringType }),
deepLinks = listOf(navDeepLink { uriPattern ="pattern/job/{index}" })
) { entry ->
LaunchedEffect(Unit) {
bottomBarState.value = false
}
JobDetails(navController = navController, companyVm = companyViewModel,vm, jobVm,entry.arguments?.getString("index")!! )
}
Inside my composable i have a launched effect that calls a function to update the viewModel.
LaunchedEffect(key1 = Unit) {
companyVm.getJob(index) {}
}
all i was doing to test what was happening was changing one value in the view model
var job: MutableState<JobModel> = mutableStateOf(JobModel())
fun getJob(jobPostUid: String, onComplete: () -> Unit) {
job.value.jobTitle = "New Title"
}
When the page loads normally through the app you can see the new title but when you load it through a deep link you quickly see it appear then disappear and from logs i can see that it's making the title blank.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论