From a13520b42fceda09afa163502c4708a7bfe67442 Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Thu, 15 Dec 2022 13:22:23 +0100 Subject: [PATCH] Reconcile Expandable.kt on master/tm-qpr-dev-plus-aosp and tm-qpr-dev This CL reconciles the content of Expandable.kt in the tm-qpr-dev-plus-aosp branch and tm-qpr-dev. This CL being on tm-qpr-dev-plus-aosp, this will also be merged in master. Currently the files are different because the androidx.savedstate library was updated in tm-qpr-dev-plus-aosp in http://ag/19946745, and removed the ViewTreeSavedStateRegistryOwner APIs. Ideally, instead of this CL, we would update the androidx.savedstate library in tm-qpr-dev but I'm getting build errors in http://ag/20708667 that might take a while to fix. Until I manage to get that CL in, I suggest we work around it in this CL by re-introducing the ViewTreeSavedStateRegistryOwner API used by tm-qpr-dev, which forwards calls to the API that replaced it. That way we can unblock the few CLs like http://ag/20256703 and http://ag/20711619 which currently have conflicts with master and tm-qpr-dev-plus-aosp. Bug: 262222023 Test: Builds Change-Id: I97660c5a9a2758c5e19d037e635c21456b6085c3 --- .../systemui/compose/animation/Expandable.kt | 7 ++-- .../ViewTreeSavedStateRegistryOwner.kt | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/ViewTreeSavedStateRegistryOwner.kt diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/Expandable.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/Expandable.kt index edbd68400f832..0abdeca31898c 100644 --- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/Expandable.kt +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/Expandable.kt @@ -53,8 +53,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.Density import androidx.lifecycle.ViewTreeLifecycleOwner import androidx.lifecycle.ViewTreeViewModelStoreOwner -import androidx.savedstate.findViewTreeSavedStateRegistryOwner -import androidx.savedstate.setViewTreeSavedStateRegistryOwner import com.android.systemui.animation.LaunchAnimator import kotlin.math.min @@ -298,8 +296,9 @@ private fun AnimatedContentInOverlay( overlayViewGroup, ViewTreeViewModelStoreOwner.get(composeViewRoot), ) - overlayViewGroup.setViewTreeSavedStateRegistryOwner( - composeViewRoot.findViewTreeSavedStateRegistryOwner() + ViewTreeSavedStateRegistryOwner.set( + overlayViewGroup, + ViewTreeSavedStateRegistryOwner.get(composeViewRoot), ) composeView.setParentCompositionContext(compositionContext) diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/ViewTreeSavedStateRegistryOwner.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/ViewTreeSavedStateRegistryOwner.kt new file mode 100644 index 0000000000000..510cec9b8b623 --- /dev/null +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/ViewTreeSavedStateRegistryOwner.kt @@ -0,0 +1,34 @@ +/* + * 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.systemui.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() + } +}