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

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

Merge "Delete ViewTreeSavedStateRegistryOwner.kt" into main

parents fd042f14 c832d318
Loading
Loading
Loading
Loading
+13 −28
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import androidx.lifecycle.setViewTreeLifecycleOwner
import androidx.lifecycle.setViewTreeViewModelStoreOwner
import androidx.savedstate.findViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import com.android.systemui.animation.Expandable
import com.android.systemui.animation.TransitionAnimator
import kotlin.math.max
@@ -173,9 +175,7 @@ fun Expandable(
    val wrappedContent =
        remember(content) {
            movableContentOf { expandable: Expandable ->
                CompositionLocalProvider(
                    LocalContentColor provides contentColor,
                ) {
                CompositionLocalProvider(LocalContentColor provides contentColor) {
                    // We make sure that the content itself (wrapped by the background) is at least
                    // 40.dp, which is the same as the M3 buttons. This applies even if onClick is
                    // null, to make it easier to write expandables that are sometimes clickable and
@@ -288,7 +288,7 @@ fun Expandable(
                    .border(controller)
                    .onGloballyPositioned {
                        controller.boundsInComposeViewRoot.value = it.boundsInRoot()
                    },
                    }
            ) {
                wrappedContent(controller.expandable)
            }
@@ -365,19 +365,14 @@ private fun AnimatedContentInOverlay(
                }

            // Set the owners.
            val overlayViewGroup =
                getOverlayViewGroup(
                    context,
                    overlay,
                )
            val overlayViewGroup = getOverlayViewGroup(context, overlay)

            overlayViewGroup.setViewTreeLifecycleOwner(composeViewRoot.findViewTreeLifecycleOwner())
            overlayViewGroup.setViewTreeViewModelStoreOwner(
                composeViewRoot.findViewTreeViewModelStoreOwner()
            )
            ViewTreeSavedStateRegistryOwner.set(
                overlayViewGroup,
                ViewTreeSavedStateRegistryOwner.get(composeViewRoot),
            overlayViewGroup.setViewTreeSavedStateRegistryOwner(
                composeViewRoot.findViewTreeSavedStateRegistryOwner()
            )

            composeView.setParentCompositionContext(compositionContext)
@@ -405,10 +400,7 @@ private fun AnimatedContentInOverlay(
    }
}

internal fun measureAndLayoutComposeViewInOverlay(
    view: View,
    state: TransitionAnimator.State,
) {
internal fun measureAndLayoutComposeViewInOverlay(view: View, state: TransitionAnimator.State) {
    val exactWidth = state.width
    val exactHeight = state.height
    view.measure(
@@ -474,7 +466,7 @@ private fun ContentDrawScope.drawBackground(
                topLeft = Offset(halfStroke, halfStroke),
                size = Size(size.width - strokeWidth, size.height - strokeWidth),
                cornerRadius = cornerRadius.shrink(halfStroke),
                style = borderStroke
                style = borderStroke,
            )
        }
    } else {
@@ -494,11 +486,7 @@ private fun ContentDrawScope.drawBackground(
        if (border != null) {
            // Copied from androidx.compose.foundation.Border.kt.
            val strokeWidth = border.width.toPx()
            val path =
                createRoundRectPath(
                    (outline as Outline.Rounded).roundRect,
                    strokeWidth,
                )
            val path = createRoundRectPath((outline as Outline.Rounded).roundRect, strokeWidth)

            drawPath(path, border.brush)
        }
@@ -510,10 +498,7 @@ private fun ContentDrawScope.drawBackground(
 *
 * Copied from androidx.compose.foundation.Border.kt.
 */
private fun createRoundRectPath(
    roundedRect: RoundRect,
    strokeWidth: Float,
): Path {
private fun createRoundRectPath(roundedRect: RoundRect, strokeWidth: Float): Path {
    return Path().apply {
        addRoundRect(roundedRect)
        val insetPath =
@@ -532,7 +517,7 @@ private fun createInsetRoundedRect(widthPx: Float, roundedRect: RoundRect) =
        topLeftCornerRadius = roundedRect.topLeftCornerRadius.shrink(widthPx),
        topRightCornerRadius = roundedRect.topRightCornerRadius.shrink(widthPx),
        bottomLeftCornerRadius = roundedRect.bottomLeftCornerRadius.shrink(widthPx),
        bottomRightCornerRadius = roundedRect.bottomRightCornerRadius.shrink(widthPx)
        bottomRightCornerRadius = roundedRect.bottomRightCornerRadius.shrink(widthPx),
    )

/**
+0 −34
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.compose.animation

import android.view.View
import androidx.savedstate.SavedStateRegistryOwner
import androidx.savedstate.findViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner

// TODO(b/262222023): Remove this workaround and import the new savedstate libraries in tm-qpr-dev
// instead.
object ViewTreeSavedStateRegistryOwner {
    fun set(view: View, owner: SavedStateRegistryOwner?) {
        view.setViewTreeSavedStateRegistryOwner(owner)
    }

    fun get(view: View): SavedStateRegistryOwner? {
        return view.findViewTreeSavedStateRegistryOwner()
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.setViewTreeLifecycleOwner
import androidx.savedstate.SavedStateRegistryController
import androidx.savedstate.SavedStateRegistryOwner
import com.android.compose.animation.ViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import com.android.systemui.lifecycle.ViewLifecycleOwner

/**
@@ -88,13 +88,13 @@ object ComposeInitializer {
        // Set the owners on the root. They will be reused by any ComposeView inside the root
        // hierarchy.
        root.setViewTreeLifecycleOwner(lifecycleOwner)
        ViewTreeSavedStateRegistryOwner.set(root, savedStateRegistryOwner)
        root.setViewTreeSavedStateRegistryOwner(savedStateRegistryOwner)
    }

    /** Function to be called on your window root view's [View.onDetachedFromWindow] function. */
    fun onDetachedFromWindow(root: View) {
        (root.findViewTreeLifecycleOwner() as ViewLifecycleOwner).onDestroy()
        root.setViewTreeLifecycleOwner(null)
        ViewTreeSavedStateRegistryOwner.set(root, null)
        root.setViewTreeSavedStateRegistryOwner(null)
    }
}