Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7bffb9ff authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I7ae7dac9,Ie142cac2 into udc-qpr-dev

* changes:
  Fix ComposeInitializerImpl
  Fix ComposeInitializerImpl to work with new lifecycle libraries
parents 24b72bdf 4b87b578
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -17,9 +17,9 @@
package com.android.systemui.compose

import android.view.View
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.setViewTreeLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryController
import androidx.savedstate.SavedStateRegistryOwner
import com.android.compose.animation.ViewTreeSavedStateRegistryOwner
@@ -27,7 +27,7 @@ import com.android.systemui.lifecycle.ViewLifecycleOwner

internal object ComposeInitializerImpl : ComposeInitializer {
    override fun onAttachedToWindow(root: View) {
        if (ViewTreeLifecycleOwner.get(root) != null) {
        if (root.findViewTreeLifecycleOwner() != null) {
            error("root $root already has a LifecycleOwner")
        }

@@ -54,7 +54,8 @@ internal object ComposeInitializerImpl : ComposeInitializer {

                override val savedStateRegistry = savedStateRegistryController.savedStateRegistry

                override fun getLifecycle(): Lifecycle = lifecycleOwner.lifecycle
                override val lifecycle: Lifecycle
                    get() = lifecycleOwner.lifecycle
            }

        // We must call [ViewLifecycleOwner.onCreate] after creating the [SavedStateRegistryOwner]
@@ -64,13 +65,13 @@ internal object ComposeInitializerImpl : ComposeInitializer {

        // Set the owners on the root. They will be reused by any ComposeView inside the root
        // hierarchy.
        ViewTreeLifecycleOwner.set(root, lifecycleOwner)
        root.setViewTreeLifecycleOwner(lifecycleOwner)
        ViewTreeSavedStateRegistryOwner.set(root, savedStateRegistryOwner)
    }

    override fun onDetachedFromWindow(root: View) {
        (ViewTreeLifecycleOwner.get(root) as ViewLifecycleOwner).onDestroy()
        ViewTreeLifecycleOwner.set(root, null)
        (root.findViewTreeLifecycleOwner() as ViewLifecycleOwner).onDestroy()
        root.setViewTreeLifecycleOwner(null)
        ViewTreeSavedStateRegistryOwner.set(root, null)
    }
}