From df6b71ae7975ec88f735e441588d62b4c65db411 Mon Sep 17 00:00:00 2001 From: Ray Ryan Date: Mon, 13 Nov 2023 15:25:12 -0800 Subject: [PATCH] Stop stomping `View.layoutParams` * `BodyAndOverlaysContainer` was being dictatorial about the body view's layout params for no clear reason * `WorkflowViewStub.replaceViewInParent` default impl now defers to `layoutParams` of incoming view if it has any, and otherwise takes care to push the params that were set on the original stub, not copy them from `newView` to `newView`. --- .../java/com/squareup/workflow1/ui/ScreenViewFactoryFinder.kt | 1 - .../src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt | 4 +--- .../main/java/com/squareup/workflow1/ui/WorkflowViewStub.kt | 2 +- .../workflow1/ui/container/BodyAndOverlaysContainer.kt | 3 +-- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/ScreenViewFactoryFinder.kt b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/ScreenViewFactoryFinder.kt index c55902c686..193428f91f 100644 --- a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/ScreenViewFactoryFinder.kt +++ b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/ScreenViewFactoryFinder.kt @@ -20,7 +20,6 @@ import com.squareup.workflow1.ui.container.EnvironmentScreen * by ScreenViewFactory( * buildView = { environment, context, _ -> * val view = MyBackStackContainer(context) - * .apply { layoutParams = (LayoutParams(MATCH_PARENT, MATCH_PARENT)) } * ScreenViewHolder(environment, view) { rendering, environment -> * view.update(rendering, environment) * } diff --git a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt index 7ed280da40..28a518a566 100644 --- a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt +++ b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt @@ -8,8 +8,6 @@ import android.os.Parcelable.Creator import android.util.AttributeSet import android.util.SparseArray import android.view.View -import android.view.ViewGroup -import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.widget.FrameLayout import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle.State @@ -51,7 +49,7 @@ public class WorkflowLayout( private val showing: WorkflowViewStub = WorkflowViewStub(context).also { rootStub -> rootStub.updatesVisibility = false - addView(rootStub, ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)) + addView(rootStub) } private var restoredChildState: SparseArray? = null diff --git a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowViewStub.kt b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowViewStub.kt index 26e0b80604..e5ce76cbc5 100644 --- a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowViewStub.kt +++ b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowViewStub.kt @@ -129,7 +129,7 @@ public class WorkflowViewStub @JvmOverloads constructor( public var replaceOldViewInParent: (ViewGroup, View) -> Unit = { parent, newView -> val index = parent.indexOfChild(actual) parent.removeView(actual) - actual.layoutParams + layoutParams?.takeIf { newView.layoutParams == null } ?.let { parent.addView(newView, index, it) } ?: run { parent.addView(newView, index) } } diff --git a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/BodyAndOverlaysContainer.kt b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/BodyAndOverlaysContainer.kt index ea5ef4c41c..04a1bd2ef0 100644 --- a/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/BodyAndOverlaysContainer.kt +++ b/workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/BodyAndOverlaysContainer.kt @@ -9,7 +9,6 @@ import android.os.Parcelable.Creator import android.util.AttributeSet import android.view.KeyEvent import android.view.MotionEvent -import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.widget.FrameLayout import com.squareup.workflow1.ui.Compatible @@ -43,7 +42,7 @@ internal class BodyAndOverlaysContainer @JvmOverloads constructor( private lateinit var savedStateParentKey: String private val baseViewStub: WorkflowViewStub = WorkflowViewStub(context).also { - addView(it, ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)) + addView(it) } private val dialogs = LayeredDialogSessions.forView(