React-native-interactable: How to call snapTo if I use functional component?

Created on 2 Oct 2019  路  2Comments  路  Source: wix/react-native-interactable

Sample here shows how to use snapTo from a class-based component for starting the animation by a button click.

Since Hook's, it's more tempting to use functional components with state, but in functional components, we can't use refs for obtaining instance. Is there any other way to use snapTo for Interactable.View inside functional component? If so, could you please provide some sample?

Thanks in advance and thanks for a great work!

Most helpful comment

You could useRef, something like this worked for me:

const interactableRef = useRef(null)

handlePress = () => {
interactableRef.current.snapTo({ x: 0 })
}

<Interactable.View
    ref={interactableRef}
   .......
>
.........
</Interactable.View>

All 2 comments

You could useRef, something like this worked for me:

const interactableRef = useRef(null)

handlePress = () => {
interactableRef.current.snapTo({ x: 0 })
}

<Interactable.View
    ref={interactableRef}
   .......
>
.........
</Interactable.View>

You can also use
containerRef.current.snapTo({index: 1});

Was this page helpful?
0 / 5 - 0 ratings