Skip to content

Commit

Permalink
fix(android): fix scroll view's layout resizing with children (#11327)
Browse files Browse the repository at this point in the history
* fix(android): fix scroll view's layout resizing with children

prevent ScrollView's layout to stretch out of bounds depending on the scroll type and the childrens
position when contentHeight\Width is not defined

* fix(android): add one more condition for dimension clipping

clip the dimensions only when they are more than the parent's one
  • Loading branch information
ypbnv authored and lokeshchdhry committed Dec 13, 2019
1 parent 1dc178e commit 5723b11
Showing 1 changed file with 19 additions and 4 deletions.
Expand Up @@ -55,6 +55,7 @@ public class TiUIScrollView extends TiUIView

private static int verticalAttrId = -1;
private static int horizontalAttrId = -1;
private int type;

public class TiScrollViewLayout extends TiCompositeLayout
{
Expand Down Expand Up @@ -126,7 +127,7 @@ public int getParentContentWidth()

/**
* Sets the height of this view's parent, excluding its top/bottom padding.
* @param width The parent view's height, excluding padding.
* @param height The parent view's height, excluding padding.
*/
public void setParentContentHeight(int height)
{
Expand Down Expand Up @@ -270,7 +271,14 @@ protected int getMeasuredWidth(int maxWidth, int widthSpec)
{
int contentWidth = getContentProperty(TiC.PROPERTY_CONTENT_WIDTH);
if (contentWidth == AUTO) {
contentWidth = maxWidth; // measuredWidth;
// If we don't have a specific contentWidth and the scroll type is 'vertical'
// match the layout's width to the ScrollView's width to avoid messing up
// children's positions to the visible part of the component.
if (type == TYPE_VERTICAL && maxWidth > this.parentContentWidth) {
contentWidth = this.parentContentWidth;
} else {
contentWidth = maxWidth; // measuredWidth;
}
}

// Returns the content's width when it's greater than the scrollview's width
Expand All @@ -286,7 +294,14 @@ protected int getMeasuredHeight(int maxHeight, int heightSpec)
{
int contentHeight = getContentProperty(TiC.PROPERTY_CONTENT_HEIGHT);
if (contentHeight == AUTO) {
contentHeight = maxHeight; // measuredHeight;
// If we don't have a specific contentHeight and the scroll type is 'horizontal'
// match the layout's width to the ScrollView's width to avoid messing up
// children's positions to the visible part of the component.
if (type == TYPE_HORIZONTAL && maxHeight > this.parentContentHeight) {
contentHeight = this.parentContentHeight;
} else {
contentHeight = maxHeight; // measuredHeight;
}
}

// Returns the content's height when it's greater than the scrollview's height
Expand Down Expand Up @@ -855,7 +870,7 @@ public void processProperties(KrollDict d)
setContentOffset(offset);
}

int type = TYPE_VERTICAL;
type = TYPE_VERTICAL;
boolean deduced = false;

if (d.containsKey(TiC.PROPERTY_WIDTH) && d.containsKey(TiC.PROPERTY_CONTENT_WIDTH)) {
Expand Down

0 comments on commit 5723b11

Please sign in to comment.