react-navigation
React Navigationは、React Nativeアプリケーション向けの堅牢なナビゲーションライブラリです。画面遷移の管理、ルーティングの処理、ボトムタブ、スタック、ドロワーなどのナビゲーションパターンの実装を簡単かつ効率的に行うことができます。
React Nativeには、ウェブブラウザにあるような組み込みのナビゲーションAPIがありません。React Navigationはこれを提供し、iOS、Android、Vegaのジェスチャーとアニメーションも使用して画面間の遷移を実現します。
このライブラリはシステムにデプロイされるため、別途インストールプロセスを必要とすることなくVegaアプリで利用できます。これは、アプリが実行時にリンクする自動リンクライブラリとしてデプロイされます。ライブラリとVegaとの互換性は、ライブラリがターゲットとしているVegaバージョンとの間でのみ保証されます。
アプリのビルドに使用しているVegaのバージョンを上げる場合は、ベストプラクティスとして、依存するライブラリのバージョンも上げることをお勧めします。
ドキュメント
このライブラリの情報、APIリファレンス、その他の詳細については、専用のドキュメントページ(英語のみ)を参照してください。
インストール
-
package.jsonファイルに、必要なすべてのパッケージの依存関係を追加します。該当するReact Nativeバージョンのタブを選択してください。以下のパッケージがすべて必要というわけではありません。アプリに必要なパッケージのサブセットを含めてください。
"dependencies": { ... "@amazon-devices/react-navigation__bottom-tabs": "~7.0.0", "@amazon-devices/react-navigation__core": "~7.0.0", "@amazon-devices/react-navigation__devtools": "~7.0.0", "@amazon-devices/react-navigation__drawer": "~7.0.0", "@amazon-devices/react-navigation__elements": "~7.0.0", "@amazon-devices/react-navigation__material-bottom-tabs": "~7.0.0", "@amazon-devices/react-navigation__material-top-tabs": "~7.0.0", "@amazon-devices/react-navigation__native": "~7.0.0", "@amazon-devices/react-navigation__native-stack": "~7.0.0", "@amazon-devices/react-navigation__react-native-tab-view": "~7.0.0", "@amazon-devices/react-navigation__routers": "~7.0.0", "@amazon-devices/react-navigation__stack": "~7.0.0", ... }
"dependencies": { ... "@amazon-devices/react-navigation__bottom-tabs": "~8.0.0", "@amazon-devices/react-navigation__core": "~8.0.0", "@amazon-devices/react-navigation__devtools": "~8.0.0", "@amazon-devices/react-navigation__drawer": "~8.0.0", "@amazon-devices/react-navigation__elements": "~8.0.0", "@amazon-devices/react-navigation__material-top-tabs": "~8.0.0", "@amazon-devices/react-navigation__native": "~8.0.0", "@amazon-devices/react-navigation__native-stack": "~8.0.0", "@amazon-devices/react-navigation__react-native-tab-view": "~8.0.0", "@amazon-devices/react-navigation__routers": "~8.0.0", "@amazon-devices/react-navigation__stack": "~8.0.0", ... } -
@amazon-devices/react-native-screensの依存関係を追加すると、非表示になった画面をマウント解除できるようになります。
"dependencies": { ... "@amazon-devices/react-native-screens": "~2.0.0" ... }
"dependencies": { ... "@amazon-devices/react-native-screens": "~3.0.0" ... } -
npm installコマンドを使用して、依存関係を再インストールします。
例
スタックの例:
次の依存関係を追加する必要があります。
"dependencies": {
...
"@amazon-devices/react-navigation__stack": "~7.0.0",
"@amazon-devices/react-navigation__native": "~7.0.0",
"@amazon-devices/react-native-screens": "~2.0.0",
...
}
"dependencies": {
...
"@amazon-devices/react-navigation__stack": "~8.0.0",
"@amazon-devices/react-navigation__native": "~8.0.0",
"@amazon-devices/react-native-screens": "~3.0.0",
...
}
次のコードをApp.tsxファイルに貼り付けます。
import {enableFreeze, enableScreens} from '@amazon-devices/react-native-screens';
import {NavigationContainer} from '@amazon-devices/react-navigation__native';
import {createStackNavigator, StackNavigationOptions} from '@amazon-devices/react-navigation__stack';
import * as React from 'react';
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native';
function generateRandomColors(n: number): string[] {
const generatedColors: string[] = [];
for (let i = 0; i < n; i++) {
const red = Math.floor(Math.random() * 128 + 64);
const green = Math.floor(Math.random() * 128 + 64);
const blue = Math.floor(Math.random() * 128 + 64);
const hex = `#${red.toString(16).padStart(2, '0')}${green
.toString(16)
.padStart(2, '0')}${blue.toString(16).padStart(2, '0')}`;
generatedColors.push(hex);
}
return generatedColors;
}
enableScreens();
enableFreeze();
const Stack = createStackNavigator();
const styles = StyleSheet.create({
screenContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 30,
},
button: {
width: 200,
height: 100,
alignItems: 'center',
justifyContent: 'center',
},
buttonContainer: {
flexWrap: 'wrap',
},
});
const numberOfScreens = 4;
const colors = generateRandomColors(numberOfScreens);
const Screen = ({navigation, route}: {navigation: any; route: any}) => {
const {id} = route.params;
return (
<View style={[styles.screenContainer, {backgroundColor: colors[id]}]}>
<Text style={styles.text}>画面{id}</Text>
<View style={styles.buttonContainer}>
{colors.map((color, buttonId) => (
<TouchableOpacity
onPress={() => navigation.navigate('Screen' + buttonId)}>
<View style={[styles.button, {backgroundColor: color}]}>
<Text>画面#{buttonId}に移動</Text>
</View>
</TouchableOpacity>
))}
<TouchableOpacity onPress={() => navigation.goBack()}>
<View style={[styles.button, {backgroundColor: 'white'}]}>
<Text>{'前の画面に戻る'}</Text>
</View>
</TouchableOpacity>
</View>
</View>
);
};
const screenOptions: StackNavigationOptions = { animation: 'default' };
export const App = () => (
<NavigationContainer>
<Stack.Navigator screenOptions={screenOptions} detachInactiveScreens>
{colors.map((_, id) => (
<Stack.Screen
key={id}
name={'Screen' + id}
component={Screen}
initialParams={{id}}
options={screenOptions}
/>
))}
</Stack.Navigator>
</NavigationContainer>
);
ネイティブスタックの例:
次の依存関係を追加する必要があります。
"dependencies": {
...
"@amazon-devices/react-navigation__native-stack": "~7.0.0",
"@amazon-devices/react-navigation__native": "~7.0.0",
"@amazon-devices/react-native-screens": "~2.0.0",
"@amazon-devices/react-native-safe-area-context": "~2.0.0",
...
}
"dependencies": {
...
"@amazon-devices/react-navigation__native-stack": "~8.0.0",
"@amazon-devices/react-navigation__native": "~8.0.0",
"@amazon-devices/react-native-screens": "~3.0.0",
"@amazon-devices/react-native-safe-area-context": "~8.0.9000000000",
...
}
次のコードをApp.tsxファイルに貼り付けます。
import {enableFreeze, enableScreens} from '@amazon-devices/react-native-screens';
import {createNativeStackNavigator} from '@amazon-devices/react-navigation__native-stack';
import {NavigationContainer} from '@amazon-devices/react-navigation__native';
import * as React from 'react';
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native';
function generateRandomColors(n: number): string[] {
const generatedColors: string[] = [];
for (let i = 0; i < n; i++) {
const red = Math.floor(Math.random() * 128 + 64);
const green = Math.floor(Math.random() * 128 + 64);
const blue = Math.floor(Math.random() * 128 + 64);
const hex = `#${red.toString(16).padStart(2, '0')}${green
.toString(16)
.padStart(2, '0')}${blue.toString(16).padStart(2, '0')}`;
generatedColors.push(hex);
}
return generatedColors;
}
enableScreens();
enableFreeze();
const Stack = createNativeStackNavigator();
const styles = StyleSheet.create({
screenContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 30,
},
button: {
width: 200,
height: 100,
alignItems: 'center',
justifyContent: 'center',
},
buttonContainer: {
flexWrap: 'wrap',
},
});
const numberOfScreens = 4;
const colors = generateRandomColors(numberOfScreens);
const Screen = ({navigation, route}: {navigation: any; route: any}) => {
const {depth, id} = route.params;
return (
<View
style={[
styles.screenContainer,
{backgroundColor: colors[id], margin: 20 * depth},
]}>
<Text style={styles.text}>画面 {id}</Text>
<View style={styles.buttonContainer}>
{colors.map((color, buttonId) => (
<TouchableOpacity
onPress={() =>
navigation.navigate('Screen' + buttonId, {depth: depth + 1})
}>
<View style={[styles.button, {backgroundColor: color}]}>
<Text>画面 #{buttonId}に移動</Text>
</View>
</TouchableOpacity>
))}
<TouchableOpacity onPress={() => navigation.goBack()}>
<View style={[styles.button, {backgroundColor: 'white'}]}>
<Text>{'前の画面に戻る'}</Text>
</View>
</TouchableOpacity>
</View>
</View>
);
};
const screenOptions = {
headerShown: false,
};
export const App = () => (
<NavigationContainer>
<Stack.Navigator screenOptions={screenOptions}>
{colors.map((_, id) => (
<Stack.Screen
key={id}
name={'Screen' + id}
component={Screen}
initialParams={{id, depth: 0}}
options={screenOptions}
/>
))}
</Stack.Navigator>
</NavigationContainer>
);
ボトムタブの例:
次の依存関係を追加する必要があります。
"dependencies": {
...
"@amazon-devices/react-navigation__bottom-tabs": "~7.0.0",
"@amazon-devices/react-navigation__native": "~7.0.0",
"@amazon-devices/react-native-screens": "~2.0.0",
...
}
"dependencies": {
...
"@amazon-devices/react-navigation__bottom-tabs": "~8.0.0",
"@amazon-devices/react-navigation__native": "~8.0.0",
"@amazon-devices/react-native-screens": "~3.0.0",
...
}
次のコードをApp.tsxファイルに貼り付けます。
import { enableScreens } from '@amazon-devices/react-native-screens';
import { createBottomTabNavigator } from '@amazon-devices/react-navigation__bottom-tabs';
import { NavigationContainer } from '@amazon-devices/react-navigation__native';
import * as React from 'react';
import { Text, TouchableOpacity,View } from 'react-native';
enableScreens();
function HomeScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>ホーム!</Text>
</View>
);
}
function SettingsScreen() {
const [text, setText] = React.useState("Press me to check if touches work");
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity onPress={() => setText("Touching works!")}>
<View style={{ width: 200, height: 200, backgroundColor: "skyblue" }}>
<Text>{text}</Text>
</View>
</TouchableOpacity>
<Text>設定!</Text>
</View>
);
}
const Tab = createBottomTabNavigator();
export const App = () => {
return (
<NavigationContainer>
<Tab.Navigator detachInactiveScreens>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
</NavigationContainer>
);
}
マテリアルトップタブの例:
次の依存関係を追加する必要があります。
"dependencies": {
...
"@amazon-devices/react-navigation__material-top-tabs": "~7.0.0",
"@amazon-devices/react-navigation__native": "~7.0.0",
"@amazon-devices/react-native-screens": "~2.0.0"
...
}
"dependencies": {
...
"@amazon-devices/react-navigation__material-top-tabs": "~8.0.0",
"@amazon-devices/react-navigation__native": "~8.0.0",
"@amazon-devices/react-native-screens": "~3.0.0"
...
}
次のコードをApp.tsxファイルに貼り付けます。
import { enableFreeze, enableScreens } from '@amazon-devices/react-native-screens';
import { createMaterialTopTabNavigator } from '@amazon-devices/react-navigation__material-top-tabs';
import { NavigationContainer } from '@amazon-devices/react-navigation__native';
import * as React from 'react';
import { Text, TouchableOpacity,View } from 'react-native';
enableScreens();
enableFreeze();
function HomeScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>ホーム!</Text>
</View>
);
}
function SettingsScreen() {
const [text, setText] = React.useState("Press me to check if touches work");
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity onPress={() => setText("タッチできました")}>
<View style={{ width: 200, height: 200, backgroundColor: "skyblue" }}>
<Text>{text}</Text>
</View>
</TouchableOpacity>
<Text>設定!</Text>
</View>
);
}
const Tab =
createMaterialTopTabNavigator();
export const App = () => {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
</NavigationContainer>
);
}
ドロワーの例:
次の依存関係を追加する必要があります。
"dependencies": {
...
"@amazon-devices/react-native-gesture-handler": "~2.0.0",
"@amazon-devices/react-native-reanimated": "~2.0.0",
"@amazon-devices/react-navigation__drawer": "~7.0.0",
"@amazon-devices/react-navigation__native": "~7.0.0",
...
}
"dependencies": {
...
"@amazon-devices/react-native-gesture-handler": "~4.0.0",
"@amazon-devices/react-native-reanimated": "~4.0.0",
"@amazon-devices/react-navigation__drawer": "~8.0.0",
"@amazon-devices/react-navigation__native": "~8.0.0",
...
}
babel.config.jsにreanimatedプラグインを追加します。
module.exports = {
presets: [...],
plugins: ['@amazon-devices/react-native-reanimated/plugin'] // ここに追加します
};
アプリを実行する前にMetroのキャッシュをリセットします。
npm start -- --reset-cache
次のコードをApp.tsxファイルに貼り付けます。
import {GestureHandlerRootView} from '@amazon-devices/react-native-gesture-handler';
import {createDrawerNavigator} from '@amazon-devices/react-navigation__drawer';
import {NavigationContainer} from '@amazon-devices/react-navigation__native';
import React, {useState} from 'react';
import {Text, TouchableOpacity, View} from 'react-native';
function HomeScreen() {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>ホーム!</Text>
</View>
);
}
function SettingsScreen() {
const [text, setText] = useState('ここを押してタッチが機能するかどうかをチェック');
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<TouchableOpacity onPress={() => setText('タッチは機能しています')}>
<View style={{width: 200, height: 200, backgroundColor: 'skyblue'}}>
<Text>{text}</Text>
</View>
</TouchableOpacity>
<Text>設定!</Text>
</View>
);
}
const Drawer = createDrawerNavigator();
export const App = () => (
<GestureHandlerRootView style={{flex: 1, backgroundColor: 'white'}}>
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home" detachInactiveScreens={false}>
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Settings" component={SettingsScreen} />
</Drawer.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
);
既知の問題
VegaでサポートされるAPI
VegaのReact-Navigationライブラリは、React-Navigation v6で利用可能なすべてのAPIのサポートを追加します。
ナビゲータータイプ
| ナビゲーションタイプ | 説明 |
|---|---|
| スタックナビゲーター | スタックナビゲーターは、アプリで画面間を遷移する方法の1つで、新しい画面をスタックに積み重ねていくように配置します。 |
| ネイティブスタックナビゲーター | ネイティブスタックナビゲーターは、アプリで画面間を遷移する方法の1つで、ネイティブAPIを使用して、新しい画面をスタックに積み重ねていくように配置します。 |
| ドロワーナビゲーター | ドロワーナビゲーターは、ジェスチャーで開閉できるナビゲーションドロワーを画面の横にレンダリングします。 |
| ボトムタブナビゲーター | 画面下部にあるシンプルなタブバーで、ルートの切り替えを行うことができます。 |
| マテリアルボトムタブナビゲーター | 画面下部にあるマテリアルデザインをテーマとしてタブバーで、アニメーションをともなうルートの切り替えを行うことができます。react-native-paperのBottomNavigationコンポーネントをラップしています。 |
| マテリアルトップタブナビゲーター | 画面上部にあるマテリアルデザインをテーマにしたタブバーで、タブをタップしたり水平方向にスワイプしたりすることで、ルートの切り替えを行うことができます。react-native-tab-viewパッケージをラップしています。 |
コンポーネント
| コンポーネント名 | 説明 |
|---|---|
| NavigationContainer | アプリの状態を管理し、最上位のナビゲーターをアプリ環境にリンクします。 |
| ServerContainer | アプリを適切なナビゲーション状態でサーバー上にレンダリングするためのユーティリティを提供します。 |
| Group | ナビゲーター内で複数の画面をグループ化するために使用します。 |
| Screen | ナビゲーター内の画面のさまざまな要素を構成するために使用されます。このコンポーネントは、createXNavigator関数の属性のひとつとして返されます。 |
| Link | 押されると画面に移動するコンポーネントをレンダリングします。ウェブで使用する場合は<a>タグがレンダリングされ、ほかのプラットフォームではTextコンポーネントが使用されます。 |
Vegaでのサポートの例外
ナビゲーションライブラリには、APIサポートに関していくつかの例外があります。
flipper-plugin-react-navigationは、Vegaプラットフォームではまだサポートされていません。
サポートされているバージョン
次の表は、Vega SDKでサポートされているReact Navigationパッケージの一覧です。
| NPMパッケージのバージョン | Vega SDKバージョン | Vega OSバージョン | React Nativeバージョン |
|---|---|---|---|
| ^7.0.x | 0.23以前 | OS 1.1(1401010009820)以前 |
0.72 |
| ^8.0.x | 0.24 | OS 1.2(2101020054720) |
0.83 |
React Native 0.83サブパッケージ
| パッケージ名 | パッケージのバージョン | @amazon-devices/react-native-keplerのバージョン |
|---|---|---|
| @amazon-devices/react-navigation__bottom-tabs | 8.0.1+7.8.7 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__core | 8.0.1+7.13.3 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__devtools | 8.0.1+7.0.42 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__drawer | 8.0.1+7.7.5 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__elements | 8.0.1+2.8.4 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__material-top-tabs | 8.0.1+7.4.5 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__native | 8.0.1+7.1.22 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__native-stack | 8.0.1+7.8.1 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__react-native-tab-view | 8.0.1+4.2.0 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__routers | 8.0.1+7.5.2 | 4.0.x+rn0.83.0 |
| @amazon-devices/react-navigation__stack | 8.0.1+7.6.8 | 4.0.x+rn0.83.0 |
| @amazon-devices/keplerscript-flipper-plugin-react-navigation | サポートなし | サポートなし |
React Native 0.72サブパッケージ
| パッケージ名 | パッケージのバージョン | @amazon-devices/react-native-keplerのバージョン |
|---|---|---|
| @amazon-devices/react-navigation__bottom-tabs | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__core | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__devtools | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__drawer | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__elements | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__material-bottom-tabs | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__material-top-tabs | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__native | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__native-stack | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__react-native-tab-view | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__routers | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/react-navigation__stack | 7.0.0 | 2.0.0+rn0.72.0 |
| @amazon-devices/keplerscript-flipper-plugin-react-navigation | サポートなし | サポートなし |
関連リソース
その他のライブラリについては、サポート対象のサードパーティのライブラリとサービスを参照してください。
Last updated: 2026年7月28日

