Skip to content
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

Update useScrollViewOffset docs #5824

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion docs/docs/scroll/useScrollViewOffset.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ import ScrollViewOffsetSrc from '!!raw-loader!@site/src/examples/ScrollViewOffse
showCode
/>

## Remarks

- You can pass the `animatedRef` argument conditionally and hook will correctly return values basing on the ScrollView component it is connected to: `useScrollViewOffset(someState ? someScrollRefA : someScrollRefB)`.
szydlovsky marked this conversation as resolved.
Show resolved Hide resolved

## Platform compatibility

<div className="platform-compatibility">

| Android | iOS | Web |
| ------- | --- | --- |
| ✅ | ✅ | |
| ✅ | ✅ | |

</div>
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"react-draggable": "^4.4.5",
"react-native": "^0.71.4",
"react-native-gesture-handler": "^2.13.2",
"react-native-reanimated": "^3.7.0-nightly-20240130-720fefba7",
"react-native-reanimated": "^3.9.0-nightly-20240320-d6dab8f65",
"react-native-svg": "^13.14.0",
"react-native-web": "^0.18.12",
"source-map": "^0.7.4",
Expand Down
28 changes: 25 additions & 3 deletions docs/src/examples/ScrollViewOffset.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { View, Text, StyleSheet, TextInput } from 'react-native';
import { View, Text, StyleSheet, TextInput, Button } from 'react-native';
import Animated, {
useAnimatedProps,
useAnimatedRef,
Expand All @@ -11,27 +11,49 @@ export default function App() {
const animatedRef = useAnimatedRef();
// highlight-start
const offset = useScrollViewOffset(animatedRef);
const text = useDerivedValue(() => `offset: ${offset.value.toFixed(1)}`);
const text = useDerivedValue(
() => `Scroll offset: ${offset.value.toFixed(1)}`
);
// highlight-end
const [isScrollHorizontal, setIsScrollHorizontal] = React.useState(false);

return (
<View style={styles.container}>
<AnimatedText text={text} />
<Animated.ScrollView ref={animatedRef}>
<Animated.ScrollView
style={styles.scroll}
contentContainerStyle={styles.scrollContent}
ref={animatedRef}
horizontal={isScrollHorizontal}>
{Array.from({ length: 10 }).map((_, i) => (
<View key={i} style={styles.box}>
<Text style={styles.center}>{i}</Text>
</View>
))}
</Animated.ScrollView>
<Button
title={`Toggle scroll to ${
isScrollHorizontal ? 'vertical' : 'horizontal'
}`}
onPress={() => setIsScrollHorizontal(!isScrollHorizontal)}
/>
</View>
);
}

const styles = StyleSheet.create({
container: {
alignItems: 'center',
},
scroll: {
borderWidth: 1,
borderColor: 'gray',
height: 250,
width: 250,
margin: 20,
},
scrollContent: {
alignItems: 'center',
},
box: {
width: 100,
Expand Down
67 changes: 57 additions & 10 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.20.2.tgz#d1b9000752b18d0877cff85a5c376ce5c3121629"
integrity sha512-8RvlJG2mj4huQ4pZ+rU9lqKi9ZKiRmuvGuM2HlWmkmgOhbs6zEAw6IEiJ5cQqGbDzGZOhwuOQNtZMi/ENLjZoQ==

"@babel/helper-plugin-utils@^7.24.0":
version "7.24.0"
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.0.tgz#945681931a52f15ce879fd5b86ce2dae6d3d7f2a"
integrity sha512-9cUznXMG0+FxRuJfvL82QlTqIzhVW9sL0KjMPHhAOOvpQGL8QtdxnBKILjBqxlHyliz0yCa1G903ZXI/FuHy2w==

"@babel/helper-remap-async-to-generator@^7.18.9":
version "7.18.9"
resolved "https://registry.yarnpkg.com/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.18.9.tgz#997458a0e3357080e54e1d79ec347f8a8cd28519"
Expand Down Expand Up @@ -520,6 +525,13 @@
dependencies:
"@babel/types" "^7.20.0"

"@babel/helper-skip-transparent-expression-wrappers@^7.22.5":
version "7.22.5"
resolved "https://registry.yarnpkg.com/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.22.5.tgz#007f15240b5751c537c40e77abb4e89eeaaa8847"
integrity sha512-tK14r66JZKiC43p8Ki33yLBVJKlQDFoA8GYN67lWCDCqoL6EMMSuM9b+Iff2jHaM/RRFYl7K+iiru7hbRqNx8Q==
dependencies:
"@babel/types" "^7.22.5"

"@babel/helper-split-export-declaration@^7.18.6":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.18.6.tgz#7367949bc75b20c6d5a5d4a97bba2824ae8ef075"
Expand Down Expand Up @@ -966,6 +978,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.20.2"

"@babel/plugin-transform-arrow-functions@^7.0.0-0":
version "7.24.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.24.1.tgz#2bf263617060c9cc45bcdbf492b8cc805082bf27"
integrity sha512-ngT/3NkRhsaep9ck9uj2Xhv9+xB1zShY3tM3g6om4xxCELwCDN4g4Aq5dRn48+0hasAql7s2hdBOysCfNpr4fw==
dependencies:
"@babel/helper-plugin-utils" "^7.24.0"

"@babel/plugin-transform-async-to-generator@^7.0.0", "@babel/plugin-transform-async-to-generator@^7.18.6":
version "7.20.7"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.20.7.tgz#dfee18623c8cb31deb796aa3ca84dda9cea94354"
Expand Down Expand Up @@ -1168,12 +1187,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.18.6"

"@babel/plugin-transform-object-assign@^7.16.7":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-assign/-/plugin-transform-object-assign-7.18.6.tgz#7830b4b6f83e1374a5afb9f6111bcfaea872cdd2"
integrity sha512-mQisZ3JfqWh2gVXvfqYCAAyRs6+7oev+myBsTwW5RnPhYXOTuCEw2oe3YgxlXMViXUS53lG8koulI7mJ+8JE+A==
"@babel/plugin-transform-nullish-coalescing-operator@^7.0.0-0":
version "7.24.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.24.1.tgz#0cd494bb97cb07d428bd651632cb9d4140513988"
integrity sha512-iQ+caew8wRrhCikO5DrUYx0mrmdhkaELgFa+7baMcVuhxIkN7oxt06CZ51D65ugIb1UWRQ8oQe+HXAVM6qHFjw==
dependencies:
"@babel/helper-plugin-utils" "^7.18.6"
"@babel/helper-plugin-utils" "^7.24.0"
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.8.3"

"@babel/plugin-transform-object-super@^7.0.0", "@babel/plugin-transform-object-super@^7.18.6":
version "7.18.6"
Expand All @@ -1183,6 +1203,15 @@
"@babel/helper-plugin-utils" "^7.18.6"
"@babel/helper-replace-supers" "^7.18.6"

"@babel/plugin-transform-optional-chaining@^7.0.0-0":
version "7.24.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-optional-chaining/-/plugin-transform-optional-chaining-7.24.1.tgz#26e588acbedce1ab3519ac40cc748e380c5291e6"
integrity sha512-n03wmDt+987qXwAgcBlnUUivrZBPZ8z1plL0YvgQalLm+ZE5BMhGm94jhxXtA1wzv1Cu2aaOv1BM9vbVttrzSg==
dependencies:
"@babel/helper-plugin-utils" "^7.24.0"
"@babel/helper-skip-transparent-expression-wrappers" "^7.22.5"
"@babel/plugin-syntax-optional-chaining" "^7.8.3"

"@babel/plugin-transform-parameters@^7.0.0", "@babel/plugin-transform-parameters@^7.12.1", "@babel/plugin-transform-parameters@^7.20.1", "@babel/plugin-transform-parameters@^7.20.7":
version "7.20.7"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.20.7.tgz#0ee349e9d1bc96e78e3b37a7af423a4078a7083f"
Expand Down Expand Up @@ -1308,6 +1337,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.18.6"

"@babel/plugin-transform-shorthand-properties@^7.0.0-0":
version "7.24.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.24.1.tgz#ba9a09144cf55d35ec6b93a32253becad8ee5b55"
integrity sha512-LyjVB1nsJ6gTTUKRjRWx9C1s9hE7dLfP/knKdrfeH9UPtAGjYGgxIbFfx7xyLIEWs7Xe1Gnf8EWiUqfjLhInZA==
dependencies:
"@babel/helper-plugin-utils" "^7.24.0"

"@babel/plugin-transform-spread@^7.0.0", "@babel/plugin-transform-spread@^7.19.0":
version "7.20.7"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-spread/-/plugin-transform-spread-7.20.7.tgz#c2d83e0b99d3bf83e07b11995ee24bf7ca09401e"
Expand All @@ -1330,6 +1366,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.18.9"

"@babel/plugin-transform-template-literals@^7.0.0-0":
version "7.24.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.24.1.tgz#15e2166873a30d8617e3e2ccadb86643d327aab7"
integrity sha512-WRkhROsNzriarqECASCNu/nojeXCDTE/F2HmRgOzi7NGvyfYGq1NEjKBK3ckLfRgGc6/lPAqP0vDOSw3YtG34g==
dependencies:
"@babel/helper-plugin-utils" "^7.24.0"

"@babel/plugin-transform-typeof-symbol@^7.18.9":
version "7.18.9"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.18.9.tgz#c8cea68263e45addcd6afc9091429f80925762c0"
Expand Down Expand Up @@ -10317,12 +10360,16 @@ react-native-gradle-plugin@^0.71.16:
resolved "https://registry.yarnpkg.com/react-native-gradle-plugin/-/react-native-gradle-plugin-0.71.16.tgz#822bb0c680e03b5df5aa65f2e5ffc2bc2930854a"
integrity sha512-H2BjG2zk7B7Wii9sXvd9qhCVRQYDAHSWdMw9tscmZBqSP62DkIWEQSk4/B2GhQ4aK9ydVXgtqR6tBeg3yy8TSA==

react-native-reanimated@^3.7.0-nightly-20240130-720fefba7:
version "3.7.0-nightly-20240130-720fefba7"
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-3.7.0-nightly-20240130-720fefba7.tgz#752de6f5de6aa53964e56d7ec896f8059511d356"
integrity sha512-cXIeR26lSg6BZ7UfOHQDticrtHhpRRLWL5AguIiMGnbSJbKfvgLOmPl1G9LI7JdKgLwCEARZb9UC6x+5MB4gXw==
react-native-reanimated@^3.9.0-nightly-20240320-d6dab8f65:
version "3.9.0-nightly-20240320-d6dab8f65"
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-3.9.0-nightly-20240320-d6dab8f65.tgz#a716e2c7b35b35b312fa557aa279fbf98ba509ad"
integrity sha512-3fStNbt4Hja58uQL/ZAkIexxroQSh56+mXMke2yJKCYTCMctT2Z0GsuJWrXeH+1T+XBwUG1NTVBUzQRRFm2kSQ==
dependencies:
"@babel/plugin-transform-object-assign" "^7.16.7"
"@babel/plugin-transform-arrow-functions" "^7.0.0-0"
"@babel/plugin-transform-nullish-coalescing-operator" "^7.0.0-0"
"@babel/plugin-transform-optional-chaining" "^7.0.0-0"
"@babel/plugin-transform-shorthand-properties" "^7.0.0-0"
"@babel/plugin-transform-template-literals" "^7.0.0-0"
"@babel/preset-typescript" "^7.16.7"
convert-source-map "^2.0.0"
invariant "^2.2.4"
Expand Down