在Compose 1.2.0-alpha08 以前,可以使用以下代码
Kotlin复制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发生了变更
Kotlin复制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
1 分钟阅读