Featured image of post Jetpack Compose 中ComposeView 绑定到Dialog中遇到的问题

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

在Compose 1.2.0-alpha08 以前,可以使用以下代码:...

封面来源 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

ComponentActivity 源码 1.2.0-alpha08