That "dirty road" which for now is only previewing via a View in the IDE, could be making an accessibility service, be it to customize the device, bring special features, or provide accessibility features. In any cases, I think it can be more… accessible 🙂
So I wrote all of this boilerplate:
val 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(…)
…