fix(label): text wrapping inside flexbox layout (#121)

* fix(ios-label): fix text wrapping in iOS 11
* fix(android): fix label text wrapping inside flexbox layout
This commit is contained in:
Manol Donev
2018-05-08 15:08:25 +03:00
committed by GitHub
parent 3170b8696f
commit a65984f1d5
2 changed files with 39 additions and 10 deletions

View File

@@ -1071,9 +1071,24 @@ public class FlexboxLayout extends ViewGroup {
} else {
accumulatedRoundError = rawCalculatedWidth - roundedCalculatedWidth;
}
child.measure(MeasureSpec.makeMeasureSpec(roundedCalculatedWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
MeasureSpec.EXACTLY));
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(roundedCalculatedWidth, MeasureSpec.EXACTLY);
// NOTE: for controls that support internal content wrapping (e.g. TextView) reducing the width
// might result in increased height e.g. text that could be shown on one line for larger
// width needs to be wrapped in two when width is reduced.
// As a result we cannot unconditionally measure with EXACTLY the current measured height
int childHeightMeasureSpec = getChildMeasureSpec(this.getMeasuredHeightAndState(),
getPaddingTop() + getPaddingBottom() + lp.topMargin
+ lp.bottomMargin, lp.height < 0 ? LayoutParams.WRAP_CONTENT : lp.height);
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
// make sure crossSize is up-to-date as child calculated height might have increased
flexLine.mCrossSize = Math.max(
flexLine.mCrossSize,
child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin
);
}
flexLine.mMainSize += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
} else {