Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

Added an interface for changing the release-to-refresh ratio #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,13 @@ public interface IPullToRefresh<T extends View> {
* @param showView
*/
public void setShowViewWhileRefreshing(boolean showView);


/**
* Sets the ratio in which we start the release-to-refresh state (e.g. if ratio = 2, only when the
* user pulls the list twice as much, then we'll enter the release-to-refresh state).
* @param ratio the ratio
*/
public void setReleaseRatio(float ratio);

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public abstract class PullToRefreshBase<T extends View> extends LinearLayout imp

private SmoothScrollRunnable mCurrentSmoothScrollRunnable;

// At what ratio should we start considering the release-to-refresh state
private float mReleaseRatio = 1;


// ===========================================================
// Constructors
// ===========================================================
Expand Down Expand Up @@ -153,6 +157,11 @@ public final boolean demo() {

return false;
}

@Override
public void setReleaseRatio(float ratio) {
mReleaseRatio = ratio;
}

@Override
public final Mode getCurrentMode() {
Expand Down Expand Up @@ -1206,7 +1215,7 @@ private void pullEvent() {

if (mState != State.PULL_TO_REFRESH && itemDimension >= Math.abs(newScrollValue)) {
setState(State.PULL_TO_REFRESH);
} else if (mState == State.PULL_TO_REFRESH && itemDimension < Math.abs(newScrollValue)) {
} else if (mState == State.PULL_TO_REFRESH && (itemDimension * mReleaseRatio) < Math.abs(newScrollValue)) {
setState(State.RELEASE_TO_REFRESH);
}
}
Expand Down