Skip to content

Commit

Permalink
Fix measuredWidth for HorizontalScrollSpec in the AT_MOST case
Browse files Browse the repository at this point in the history
Summary: Fix measuredWidth for HorizontalScrollSpec in the AT_MOST case

Reviewed By: adityasharat

Differential Revision: D55016696

fbshipit-source-id: 1dff3b684c8dfeb36b8ec93cbbedc81764d53666
  • Loading branch information
jettbow authored and facebook-github-bot committed Mar 20, 2024
1 parent 7af52f4 commit 9ee017c
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.facebook.litho.widget;

import static android.view.View.OVER_SCROLL_IF_CONTENT_SCROLLS;
import static com.facebook.litho.SizeSpec.AT_MOST;
import static com.facebook.litho.SizeSpec.EXACTLY;
import static com.facebook.litho.SizeSpec.UNSPECIFIED;

Expand Down Expand Up @@ -101,6 +102,7 @@ static void onMeasure(
int widthSpec,
int heightSpec,
Size size,
@Prop(optional = true) boolean wrapContent, // TODO:T182959582
@Prop Component contentProps,
@CachedValue ComponentTree childComponentTree,
Output<Integer> measuredComponentWidth,
Expand Down Expand Up @@ -130,10 +132,15 @@ static void onMeasure(
measuredComponentWidth.set(measuredWidth);
measuredComponentHeight.set(measuredHeight);

// If size constraints were not explicitly defined, just fallback to the
// component dimensions instead.
size.width =
SizeSpec.getMode(widthSpec) == UNSPECIFIED ? measuredWidth : SizeSpec.getSize(widthSpec);
final int sizeSpecMode = SizeSpec.getMode(widthSpec);
final int sizeSpecWidth = SizeSpec.getSize(widthSpec);
if (sizeSpecMode == UNSPECIFIED) {
size.width = measuredWidth;
} else if (sizeSpecMode == AT_MOST && wrapContent) {
size.width = Math.min(measuredWidth, sizeSpecWidth);
} else {
size.width = sizeSpecWidth;
}
size.height = measuredHeight;
}

Expand Down

0 comments on commit 9ee017c

Please sign in to comment.