File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import * as React from 'react' ;
2+ import { View , ScrollView , Image } from 'react-native' ;
3+ import { NavigationContainer , useScrollToTop } from '@react-navigation/native' ;
4+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs' ;
5+
6+ function Albums ( ) {
7+ const ref = React . useRef ( null ) ;
8+
9+ useScrollToTop (
10+ React . useRef ( {
11+ scrollToTop : ( ) => ref . current ?. scrollTo ( { y : 100 } ) ,
12+ } )
13+ ) ;
14+
15+ return (
16+ < ScrollView ref = { ref } >
17+ < Image
18+ source = { { uri : 'https://facebook.github.io/react/logo-og.png' } }
19+ style = { { width : 400 , height : 400 } }
20+ key = "1"
21+ />
22+ < Image
23+ source = { { uri : 'https://facebook.github.io/react/logo-og.png' } }
24+ style = { { width : 400 , height : 400 } }
25+ key = "2"
26+ />
27+ < Image
28+ source = { { uri : 'https://facebook.github.io/react/logo-og.png' } }
29+ style = { { width : 400 , height : 400 } }
30+ key = "3"
31+ />
32+ < Image
33+ source = { { uri : 'https://facebook.github.io/react/logo-og.png' } }
34+ style = { { width : 400 , height : 400 } }
35+ key = "4"
36+ />
37+ </ ScrollView >
38+ ) ;
39+ }
40+
41+ function HomeScreen ( ) {
42+ return < View /> ;
43+ }
44+
45+ const Tab = createBottomTabNavigator ( ) ;
46+
47+ export default function App ( ) {
48+ return (
49+ < NavigationContainer >
50+ < Tab . Navigator >
51+ < Tab . Screen name = "Home" component = { HomeScreen } />
52+ < Tab . Screen name = "Albums" component = { Albums } />
53+ </ Tab . Navigator >
54+ </ NavigationContainer >
55+ ) ;
56+ }
Original file line number Diff line number Diff line change 1+ import * as React from 'react' ;
2+ import { View , ScrollView , Image } from 'react-native' ;
3+ import { NavigationContainer , useScrollToTop } from '@react-navigation/native' ;
4+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs' ;
5+
6+ function Albums ( ) {
7+ const ref = React . useRef ( null ) ;
8+
9+ useScrollToTop (
10+ React . useRef ( {
11+ scrollToTop : ( ) => ref . current ?. scrollTo ( { y : 100 } ) ,
12+ } )
13+ ) ;
14+
15+ return (
16+ < ScrollView ref = { ref } >
17+ < Image
18+ source = { { uri : 'https://facebook.github.io/react/logo-og.png' } }
19+ style = { { width : 400 , height : 400 } }
20+ key = "1"
21+ />
22+ < Image
23+ source = { { uri : 'https://facebook.github.io/react/logo-og.png' } }
24+ style = { { width : 400 , height : 400 } }
25+ key = "2"
26+ />
27+ < Image
28+ source = { { uri : 'https://facebook.github.io/react/logo-og.png' } }
29+ style = { { width : 400 , height : 400 } }
30+ key = "3"
31+ />
32+ < Image
33+ source = { { uri : 'https://facebook.github.io/react/logo-og.png' } }
34+ style = { { width : 400 , height : 400 } }
35+ key = "4"
36+ />
37+ </ ScrollView >
38+ ) ;
39+ }
40+
41+ function HomeScreen ( ) {
42+ return < View /> ;
43+ }
44+
45+ const Tab = createBottomTabNavigator ( ) ;
46+
47+ export default function App ( ) {
48+ return (
49+ < NavigationContainer >
50+ < Tab . Navigator >
51+ < Tab . Screen name = "Home" component = { HomeScreen } />
52+ < Tab . Screen name = "Albums" component = { Albums } />
53+ </ Tab . Navigator >
54+ </ NavigationContainer >
55+ ) ;
56+ }
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ export default function (props) {
5151
5252If you require offset to scroll position you can wrap and decorate passed reference:
5353
54+ <samp id =" use-scroll-to-top-offset " />
55+
5456``` js
5557import * as React from ' react' ;
5658import { ScrollView } from ' react-native' ;
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ export default function (props) {
5151
5252If you require offset to scroll position you can wrap and decorate passed reference:
5353
54+ <samp id =" use-scroll-to-top-offset " />
55+
5456``` js
5557import * as React from ' react' ;
5658import { ScrollView } from ' react-native' ;
You can’t perform that action at this time.
0 commit comments