Skip to content

Commit 5723b11

Browse files
ypbnvlokeshchdhry
authored andcommittedDec 13, 2019
fix(android): fix scroll view's layout resizing with children (#11327)
* 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
1 parent 1dc178e commit 5723b11

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed
 

‎android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIScrollView.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class TiUIScrollView extends TiUIView
5555

5656
private static int verticalAttrId = -1;
5757
private static int horizontalAttrId = -1;
58+
private int type;
5859

5960
public class TiScrollViewLayout extends TiCompositeLayout
6061
{
@@ -126,7 +127,7 @@ public int getParentContentWidth()
126127

127128
/**
128129
* Sets the height of this view's parent, excluding its top/bottom padding.
129-
* @param width The parent view's height, excluding padding.
130+
* @param height The parent view's height, excluding padding.
130131
*/
131132
public void setParentContentHeight(int height)
132133
{
@@ -270,7 +271,14 @@ protected int getMeasuredWidth(int maxWidth, int widthSpec)
270271
{
271272
int contentWidth = getContentProperty(TiC.PROPERTY_CONTENT_WIDTH);
272273
if (contentWidth == AUTO) {
273-
contentWidth = maxWidth; // measuredWidth;
274+
// If we don't have a specific contentWidth and the scroll type is 'vertical'
275+
// match the layout's width to the ScrollView's width to avoid messing up
276+
// children's positions to the visible part of the component.
277+
if (type == TYPE_VERTICAL && maxWidth > this.parentContentWidth) {
278+
contentWidth = this.parentContentWidth;
279+
} else {
280+
contentWidth = maxWidth; // measuredWidth;
281+
}
274282
}
275283

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

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

858-
int type = TYPE_VERTICAL;
873+
type = TYPE_VERTICAL;
859874
boolean deduced = false;
860875

861876
if (d.containsKey(TiC.PROPERTY_WIDTH) && d.containsKey(TiC.PROPERTY_CONTENT_WIDTH)) {

0 commit comments

Comments
 (0)
Please sign in to comment.