louiscad
05/06/2021, 1:56 PMComposeView
from Android Studio? It complains about missing ViewTreeLifecycleOwner
, and ViewTressSavedStateRegistryOwner
😕
Also, does it mean it's impossible to have a compose view outisde of an Activity? I'm thinking about the few WindowManager
use cases.Adam Powell
05/06/2021, 2:01 PMlouiscad
05/06/2021, 2:06 PMYou must attach theGetting a standaloneto aComposeView
.ViewTreeLifecycleOwner
ViewTreeLifecycleOwner
instance for use in the WindowManager
is not really possible, so I'm wondering how it's supposed to work 🤔Adam Powell
05/06/2021, 2:30 PMAdam Powell
05/06/2021, 2:30 PMLifecycleOwner
is just an interface and LifecycleRegistry
is publiclouiscad
05/06/2021, 2:59 PMViewTressSavedStateRegistryOwner
that you can't fakelouiscad
05/06/2021, 3:00 PMWindowManager
, you don't have a Lifecycle
. Making a custom one doesn't seem so great to me.Zach Klippenstein (he/him) [MOD]
05/06/2021, 3:55 PMAdam Powell
05/06/2021, 4:09 PMlouiscad
05/06/2021, 5:52 PMval lifecycleOwner = object : LifecycleOwner {
private val lifecycle = LifecycleRegistry(this)
init {
lifecycle.currentState = Lifecycle.State.STARTED
}
override fun getLifecycle(): Lifecycle = lifecycle
}
val savedStateRegistryOwner = object : SavedStateRegistryOwner {
private val controller = SavedStateRegistryController.create(this)
override fun getLifecycle() = lifecycleOwner.lifecycle
override fun getSavedStateRegistry(): SavedStateRegistry = controller.savedStateRegistry
}
ViewTreeLifecycleOwner.set(it.root, lifecycleOwner)
ViewTreeSavedStateRegistryOwner.set(it.root, savedStateRegistryOwner)
But I still get an error:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from com.android.layoutlib.bridge.impl.Layout{3feb6b45 V.E...... ......ID 0,0-0,0} at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareViewTreeRecomposer(…)
…
louiscad
05/06/2021, 6:14 PM