as

Settings
Sign out
Notifications
Alexa
Amazonアプリストア
Ring
AWS
ドキュメント
Support
Contact Us
My Cases
開発
設計と開発
公開
リファレンス
サポート
アクセスいただきありがとうございます。こちらのページは現在英語のみのご用意となっております。順次日本語化を進めてまいりますので、ご理解のほどよろしくお願いいたします。

Create animations in Vega using the Animated API

In this article, you'll build an interactive button with the Animated API that moves to a random position when selected. You'll start with the hello-world template and add animation functionality to create a smooth, interactive experience in your Fire TV app. Vega supports three main approaches for animations: the Animated API (built into React Native), React Native Reanimated, and Lottie. This tutorial focuses on the Animated API, which requires no additional dependencies and is perfect for learning animation fundamentals.

Prerequisites

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.

Copied to clipboard.


import React, {useState, useRef} from 'react';  // Add useRef here
import {
  StyleSheet, 
  Text, 
  ImageBackground, 
  View, 
  Image,
  Animated  // Add Animated here
} from 'react-native';
import {Link} from './components/Link';

The 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 the App component, add a position reference after the useState() line.

Copied to clipboard.


export const App = () => {
  const [image, setImage] = useState(images.vega);
  
  // Add this line:
  const position = useRef(new Animated.ValueXY({x: 0, y: 0})).current;

  const styles = getStyles();
  // ... rest of component

This creates a position reference using useRef() to store the x and y coordinates. This value persists across component re-renders.

Create the animation function

Add this function inside the App component, before the return statement.

Copied to clipboard.


const getRandomNumber = (min: number, max: number) => {
  return Math.random() * (max - min) + min;
};

const handleImagePress = () => {
  const randomX = getRandomNumber(-100, 100);
  const randomY = getRandomNumber(-100, 100);

  Animated.timing(position, {
    toValue: {x: randomX, y: randomY},
    duration: 1000,
    useNativeDriver: false,
  }).start();
};

This creates an animation that moves the image to a random position over 1 second (1000 milliseconds).

Wrap the image with Animated.View

Find the image View in your return statement and wrap it with Animated.View.

Before:

Copied to clipboard.


<View style={styles.image}>
  <Image source={image} />
</View>

After:

Copied to clipboard.


<Animated.View style={[styles.image, position.getLayout()]}>
  <Image source={image} />
</Animated.View>

The position.getLayout() call applies the animated x and y values to the View's style.

Make the image clickable

Wrap the Image with a TouchableOpacity component to make it clickable. First, update your imports.

Copied to clipboard.


import {
  StyleSheet, 
  Text, 
  ImageBackground, 
  View, 
  Image,
  Animated,
  TouchableOpacity  // Add this
} from 'react-native';

Then update the image section.

Copied to clipboard.


<Animated.View style={[styles.image, position.getLayout()]}>
  <TouchableOpacity onPress={handleImagePress}>
    <Image source={image} />
  </TouchableOpacity>
</Animated.View>

Test the animation

Build and run the project on the Vega Virtual Device:

Copied to clipboard.


npm install && npx react-native build-vega

Copied to clipboard.


vega run-app <your-package-file.vpkg>

Now when you select the image on the right side of the screen, it animates to a random position.


Last updated: Apr 17, 2026