Prerequisites
- Vega development environment set up
- hello-world template project created
- Basic knowledge of React Native and TypeScript
- Vega Virtual Device for testing
Import Animated API and useRef()
Open your App.tsx file and update the imports at the top. Add useRef() to the React import and add Animated to the react-native imports.
useRef() hook creates a persistent reference for your animation value, while Animated provides React Native’s animation library for creating smooth animations.
Define the position reference
Inside theApp component, add a position reference after the useState() line.
useRef() to store the x and y coordinates. This value persists across component re-renders.
Create the animation function
Add this function inside theApp component, before the return statement.
Wrap the image with Animated.View
Find the image View in your return statement and wrap it withAnimated.View.
Before:
position.getLayout() call applies the animated x and y values to the View’s style.
Make the image clickable
Wrap the Image with aTouchableOpacity component to make it clickable. First, update your imports.

