Jetpack Compose 中ComposeView 绑定到Dialog中遇到的问题

文章目录

在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

ComponentActivity 源码 1.2.0-alpha08

评论

0 条留言

还没有留言,欢迎分享你的想法。