Skip to content

Commit c0ecce5

Browse files
committed
Disable last item snap by default
1 parent 5655c66 commit c0ecce5

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

gravitysnaphelper/src/main/java/com/github/rubensousa/gravitysnaphelper/GravityDelegate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
3535
};
3636

3737
public GravityDelegate(int gravity) {
38-
this(gravity, true, null);
38+
this(gravity, false, null);
3939
}
4040

4141
public GravityDelegate(int gravity, GravitySnapHelper.SnapListener listener) {
42-
this(gravity, true, listener);
42+
this(gravity, false, listener);
4343
}
4444

4545
public GravityDelegate(int gravity, boolean enableSnapLast,

gravitysnaphelper/src/main/java/com/github/rubensousa/gravitysnaphelper/GravityPagerSnapHelper.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ public class GravityPagerSnapHelper extends PagerSnapHelper {
1212
private GravityDelegate delegate;
1313

1414
public GravityPagerSnapHelper(int gravity) {
15-
this.delegate = new GravityDelegate(gravity);
15+
this(gravity, false, null);
16+
}
17+
18+
public GravityPagerSnapHelper(int gravity, boolean enableSnapLastItem) {
19+
this(gravity, enableSnapLastItem, null);
20+
}
21+
22+
public GravityPagerSnapHelper(int gravity, boolean enableSnapLastItem,
23+
GravitySnapHelper.SnapListener snapListener) {
24+
delegate = new GravityDelegate(gravity, enableSnapLastItem, snapListener);
1625
}
1726

1827
@Override
@@ -34,4 +43,15 @@ public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager la
3443
public View findSnapView(RecyclerView.LayoutManager layoutManager) {
3544
return delegate.findSnapView(layoutManager);
3645
}
46+
47+
/**
48+
* Enable snapping of the last item that's snappable.
49+
* The default value is false, because you can't see the last item completely
50+
* if this is enabled.
51+
*
52+
* @param snap true if you want to enable snapping of the last snappable item
53+
*/
54+
public void enableLastItemSnap(boolean snap) {
55+
delegate.enableLastItemSnap(snap);
56+
}
3757
}

0 commit comments

Comments
 (0)