Skip to content

Commit 88ce877

Browse files
Anna Powolnyfacebook-github-bot
Anna Powolny
authored andcommitted
Fix scroll stretching
Summary: During the last QE where I was testing the Primitive scroll someone reported that the scroll is taking too much space. https://fb.workplace.com/groups/litho.support/permalink/3981699508818054/ After investigating it, what seems to be wrong is again the measuring logic... We tried to create a copy of [ViewGroup.getChildMeasureSpec](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/ViewGroup.java#7030) but I didn't include the specMode variants. Before the change: **Spec:** widthSpec from spec **[1080, AT_MOST]** **Primitive:** - sizeConstraints width mode **AT_MOST** SizeConstraints[**minWidth = 0, maxWidth = 1080**, minHeight = 0, maxHeight = 1647] (what we are getting in LayoutScope.layout) - childConstraints width **[1080, EXACTLY]** SizeConstraints **[minWidth = 1080, maxWidth = 1080**, minHeight = 0, maxHeight = Infinity] (this is the result of our getChildMeasureSpec primitive call) I published next diff with force to test and let's see if all of the e2e and tests will pass <fingers crossed> Reviewed By: adityasharat Differential Revision: D68208796 fbshipit-source-id: a3f054da61afaaad451ad7577d5a115fce0fad65
1 parent a0d48a5 commit 88ce877

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

litho-widget/src/main/java/com/facebook/litho/widget/ExperimentalVerticalScroll.kt

+20-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import com.facebook.rendercore.primitives.LayoutBehavior
4444
import com.facebook.rendercore.primitives.LayoutScope
4545
import com.facebook.rendercore.primitives.PrimitiveLayoutResult
4646
import com.facebook.rendercore.primitives.ViewAllocator
47+
import com.facebook.rendercore.toWidthSpec
48+
import com.facebook.rendercore.utils.MeasureSpecUtils.getMode
4749
import kotlin.math.max
4850
import kotlin.math.min
4951

@@ -227,9 +229,11 @@ internal class VerticalScrollLayoutBehavior(
227229

228230
val (minMeasureWidth, maxMeasureWidth) =
229231
getChildMeasureSize(
230-
constraints.minWidth, constraints.maxWidth, ViewGroup.LayoutParams.MATCH_PARENT)
232+
constraints.minWidth,
233+
constraints.maxWidth,
234+
ViewGroup.LayoutParams.MATCH_PARENT,
235+
getMode(sizeConstraints.toWidthSpec()))
231236
val childConstraints = constraints.copy(minWidth = minMeasureWidth, maxWidth = maxMeasureWidth)
232-
233237
val layoutState =
234238
NestedLithoTree.layout(
235239
result = resolveResult,
@@ -262,7 +266,12 @@ internal class VerticalScrollLayoutBehavior(
262266
/**
263267
* Equivalent to [VerticalScrollComponent.onMeasure] code calling [ViewGroup.getChildMeasureSpec]
264268
*/
265-
private fun getChildMeasureSize(min: Int, max: Int, preferred: Int): Pair<Int, Int> =
269+
private fun getChildMeasureSize(
270+
min: Int,
271+
max: Int,
272+
preferred: Int,
273+
widthMode: Int
274+
): Pair<Int, Int> =
266275
when {
267276
preferred >= 0 || min == max -> {
268277
// Fixed size due to fixed size layout param or fixed constraints.
@@ -274,8 +283,14 @@ internal class VerticalScrollLayoutBehavior(
274283
0 to max
275284
}
276285
preferred == ViewGroup.LayoutParams.MATCH_PARENT && max != SizeConstraints.Infinity -> {
277-
// Match parent layout param, so we force the child to fill the available space.
278-
max to max
286+
if (widthMode == View.MeasureSpec.AT_MOST) {
287+
// Match parent layout param with AT_MOST constraint, so we let the child decide its
288+
// size.
289+
0 to max
290+
} else {
291+
// Match parent layout param, so we force the child to fill the available space.
292+
max to max
293+
}
279294
}
280295
else -> {
281296
// max constraint is infinite and layout param is WRAP_CONTENT or MATCH_PARENT.

0 commit comments

Comments
 (0)