Skip to content

Commit eab20af

Browse files
committed
[fix] If requestLayout() call, will reset children bounds.
1 parent 14b67ac commit eab20af

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

library/src/main/java/com/daimajia/swipe/SwipeLayout.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class SwipeLayout extends FrameLayout {
5252
private List<SwipeDenier> mSwipeDeniers = new ArrayList<>();
5353
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<>();
5454
private Map<View, Boolean> mShowEntirely = new HashMap<>();
55+
private Map<View, Rect> mViewBoundCache = new HashMap<>();//save all children's bound, restore in onLayout
5556

5657
private DoubleClickListener mDoubleClickListener;
5758

@@ -392,9 +393,35 @@ else if (mCurrentDragEdge == DragEdge.Bottom && newTop > getPaddingTop())
392393
dispatchSwipeEvent(evLeft, evTop, dx, dy);
393394

394395
invalidate();
396+
397+
captureChildrenBound();
395398
}
396399
};
397400

401+
/**
402+
* save children's bounds, so they can restore the bound in {@link #onLayout(boolean, int, int, int, int)}
403+
*/
404+
private void captureChildrenBound(){
405+
View currentBottomView = getCurrentBottomView();
406+
if(getOpenStatus()==Status.Close){
407+
mViewBoundCache.remove(currentBottomView);
408+
return;
409+
}
410+
411+
View[] views = new View[]{getSurfaceView(), currentBottomView};
412+
for (View child : views) {
413+
Rect rect = mViewBoundCache.get(child);
414+
if(rect==null){
415+
rect = new Rect();
416+
mViewBoundCache.put(child, rect);
417+
}
418+
rect.left = child.getLeft();
419+
rect.top = child.getTop();
420+
rect.right = child.getRight();
421+
rect.bottom = child.getBottom();
422+
}
423+
}
424+
398425
/**
399426
* the dispatchRevealEvent method may not always get accurate position, it
400427
* makes the view may not always get the event when the view is totally
@@ -763,30 +790,34 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
763790
}
764791

765792
void layoutPullOut() {
766-
Rect rect = computeSurfaceLayoutArea(false);
767793
View surfaceView = getSurfaceView();
794+
Rect surfaceRect = mViewBoundCache.get(surfaceView);
795+
if(surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
768796
if (surfaceView != null) {
769-
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
797+
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
770798
bringChildToFront(surfaceView);
771799
}
772-
rect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
773800
View currentBottomView = getCurrentBottomView();
801+
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
802+
if(bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect);
774803
if (currentBottomView != null) {
775-
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
804+
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
776805
}
777806
}
778807

779808
void layoutLayDown() {
780-
Rect rect = computeSurfaceLayoutArea(false);
781809
View surfaceView = getSurfaceView();
810+
Rect surfaceRect = mViewBoundCache.get(surfaceView);
811+
if(surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
782812
if (surfaceView != null) {
783-
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
813+
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
784814
bringChildToFront(surfaceView);
785815
}
786-
rect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, rect);
787816
View currentBottomView = getCurrentBottomView();
817+
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
818+
if(bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect);
788819
if (currentBottomView != null) {
789-
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
820+
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
790821
}
791822
}
792823

0 commit comments

Comments
 (0)