封面来源 Unsplash
在Compose 1.2.0-alpha08 以前,可以使用以下代码
val dialog = Dialog(context)
dialog.window?.decorView?.apply {
ViewTreeLifecycleOwner.set(this, this@MainActivity)
ViewTreeViewModelStoreOwner.set(this, this@MainActivity)
ViewTreeSavedStateRegistryOwner.set(this, this@MainActivity)
}
在Compose 1.2.0-alpha08以后,ViewTreeSavedStateRegistryOwner
的API发生了变更
val dialog = BottomSheetDialog(this@MainActivity)
dialog.window?.decorView?.apply {
ViewTreeLifecycleOwner.set(this, this@MainActivity)
ViewTreeViewModelStoreOwner.set(this, this@MainActivity)
setViewTreeSavedStateRegistryOwner(this@MainActivity)
}
参考内容
更新日志: Update ViewTreeSavedStateRegistryOwner use in Compose UI