Skip to content

Commit 5006302

Browse files
modified CardContainerView#updateAlpha.
1 parent c837977 commit 5006302

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

cardstackview/src/main/java/com/yuyakaido/android/cardstackview/internal/CardContainerView.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,44 @@ private void updateAlpha() {
215215
float percentX = getPercentX();
216216
float percentY = getPercentY();
217217

218-
if (Math.abs(percentX) > Math.abs(percentY)){
219-
if (percentX < 0) {
220-
showLeftOverlay();
218+
if (option.swipeDirection == SwipeDirection.HORIZONTAL) {
219+
showHorizontalOverlay(percentX);
220+
} else if (option.swipeDirection == SwipeDirection.VERTICAL) {
221+
showVerticalOverlay(percentY);
222+
} else if (option.swipeDirection == SwipeDirection.FREEDOM_NO_BOTTOM) {
223+
if (Math.abs(percentX) < Math.abs(percentY) && percentY < 0) {
224+
showTopOverlay();
225+
setOverlayAlpha(Math.abs(percentY));
221226
} else {
222-
showRightOverlay();
227+
showHorizontalOverlay(percentX);
223228
}
224-
setOverlayAlpha(Math.abs(percentX));
225-
}else{
226-
if (percentY < 0) {
227-
showTopOverlay();
229+
} else if (option.swipeDirection == SwipeDirection.FREEDOM) {
230+
if (Math.abs(percentX) > Math.abs(percentY)) {
231+
showHorizontalOverlay(percentX);
228232
} else {
229-
showBottomOverlay();
233+
showVerticalOverlay(percentY);
230234
}
231-
setOverlayAlpha(Math.abs(percentY));
232235
}
233236
}
234237

238+
private void showHorizontalOverlay(float percentX) {
239+
if (percentX < 0) {
240+
showLeftOverlay();
241+
} else {
242+
showRightOverlay();
243+
}
244+
setOverlayAlpha(Math.abs(percentX));
245+
}
246+
247+
private void showVerticalOverlay(float percentY) {
248+
if (percentY < 0) {
249+
showTopOverlay();
250+
} else {
251+
showBottomOverlay();
252+
}
253+
setOverlayAlpha(Math.abs(percentY));
254+
}
255+
235256
private void moveToOrigin() {
236257
animate().translationX(viewOriginX)
237258
.translationY(viewOriginY)

0 commit comments

Comments
 (0)