How to scroll to component onPress with useRef

724 Views Asked by At

its a simple question, i just dont find the method that can handle this.

  1. i declare use ref variable like so:

     const massageTypeRef = useRef();
    
  2. Now I have Text component at the top of the page:

                 <Text ref={massageTypeRef} style={styles.massagetitle}>
                 Choose type:
             </Text>
    

3.and i have another button in the bottom , i want when the button clicked, take the user all the way up to the Text component. in my bottom button i have:

<AnimatedButton
                onPress={() => console.log(massageTypeRef.current}/// here i dont know what i need to 
                 pass
                icon="arrow-up"
                buttonStyle={styles.problembutton}
                textStyle={styles.problembuttontext}
            />

i tried:

onPress={() =>
                    massageTypeRef.current.scrollIntoView({
                        behavior: "smooth",
                    })

and:

onPress={() =>
                    massageTypeRef.current.scrollTo()
                    })

but i always get: TypeError: massageTypeRef.current.scrollIntoView is not a function. (In 'massageTypeRef.current.scrollIntoView()', 'massageTypeRef.current.scrollIntoView' is undefined)

0

There are 0 best solutions below