1

lets suppose we got the following:

Navigation screen:

<Drawer.Navigator
        initialRouteName="Home"             
        drawerContent={props => {
            return (
                <DrawerContentScrollView {...props}>
                    <DrawerItemList {...props} />
                    <DrawerItem label="Scroll to aboutus"/>
                </DrawerContentScrollView>                        
            )}
        }>
        <Drawer.Screen options={{
            drawerLabel: 'Home',
            title: ''
            }} name="Home" component={HomeScreen} />            
</Drawer.Navigator>

Home screen:

export default function Home() {
  return (
    <ScrollView>
      <View>
        <Text>One</Text>
      </View>
      <View style={{marginTop:100}}>
        <Text>two</Text>
      </View>
      <View style={{marginTop:100}}>
        <Text>three</Text>
      </View>
      <View style={{marginTop:100}}>
        <Text>four</Text>
      </View>     
      
      <AboutUs/>
    </ScrollView>
  );
}

How could I use this DrawerItem kinda like an anchor linked to about us, so when I click on it my scrollview gets scrolled to the <AboutUs/> part?

SaFteiNZz
  • 348
  • 4
  • 18
  • Does this answer your question? [React Native - how to scroll a ScrollView to a given location after navigation from another screen](https://stackoverflow.com/questions/46680890/react-native-how-to-scroll-a-scrollview-to-a-given-location-after-navigation-f) – Abe Feb 20 '23 at 00:30
  • Yeah I already saw that and it is with what I played the most. Problem is, it has 2 screens and navigates and sends the id to the other one. I find myself in the navigator drawer itself so I don't know how to send and get the id – SaFteiNZz Feb 20 '23 at 22:50
  • 1
    You can use navigation params. Have a useEffect in the destination screen that watches for the param and scrolls when it receives it. You can use setParams if you need to delete the param after scrolling. – Abe Feb 21 '23 at 01:07

0 Answers0