android Jetpack合成附加功能单击将进行合成

9udxz4iz  于 2022-12-28  发布在  Android
关注(0)|答案(1)|浏览(156)

我的代码

@Composable
fun AlbumPage(navHostController: NavHostController) {
   ElevatedButton(onClick = {
      navHostController.popBackStack()
   }) {
      Text(text = "click")
   }

   SideEffect {
        Log.d("tag","1111")
   }
}

当我在onClick {}中设置navHostController. popBackStack()时,日志显示两次
第一个月
14:53:34.816 D 1111
我删除了navHostController. popBackStack()

@Composable
fun AlbumPage(navHostController: NavHostController) {
   ElevatedButton(onClick = {
      //navHostController.popBackStack()
   }) {
      Text(text = "click")
   }

   SideEffect {
        Log.d("tag","1111")
   }
}

记录一次
为甚么?

58wvjzkj

58wvjzkj1#

源文件NavHostController.kt的描述

When the given navController
 * changes the back stack due to a [NavController.navigate] or [NavController.popBackStack] this
 * will trigger a recompose and return the top entry on the back stack.
 *
 * @return a mutable state of the current back stack entry

相关问题