From 4049d950b6c8a908f8594d2ce6a51176c9c5763e Mon Sep 17 00:00:00 2001 From: Max Thirouin Date: Wed, 28 Aug 2019 10:33:15 +0200 Subject: [PATCH] reason-react-native: add example for ScrollView scrollTo method (#577) * reason-react-native: add example for ScrollView scrollTo method * Update ScrollView.md * Update ScrollView.md * Update ScrollView.md * Update ScrollView.md --- .../src/components/ScrollView.md | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/reason-react-native/src/components/ScrollView.md b/reason-react-native/src/components/ScrollView.md index 85f34bcc221f58..5a52e0683b27a4 100644 --- a/reason-react-native/src/components/ScrollView.md +++ b/reason-react-native/src/components/ScrollView.md @@ -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); + + + switch (scrollViewRef->React.Ref.current->Js.Nullable.toOption) { + | Some(scrollView) => + scrollView->ScrollView.scrollTo( + ScrollView.scrollToParams(~x=0., ~y=0., ~animated=true, ()), + ) + | _ => () + } + }> + "ScrollTo 0, 0"->React.string + + ; +}; +``` + +### `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;