daimajia / daimajia/AndroidSwipeLayout

Recycle of SwipeLayout with match parent width corrupts layout of bottom view

Open
#238 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.3k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

I suggest you to add measure call to beginning of onLayout function (before bottom views are getting updated).

``` java
protected void onLayout(boolean changed, int l, int t, int r, int b) {
/* Call measure previous to any getMeasuredWidth/getMeasuredHeight calls to avoid
problems with "wrap_content" or "match_parent" layout params */
measure(View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
updateBottomViews();

if (mOnLayoutListeners != null) for (int i = 0; i < mOnLayoutListeners.size(); i++) {
mOnLayoutListeners.get(i).onLayout(this);
}
}
```

Without this call, update process will get wrong values from getMeasuredWidth in computeSurfaceLayoutArea when width of SwipeLayout is either "match_parent" or "wrap_content" and SwipeLayout is recycled.

``` java
private Rect computeSurfaceLayoutArea(boolean open) {
int l = getPaddingLeft(), t = getPaddingTop();
if (open) {
if (mCurrentDragEdge == DragEdge.Left)
l = getPaddingLeft() + mDragDistance;
else if (mCurrentDragEdge == DragEdge.Right)
l = getPaddingLeft() - mDragDistance;
else if (mCurrentDragEdge == DragEdge.Top)
t = getPaddingTop() + mDragDistance;
else t = getPaddingTop() - mDragDistance;
}
/* without measure being called previously, getMeasuredWidth will return 16777214 when
wrap_content is specified, or 16777215 when match_parent is specified*/
return new Rect(l, t, l + getMeasuredWidth(), t + getMeasuredHeight());
}
```

``` java
private Rect computeBottomLayoutAreaViaSurface(ShowMode mode, Rect surfaceArea) {
Rect rect = surfaceArea;
View bottomView = getCurrentBottomView();
/* When incorrect surfaceArea is passed (rect.right value 16777214 or 16777215),
then left is computed from this incorrect value, what results in bottom view being
laid out too far away from visible part of screen. */
int bl = rect.left, bt = rect.top, br = rect.right, bb = rect.bottom;
/* rest of function*/
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.