Skip to content

Commit

Permalink
reason-react-native: add example for ScrollView scrollTo method (face…
Browse files Browse the repository at this point in the history
…book#577)

* reason-react-native: add example for ScrollView scrollTo method

* Update ScrollView.md

* Update ScrollView.md

* Update ScrollView.md

* Update ScrollView.md
  • Loading branch information
MoOx authored Aug 28, 2019
1 parent 129d490 commit 4049d95
Showing 1 changed file with 61 additions and 0 deletions.
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

0 comments on commit 4049d95

Please sign in to comment.