masteramyx
12/13/2022, 12:02 AMPresentation
class. Currently using legacy views and I was exploring updating those views to Compose.
I've tried different approaches for interop here, unsuccessfully.
The problem is ViewTreeLifecycleOwner not found from android.widget.LinearLayout
I don't believe my problem is an outdated library, I've come across many answers referring to appCompat, fragment-ktx, etc. versions. However the versions in my project are up-to-date.
Is there something unique about incorporating Compose UI content in a Presentation class like this?masteramyx
12/13/2022, 12:02 AM<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Kotlin:
class PresentationView(val context: Context, display: Display) :
Presentation(context, display) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.initial).apply {
findViewById<ComposeView>(R.id.compose_view).setContent {
PresentationView()
}
}
}
}
Error:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from android.widget.LinearLayout{934d0e2 V.E...... ......I. 0,0-0,0}
at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareWindowRecomposer(WindowRecomposer.android.kt:349)
at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareWindowRecomposer$default(WindowRecomposer.android.kt:324)
at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:168)
at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:224)
at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:299)
at androidx.compose.ui.platform.AbstractComposeView.resolveParentCompositionContext(ComposeView.android.kt:242)
at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:249)
at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.android.kt:281)
at android.view.View.dispatchAttachedToWindow(View.java:19553)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3430)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2028)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
at android.view.Choreographer.doCallbacks(Choreographer.java:790)
at android.view.Choreographer.doFrame(Choreographer.java:725)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Ian Lake
12/13/2022, 1:20 AMViewTreeLifecycleOwner
in this channel? There are a couple of threads about this, such as:
• https://kotlinlang.slack.com/archives/CJLTWPH7S/p1607795847192900
• https://kotlinlang.slack.com/archives/CJLTWPH7S/p1619646833068500?thread_ts=1619643434.059400&cid=CJLTWPH7SIan Lake
12/13/2022, 1:21 AMComponentActivity
or its subclasses or a DialogFragment
), then you need to set them yourself with whatever is the appropriate Lifecycle
and SavedStateRegistry
for your window