shopify-react-native-performance-navigation
このパッケージには、ほとんどのアプリに役立つと思われる追加の高次プロファイラーがいくつか含まれています。また、標準のPerformanceMeasureView上に構築されたReactNavigationPerformanceViewも含まれ、これにはReact Navigationライブラリ向けの最適化が追加されています。
インストール
package.jsonファイルにJavaScriptライブラリの依存関係を追加します。"dependencies": { ... "@shopify/react-native-performance": "npm:@amazon-devices/shopify__react-native-performance@~2.0.0", "@shopify/react-native-performance-navigation": "npm:@amazon-devices/shopify__react-native-performance-navigation@~3.0.0" },package.jsonファイルのdevDependenciesセクションに、Babelモジュールリゾルバープラグインを追加します。"devDependencies": { ... "babel-plugin-module-resolver": "~5.0.2", },babel.config.jsファイルのpluginセクションで、@amazon-devices/shopify__react-native-performance*のエイリアスを構成します。plugins: [ ["module-resolver", { "alias": { "~@amazon-devices/shopify__react-native-performance(.*)": "@shopify/react-native-performance/\\1" } }] ]- プロジェクトで
@amazon-devices/react-navigation_<X>@2.0.0ライブラリ(<X>はstackやnativeなどの固有のコンポーネント)を使用している場合は、それらのライブラリをpackage.jsonファイルのdependenciesとoverridesの両方のセクションに含めます。@amazon-devices/react-navigation_<X>@7.0.0にアップグレードすることを強くお勧めします。アップグレードすると、@amazon-devices/react-native-reanimatedのサポートが導入され、パフォーマンスとアニメーションが強化されます。"dependencies": { ... "@amazon-devices/react-navigation__<X>": "~2.0.0", ... }, ... "overrides": { ... "@amazon-devices/react-navigation__<X>": "~2.0.0", ... }, npm installコマンドを使用して、依存関係を再インストールします。
例
import React, { useCallback, useContext, useState } from 'react';
import {
Button,
GestureResponderEvent,
StyleSheet,
Text,
View,
} from 'react-native';
import { NavigationContainer } from '@amazon-devices/react-navigation__native';
import { createStackNavigator } from '@amazon-devices/react-navigation__stack';
import {
PerformanceProfiler,
RenderPassReport,
} from '@shopify/react-native-performance';
import {
ReactNavigationPerformanceView,
useProfiledNavigation,
} from '@shopify/react-native-performance-navigation';
type ReportContextState = {
saveReport: (report: RenderPassReport) => void;
findReport: (destinationScreen: string, sourceScreen?: string) => void;
};
const INITIAL_STATE = {
saveReport: () => {},
findReport: () => {},
};
const ReportContext = React.createContext<ReportContextState>(INITIAL_STATE);
const useReportContext = () => {
return useContext(ReportContext);
};
const HomeScreen = () => {
const profiledNavigation = useProfiledNavigation();
const navigateToScreenUsingPerformanceNavigation = (
uiEvent: GestureResponderEvent,
source: 'HomeScreen' | 'DestinationScreen',
destination: 'HomeScreen' | 'DestinationScreen',
) => {
profiledNavigation.navigate(
{
source: source,
uiEvent,
},
destination,
);
};
return (
<View style={styles.container}>
<Button
title="Go to DestinationScreen"
onPress={(uiEvent) =>
navigateToScreenUsingPerformanceNavigation(
uiEvent,
'HomeScreen',
'DestinationScreen',
)
}
/>
</View>
);
};
const DestinationScreen = () => {
const { findReport } = useReportContext();
const report = findReport('destinationScreen', 'HomeScreen');
return (
<ReactNavigationPerformanceView screenName="destinationScreen" interactive>
<View style={[styles.container]}>
<Text style={styles.label}>Measuring navigation render time</Text>
<Text style={styles.label}>
New report is generated after each navigation from "HomeScreen" to
"DestinationScreen"
</Text>
<Text style={styles.text}>{JSON.stringify(report)}</Text>
</View>
</ReactNavigationPerformanceView>
);
};
const Stack = createStackNavigator();
export const App = () => {
const onReportPrepared = (report: RenderPassReport) => {
saveReport(report);
};
const [reports, setReports] = useState<RenderPassReport[]>([]);
const saveReport = useCallback((report: RenderPassReport) => {
setReports((prev) => {
const filtered = prev.filter(
(r) =>
r.sourceScreen !== report.sourceScreen ||
r.destinationScreen !== report.destinationScreen,
);
return [...filtered, report];
});
}, []);
const findReport = useCallback(
(destinationScreen: string, sourceScreen?: string) => {
return reports.find(
(r) =>
r.sourceScreen === sourceScreen &&
r.destinationScreen === destinationScreen,
);
},
[reports],
);
return (
<>
<ReportContext.Provider value={{ saveReport, findReport }}>
<PerformanceProfiler onReportPrepared={onReportPrepared}>
<NavigationContainer>
<Stack.Navigator initialRouteName="HomeScreen">
<Stack.Screen name="HomeScreen" component={HomeScreen} />
<Stack.Screen
name="DestinationScreen"
component={DestinationScreen}
/>
</Stack.Navigator>
</NavigationContainer>
</PerformanceProfiler>
</ReportContext.Provider>
</>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
label: {
fontSize: 28,
},
text: {
fontSize: 20,
marginTop: 20,
},
});
APIリファレンス
このライブラリの情報、APIリファレンス、その他の詳細については、 公式ドキュメントのreact-native-performance-navigation(英語のみ)を参照してください。
フック
| フック | 説明 | 対応プラットフォーム |
|---|---|---|
useProfiledNavigation |
このラッパーuseProfiledNavigationフックは、react-navigationの未処理のuseNavigationに対して使用すると、2つの呼び出しを1つの呼び出しにまとめることができます。ナビゲーションフローに対応するレンダリング時間のプロファイリングを開始し、指定された宛先画面へのナビゲーションを要求します。 |
すべて |
コンポーネント
| コンポーネント | 説明 | 対応プラットフォーム |
|---|---|---|
ReactNavigationPerformanceView |
ReactNavigationPerformanceViewは標準のPerformanceMeasureView上に構築され、React Navigationライブラリ向けの最適化が追加されています。 |
すべて |
実装の詳細
画面間を移動するためのレンダリングパスレポートは、現在Vega仮想デバイスでは生成されません。
この問題を回避するには、以下に示すようにpackage.jsonファイル内の依存関係を置き換えてください。
"dependencies": {
...
"@amazon-devices/shopify__react-native-performance": "~2.0.0",
"@amazon-devices/shopify__react-native-performance-navigation": "~3.0.0"
},
サポートされているバージョン
| パッケージのバージョン | ベース | @amazon-devices/react-native-keplerバージョン |
|---|---|---|
| 3.0.0 | @shopify/react-native-performance-navigation v3.0.0 | 2.0.x |
関連リソース
その他のライブラリについては、サポート対象のサードパーティのライブラリとサービスを参照してください。
Last updated: 2025年9月30日

