Skip to content

Commit

Permalink
Stop stomping View.layoutParams
Browse files Browse the repository at this point in the history
* `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`.
  • Loading branch information
rjrjr committed Nov 14, 2023
1 parent 87ade41 commit df6b71a
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Parcelable>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit df6b71a

Please sign in to comment.