Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix column content changes #1688

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Comment on lines +70 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any downside to not specifying the requested sizes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just clears them out so that we can set the ones we want below. Otherwise it ends up accumulating both exact and max values when it’s repeatedly measured.

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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was broken before the code change. It showed the B at 50%, not at the bottom.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably create an Issue to have these work with Compose UI so we don't forget about it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do better than that. I can fix the problem!
#1691

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.