Skip to content

Commit

Permalink
Fix column content changes
Browse files Browse the repository at this point in the history
We had a bug where changes to a column's content wouldn't
trigger all the necessary layout updates.
  • Loading branch information
squarejesse committed Nov 19, 2023
1 parent 59a6600 commit 7615b59
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 21 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,60 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container, "BCDE")
}

@Test
fun testDynamicContainerSize() {
val parent = flexContainer(FlexDirection.Column).apply {
width(Constraint.Fill)
height(Constraint.Fill)
}

parent.add(
flexContainer(FlexDirection.Column).apply {
modifier = GrowImpl(1.0)
width(Constraint.Fill)
mainAxisAlignment(MainAxisAlignment.SpaceBetween)
add(
widget(
"A",
GrowImpl(1.0).then(CrossAxisAlignmentImpl(CrossAxisAlignment.Start)),
),
)
add(
widget(
"B",
GrowImpl(1.0).then(CrossAxisAlignmentImpl(CrossAxisAlignment.End)),
),
)
},
)

parent.add(
flexContainer(FlexDirection.Column).apply {
modifier = GrowImpl(1.0)
width(Constraint.Fill)
mainAxisAlignment(MainAxisAlignment.SpaceBetween)
add(
widget(
"C",
GrowImpl(1.0)
.then(CrossAxisAlignmentImpl(CrossAxisAlignment.Start)),
),
)
add(
widget(
"D",
GrowImpl(1.0).then(CrossAxisAlignmentImpl(CrossAxisAlignment.End)),
),
)
},
)

verifySnapshot(parent, "both")

parent.removeAt(1)
verifySnapshot(parent, "single")
}

/** We don't have assume() on kotlin.test. Tests that fail here should be skipped instead. */
private fun assumeTrue(b: Boolean) {
assertTrue(b)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ internal class ViewFlexContainer(
}

private fun View.asNode(): Node {
val childNode = Node()
childNode.measureCallback = ViewMeasureCallback(this)
applyLayoutParams(childNode, layoutParams)
return childNode
return Node().apply {
measureCallback = ViewMeasureCallback(this@asNode)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ internal class YogaLayout(
) : ViewGroup(context) {
val rootNode = Node()

init {
applyLayoutParams(rootNode, layoutParams)
}

private fun applyLayout(node: Node, xOffset: Float, yOffset: Float) {
val view = node.view
if (view != null && view !== this) {
Expand Down Expand Up @@ -71,6 +67,11 @@ internal class YogaLayout(
}

private fun calculateLayout(widthSpec: Int, heightSpec: Int) {
rootNode.requestedWidth = Size.Undefined
rootNode.requestedMaxWidth = Size.Undefined
rootNode.requestedHeight = Size.Undefined
rootNode.requestedMaxHeight = Size.Undefined

val widthSize = MeasureSpec.getSize(widthSpec).toFloat()
when (MeasureSpec.getMode(widthSpec)) {
MeasureSpec.EXACTLY -> rootNode.requestedWidth = widthSize
Expand All @@ -95,16 +96,3 @@ internal class YogaLayout(

private val Node.view: View?
get() = (measureCallback as ViewMeasureCallback?)?.view

internal fun applyLayoutParams(node: Node, layoutParams: ViewGroup.LayoutParams?) {
if (layoutParams != null) {
val width = layoutParams.width
if (width >= 0) {
node.requestedWidth = width.toFloat()
}
val height = layoutParams.height
if (height >= 0) {
node.requestedHeight = height.toFloat()
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7615b59

Please sign in to comment.