Skip to content

Android - Vertical/Horizontal bounce enabled props #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The following props are supported:
| `bouncesZoom` | `true` | Whether content bounces at the limits when zooming. |
| `alwaysBounceHorizontal` | `false` | When `bounces` is enabled, content will bounce horizontally even if the content is smaller than the bounds of the scroll view. |
| `alwaysBounceVertical` | `false` | When `bounces` is enabled, content will bounce vertically even if the content is smaller than the bounds of the scroll view.. |
| **android** `horizontalBounceEnabled` | `true` | If `false`, content will not bounce horizontally. |
| **android** `verticalBounceEnabled` | `true` | If `false`, content will not bounce vertically. |
| **ios** `showsVerticalScrollIndicator` | `true` | Whether vertical scroll bars are visible. |
| **ios** `showsHorizontalScrollIndicator` | `true` | Whether horizontal scroll bars are visible. |

Expand Down
12 changes: 11 additions & 1 deletion android/src/main/java/com/rnds/DirectedScrollView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class DirectedScrollView extends ReactViewGroup {
private float minimumZoomScale = 1.0f;
private float maximumZoomScale = 1.0f;
private boolean bounces = true;
private boolean verticalBounceEnabled = true;
private boolean horizontalBounceEnabled = true;
private boolean alwaysBounceVertical = false;
private boolean alwaysBounceHorizontal = false;
private boolean bouncesZoom = true;
Expand Down Expand Up @@ -214,7 +216,7 @@ private void onActionMove(MotionEvent motionEvent) {
scrollY = startScrollY + deltaY;

if (bounces) {
clampAndTranslateChildren(false, getMaxScrollY() <= 0 && !alwaysBounceVertical, getMaxScrollX() <= 0 && !alwaysBounceHorizontal);
clampAndTranslateChildren(false, !verticalBounceEnabled || (getMaxScrollY() <= 0 && !alwaysBounceVertical), !horizontalBounceEnabled || (getMaxScrollX() <= 0 && !alwaysBounceHorizontal));
} else {
clampAndTranslateChildren(false);
}
Expand Down Expand Up @@ -433,6 +435,14 @@ public void setBouncesZoom(final boolean bouncesZoom) {
this.bouncesZoom = bouncesZoom;
}

public void setVerticalBounceEnabled(final boolean verticalBounceEnabled) {
this.verticalBounceEnabled = verticalBounceEnabled;
}

public void setHorizontalBounceEnabled(final boolean horizontalBounceEnabled) {
this.horizontalBounceEnabled = horizontalBounceEnabled;
}

public void setAlwaysBounceHorizontal(final boolean alwaysBounceHorizontal) {
this.alwaysBounceHorizontal = alwaysBounceHorizontal;
}
Expand Down
10 changes: 10 additions & 0 deletions android/src/main/java/com/rnds/DirectedScrollViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public void setBouncesZoom(DirectedScrollView view, @Nullable boolean bouncesZoo
view.setBouncesZoom(bouncesZoom);
}

@ReactProp(name = "verticalBounceEnabled", defaultBoolean = true)
public void setVerticalBounceEnabled(DirectedScrollView view, @Nullable boolean verticalBounceEnabled) {
view.setVerticalBounceEnabled(verticalBounceEnabled);
}

@ReactProp(name = "horizontalBounceEnabled", defaultBoolean = true)
public void setHorizontalBounceEnabled(DirectedScrollView view, @Nullable boolean horizontalBounceEnabled) {
view.setHorizontalBounceEnabled(horizontalBounceEnabled);
}

@ReactProp(name = "alwaysBounceHorizontal", defaultBoolean = false)
public void setAlwaysBounceHorizontal(DirectedScrollView view, @Nullable boolean alwaysBounceHorizontal) {
view.setAlwaysBounceHorizontal(alwaysBounceHorizontal);
Expand Down