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

Ensure flexbox layout row children can be as big as they want #590

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,27 @@ class FlexboxHelperTest {
assertThat(view3.measuredWidth, `is`(100))
}

@Test
@Throws(Throwable::class)
fun testDetermineMainSize_directionRow_unconstrainedWidth_childrenCanBeSizeTheyWant() {
val activity = activityRule.activity
val view1 = View(activity).apply {
layoutParams = FlexboxLayout.LayoutParams(100, 100)
}.also(flexContainer::addView)
val view2 = View(activity).apply {
layoutParams = FlexboxLayout.LayoutParams(1000, 100)
}.also(flexContainer::addView)
val widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
val heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.UNSPECIFIED)
val result = FlexboxHelper.FlexLinesResult()
flexboxHelper.calculateHorizontalFlexLines(result, widthMeasureSpec, heightMeasureSpec)
flexContainer.flexLines = result.mFlexLines
flexboxHelper.determineMainSize(widthMeasureSpec, heightMeasureSpec)

assertThat(view1.measuredWidth, `is`(100))
assertThat(view2.measuredWidth, `is`(1000))
}

@Test
@Throws(Throwable::class)
fun testDetermineMainSize_directionRow_considerCompoundButtonImplicitMinSizeWhenNotSpecified() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,10 @@ void determineMainSize(int widthMeasureSpec, int heightMeasureSpec, int fromInde
int largestMainSize = mFlexContainer.getLargestMainSize();
if (widthMode == View.MeasureSpec.EXACTLY) {
mainSize = widthSize;
} else {
} else if (widthMode == View.MeasureSpec.AT_MOST) {
mainSize = Math.min(largestMainSize, widthSize);
} else {
mainSize = largestMainSize;
}
paddingAlongMainAxis = mFlexContainer.getPaddingLeft()
+ mFlexContainer.getPaddingRight();
Expand Down