Skip to content

Commit e6d76b7

Browse files
committed
Initialized card position when app entering foreground
1 parent c421643 commit e6d76b7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cardstackview/src/main/java/com/yuyakaido/android/cardstackview/CardStackView.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ public CardStackView(Context context, AttributeSet attrs, int defStyle) {
105105
array.recycle();
106106
}
107107

108+
@Override
109+
protected void onWindowVisibilityChanged(int visibility) {
110+
super.onWindowVisibilityChanged(visibility);
111+
if (state.isInitialized && visibility == View.VISIBLE) {
112+
initializeCardStackPosition();
113+
}
114+
}
115+
108116
private void initialize(boolean shouldReset) {
109117
resetIfNeeded(shouldReset);
110118
initializeViews();
@@ -116,6 +124,7 @@ private void resetIfNeeded(boolean shouldReset) {
116124
if (shouldReset) {
117125
state.topIndex = 0;
118126
state.lastPoint = null;
127+
state.isInitialized = false;
119128
}
120129
}
121130

@@ -134,6 +143,8 @@ private void initializeViews() {
134143
}
135144

136145
containers.getFirst().setContainerEventListener(containerEventListener);
146+
147+
state.isInitialized = true;
137148
}
138149

139150
private void initializeCardStackPosition() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ public class CardStackState {
77
public Point lastPoint = null;
88
public Integer lastCount = null;
99
public boolean isPaginationReserved = false;
10+
public boolean isInitialized = false;
1011
}

0 commit comments

Comments
 (0)