Skip to content

Commit

Permalink
Adapting ScrollableView.height to the tallest child when Ti.UI.SIZE.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jei committed Feb 21, 2017
1 parent d306867 commit 50b0eee
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,21 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
TiCompositeLayout.LayoutParams layoutParams = (TiCompositeLayout.LayoutParams) mContainer.getLayoutParams();

if (layoutParams.sizeOrFillHeightEnabled && !layoutParams.autoFillsHeight) {
int index = getCurrentItem();
if (index < mViews.size()) {
TiUIView view = mViews.get(index).getOrCreateView();
int height = view.getLayoutParams().optionHeight.getAsPixels(this);

int mode = MeasureSpec.getMode(heightMeasureSpec);
// Unspecified means that the ViewPager is in a ScrollView WRAP_CONTENT.
// At Most means that the ViewPager is not in a ScrollView WRAP_CONTENT.
if (mode == MeasureSpec.UNSPECIFIED || mode == MeasureSpec.AT_MOST) {
// super has to be called in the beginning so the child views can be initialized.
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height) height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
}
}
Expand Down

0 comments on commit 50b0eee

Please sign in to comment.