Skip to content

Commit d1ef529

Browse files
author
Thomas LECLERCQ
committed
Add android bounce cotrol
1 parent 1d95577 commit d1ef529

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The following props are supported:
1818
| `bouncesZoom` | `true` | Whether content bounces at the limits when zooming. |
1919
| `alwaysBounceHorizontal` | `false` | When `bounces` is enabled, content will bounce horizontally even if the content is smaller than the bounds of the scroll view. |
2020
| `alwaysBounceVertical` | `false` | When `bounces` is enabled, content will bounce vertically even if the content is smaller than the bounds of the scroll view.. |
21+
| **android** `horizontalBounceEnabled` | `true` | If `false`, content will not bounce horizontally. |
22+
| **android** `verticalBounceEnabled` | `true` | If `false`, content will not bounce vertically. |
2123
| **ios** `showsVerticalScrollIndicator` | `true` | Whether vertical scroll bars are visible. |
2224
| **ios** `showsHorizontalScrollIndicator` | `true` | Whether horizontal scroll bars are visible. |
2325

android/src/main/java/com/rnds/DirectedScrollView.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class DirectedScrollView extends ReactViewGroup {
3131
private float minimumZoomScale = 1.0f;
3232
private float maximumZoomScale = 1.0f;
3333
private boolean bounces = true;
34+
private boolean verticalBounceEnabled = true;
35+
private boolean horizontalBounceEnabled = true;
3436
private boolean alwaysBounceVertical = false;
3537
private boolean alwaysBounceHorizontal = false;
3638
private boolean bouncesZoom = true;
@@ -214,7 +216,7 @@ private void onActionMove(MotionEvent motionEvent) {
214216
scrollY = startScrollY + deltaY;
215217

216218
if (bounces) {
217-
clampAndTranslateChildren(false, getMaxScrollY() <= 0 && !alwaysBounceVertical, getMaxScrollX() <= 0 && !alwaysBounceHorizontal);
219+
clampAndTranslateChildren(false, !verticalBounceEnabled || (getMaxScrollY() <= 0 && !alwaysBounceVertical), !horizontalBounceEnabled || (getMaxScrollX() <= 0 && !alwaysBounceHorizontal));
218220
} else {
219221
clampAndTranslateChildren(false);
220222
}
@@ -433,6 +435,14 @@ public void setBouncesZoom(final boolean bouncesZoom) {
433435
this.bouncesZoom = bouncesZoom;
434436
}
435437

438+
public void setVerticalBounceEnabled(final boolean verticalBounceEnabled) {
439+
this.verticalBounceEnabled = verticalBounceEnabled;
440+
}
441+
442+
public void setHorizontalBounceEnabled(final boolean horizontalBounceEnabled) {
443+
this.horizontalBounceEnabled = horizontalBounceEnabled;
444+
}
445+
436446
public void setAlwaysBounceHorizontal(final boolean alwaysBounceHorizontal) {
437447
this.alwaysBounceHorizontal = alwaysBounceHorizontal;
438448
}

android/src/main/java/com/rnds/DirectedScrollViewManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public void setBouncesZoom(DirectedScrollView view, @Nullable boolean bouncesZoo
8989
view.setBouncesZoom(bouncesZoom);
9090
}
9191

92+
@ReactProp(name = "verticalBounceEnabled", defaultBoolean = true)
93+
public void setVerticalBounceEnabled(DirectedScrollView view, @Nullable boolean verticalBounceEnabled) {
94+
view.setVerticalBounceEnabled(verticalBounceEnabled);
95+
}
96+
97+
@ReactProp(name = "horizontalBounceEnabled", defaultBoolean = true)
98+
public void setHorizontalBounceEnabled(DirectedScrollView view, @Nullable boolean horizontalBounceEnabled) {
99+
view.setHorizontalBounceEnabled(horizontalBounceEnabled);
100+
}
101+
92102
@ReactProp(name = "alwaysBounceHorizontal", defaultBoolean = false)
93103
public void setAlwaysBounceHorizontal(DirectedScrollView view, @Nullable boolean alwaysBounceHorizontal) {
94104
view.setAlwaysBounceHorizontal(alwaysBounceHorizontal);

0 commit comments

Comments
 (0)