Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions library/src/main/java/com/daimajia/swipe/SwipeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class SwipeLayout extends FrameLayout {
private List<SwipeDenier> mSwipeDeniers = new ArrayList<>();
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<>();
private Map<View, Boolean> mShowEntirely = new HashMap<>();
private Map<View, Rect> mViewBoundCache = new HashMap<>();//save all children's bound, restore in onLayout

private DoubleClickListener mDoubleClickListener;

Expand Down Expand Up @@ -392,9 +394,35 @@ else if (mCurrentDragEdge == DragEdge.Bottom && newTop > getPaddingTop())
dispatchSwipeEvent(evLeft, evTop, dx, dy);

invalidate();

captureChildrenBound();
}
};

/**
* save children's bounds, so they can restore the bound in {@link #onLayout(boolean, int, int, int, int)}
*/
private void captureChildrenBound(){
View currentBottomView = getCurrentBottomView();
if(getOpenStatus()==Status.Close){
mViewBoundCache.remove(currentBottomView);
return;
}

View[] views = new View[]{getSurfaceView(), currentBottomView};
for (View child : views) {
Rect rect = mViewBoundCache.get(child);
if(rect==null){
rect = new Rect();
mViewBoundCache.put(child, rect);
}
rect.left = child.getLeft();
rect.top = child.getTop();
rect.right = child.getRight();
rect.bottom = child.getBottom();
}
}

/**
* the dispatchRevealEvent method may not always get accurate position, it
* makes the view may not always get the event when the view is totally
Expand Down Expand Up @@ -763,30 +791,35 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
}

void layoutPullOut() {
Rect rect = computeSurfaceLayoutArea(false);
View surfaceView = getSurfaceView();
Rect surfaceRect = mViewBoundCache.get(surfaceView);
if(surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
if (surfaceView != null) {
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
bringChildToFront(surfaceView);
}
rect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
View currentBottomView = getCurrentBottomView();
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
if(bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect);
Log.e("fax", this + ":bottomRect:"+bottomViewRect);
if (currentBottomView != null) {
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
}
}

void layoutLayDown() {
Rect rect = computeSurfaceLayoutArea(false);
View surfaceView = getSurfaceView();
Rect surfaceRect = mViewBoundCache.get(surfaceView);
if(surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
if (surfaceView != null) {
surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom);
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
bringChildToFront(surfaceView);
}
rect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, rect);
View currentBottomView = getCurrentBottomView();
Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
if(bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect);
if (currentBottomView != null) {
currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom);
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
}
}

Expand Down