Skip to content

Commit

Permalink
fix(android): pull header/footer collapse animation
Browse files Browse the repository at this point in the history
  • Loading branch information
iPel authored and zoomchan-cxj committed Feb 17, 2023
1 parent 65a93c0 commit 888c99a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,6 @@ public void enableRefresh() {
}
}

@Override
public void onRefreshCompleted() {
if (mRefreshStatus == PullRefreshStatus.PULL_STATUS_REFRESHING) {
// when only part of the header is visible, scroll it off the screen before hiding it
// to avoid inappropriate offsets of the list
if (HippyListUtils.isVerticalLayout(mRecyclerView)) {
int offsetY = mRecyclerView.getContentOffsetY();
if (offsetY < 0 && offsetY > -mRenderNode.getHeight()) {
mRecyclerView.scrollBy(0, -offsetY);
}
} else {
int offsetX = mRecyclerView.getContentOffsetX();
if (offsetX < 0 && offsetX > -mRenderNode.getWidth()) {
mRecyclerView.scrollBy(-offsetX, 0);
}
}
}
super.onRefreshCompleted();
}

/**
* scrollable distance from list start, value greater than or equal to 0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ protected void endDrag() {
mRefreshStatus = PullRefreshStatus.PULL_STATUS_REFRESHING;
sendReleasedEvent();
}
smoothScrollTo(getVisibleSize(), nodeSize, DURATION);
smoothResizeTo(getVisibleSize(), nodeSize, DURATION);
} else { // only partially showing
if (mRefreshStatus == PullRefreshStatus.PULL_STATUS_DRAGGING) {
mRefreshStatus = PullRefreshStatus.PULL_STATUS_FOLDED;
}
if (visibleSize > 0) {
smoothScrollTo(getVisibleSize(), 0, DURATION);
smoothResizeTo(getVisibleSize(), 0, DURATION);
}
}
}
Expand All @@ -100,8 +100,7 @@ public void onDestroy() {
public void onRefreshCompleted() {
if (mRefreshStatus == PullRefreshStatus.PULL_STATUS_REFRESHING) {
mRefreshStatus = PullRefreshStatus.PULL_STATUS_FOLDED;
endAnimation();
setVisibleSize(0);
smoothResizeTo(getVisibleSize(), 0, DURATION);
}
}

Expand Down Expand Up @@ -218,7 +217,7 @@ protected void setVisibleSize(int size) {
mRecyclerView.dispatchLayout();
}

protected void smoothScrollTo(int fromValue, int toValue, int duration) {
protected void smoothResizeTo(int fromValue, int toValue, int duration) {
endAnimation();
mAnimator = ValueAnimator.ofInt(fromValue, toValue);
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
Expand Down

0 comments on commit 888c99a

Please sign in to comment.