Skip to content

reason-react-native: add example for ScrollView scrollTo method #577

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

Merged
merged 5 commits into from
Aug 28, 2019
Merged
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
61 changes: 61 additions & 0 deletions reason-react-native/src/components/ScrollView.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,67 @@ title: ScrollView
wip: true
---

## Methods

### `scrollTo`

Scrolls to a given `x`, `y` offset, either immediately, with a smooth animation, or,
for Android only, a custom animation duration time.

```reason
let scrollParams = (~x: float, ~y: float, ~animated: bool=?, ~duration: float=?, unit) => unit;

let scrollTo = (scrollView, scrollParams) => unit;
```

#### `scrollTo` Example

```reason
open ReactNative;

[@react.component]
let make = () => {
let scrollViewRef = React.useRef(Js.Nullable.null);
<ScrollView ref=scrollViewRef>
<TouchableOpacity
onPress={_ =>
switch (scrollViewRef->React.Ref.current->Js.Nullable.toOption) {
| Some(scrollView) =>
scrollView->ScrollView.scrollTo(
ScrollView.scrollToParams(~x=0., ~y=0., ~animated=true, ()),
)
| _ => ()
}
}>
<Text> "ScrollTo 0, 0"->React.string </Text>
</TouchableOpacity>
</ScrollView>;
};
```

### `scrollToEnd`

Scrolls to the end of the `ScrollView` with an animation.
If this is a vertical `ScrollView` scrolls to the bottom.
If this is a horizontal `ScrollView` scrolls to the right.

```reason
let scrollToEnd = (scrollView) => unit;
```

### `scrollToEndWithOptions`

Similar to `scrollToEnd`, with options for animation or, for Android only duration.

```reason
let scrollToEndOptions = (~animated: bool=?, ~duration: float=?, unit) => unit;

let scrollToEndWithOptions = (scrollView, scrollParams) => unit;
```

---


```reason
include ScrollViewElement;

Expand Down