Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6_3_X][TIMOB-25258] Android: TableView bottom border extends past the last table row #9489

Merged
merged 2 commits into from
Oct 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.view.View.MeasureSpec;


/**
Expand All @@ -16,6 +18,8 @@
* Extends Google's "SwipeRefreshLayout" class by adding a new setSwipeRefreshEnabled() method.
* Allows the swipe-down feature to be disabled independently of the setEnabled() method that
* Google's implementation uses to disable this feature (along with touch support).
* <p>
* Also adds WRAP_CONTENT support for height. (Google's implementation does not support this.)
*/
public class TiSwipeRefreshLayout extends SwipeRefreshLayout
{
Expand Down Expand Up @@ -61,4 +65,56 @@ public void setSwipeRefreshEnabled(boolean value)
{
this.isSwipeRefreshEnabled = value;
}

/**
* Called when this view's measure() method gets called. Typically called by the parent view.
* Updates this view's width and height based on the given width and height constraints.
* <p>
* Given arguments' size and mode can be extracted via the Android "View.MeasureSpec" class.
* @param widthMeasureSpec Provides the parent's width constraints and size mode.
* @param heightMeasureSpec Provides the parent's height constraints and size mode.
*/
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// If height mode not set to "exactly", then change height to match view's tallest child.
// Note: We need to do this since Google's "SwipeRefreshLayout" class ignores the
// WRAP_CONTENT setting and will fill the height of the parent view instead.
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (heightMode != MeasureSpec.EXACTLY) {
// Determine the min height needed to fit this view's tallest child view.
int minHeight = 0;
for (int index = getChildCount() - 1; index >= 0; index--) {
// Fetch the next child.
View child = getChildAt(index);
if (child == null) {
continue;
}

// Skip child views that are flagged as excluded from the layout.
if (child.getVisibility() == View.GONE) {
continue;
}

// Determine the height of the child.
child.measure(widthMeasureSpec, heightMeasureSpec);
int childHeight = child.getMeasuredHeight();
childHeight += child.getPaddingTop() + child.getPaddingBottom();

// Store the child's height if it's the tallest so far.
minHeight = Math.max(minHeight, childHeight);
}

// Make sure we're not below the suggested min height assigned to this view.
minHeight = Math.max(minHeight, getSuggestedMinimumHeight());

// Update this view's given height spec to match the tallest child view.
if (minHeight < MeasureSpec.getSize(heightMeasureSpec)) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(minHeight, heightMode);
}
}

// Update this view's measurements.
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}