shopify-react-native-performance-navigation-drawer
shopify-react-native-performance-navigation-drawerは、@shopify/react-native-performance-navigation上にある拡張ライブラリです。@react-navigation/drawerライブラリ用のヘルパーメソッドが追加されています。
インストール
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", "@shopify/react-native-performance-navigation-drawer": "npm:@amazon-devices/shopify__react-native-performance-navigation-drawer@~3.0.0", "@amazon-devices/react-native-reanimated": "~2.0.0", "@amazon-devices/react-native-gesture-handler": "~2.0.0" },- 次のコマンドを実行します。このコマンドは、現在のプロジェクトに限定して、ピア依存関係の処理にバージョン7より前の動作を使用するようにnpmを設定します。これにより、互換性があるとは限らない依存関係や古い依存関係を扱うときに、より緩やかなパッケージインストールが可能になります。
npm config set legacy-peer-deps=true --location=project 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-native-reanimated/plugin" ]- プロジェクトで
@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コマンドを使用して、依存関係を再インストールします。 - キャッシュのリセットオプションを使用して、
npm start -- --reset-cacheとしてMetroを再起動します。
例
createProfiledDrawerNavigator関数で作成されたドロワーナビゲーターを使用して、さまざまなタブ内でホストされている画面のレンダリングにかかる時間をプロファイリングします。
import React, { useCallback, useContext, useState } from 'react';
import { createProfiledDrawerNavigator } from '@shopify/react-native-performance-navigation-drawer';
import {
LogLevel,
PerformanceProfiler,
RenderPassReport,
} from '@shopify/react-native-performance';
import { NavigationContainer } from '@amazon-devices/react-navigation__native';
import { StyleSheet, Text, View } from 'react-native';
import { ReactNavigationPerformanceView } from '@shopify/react-native-performance-navigation';
import { GestureHandlerRootView } from '@amazon-devices/react-native-gesture-handler';
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 DrawerScreenA = () => {
const { findReport } = useReportContext();
const report = findReport('drawerScreenA', 'Drawer');
return (
<ReactNavigationPerformanceView
screenName="drawerScreenA"
interactive={true}
>
<View style={styles.container}>
<Text style={styles.label}>ナビゲーションのレンダリング時間の測定</Text>
<Text style={styles.label}>
「Drawer」から「ドロワー画面A」へのナビゲーション後に毎回新しいレポートが
生成されます
</Text>
<Text style={styles.text}>{JSON.stringify(report)}</Text>
</View>
</ReactNavigationPerformanceView>
);
};
const DrawerScreenB = () => {
const { findReport } = useReportContext();
const report = findReport('drawerScreenB', 'Drawer');
return (
<ReactNavigationPerformanceView
screenName="drawerScreenB"
interactive={true}
>
<View style={[styles.container]}>
<Text style={styles.label}>ナビゲーションのレンダリング時間の測定</Text>
<Text style={styles.label}>
「Drawer」から「ドロワー画面B」へのナビゲーション後に毎回新しいレポートが
生成されます"
</Text>
<Text style={styles.text}>{JSON.stringify(report)}</Text>
</View>
</ReactNavigationPerformanceView>
);
};
const Drawer = createProfiledDrawerNavigator();
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 (
<GestureHandlerRootView style={{flex: 1}}>
<ReportContext.Provider value={{ saveReport, findReport }}>
<PerformanceProfiler
onReportPrepared={onReportPrepared}
logLevel={LogLevel.Debug}
>
<NavigationContainer>
<Drawer.Navigator>
<Drawer.Screen name="ドロワー画面A" component={DrawerScreenA} />
<Drawer.Screen name="ドロワー画面B" component={DrawerScreenB} />
</Drawer.Navigator>
</NavigationContainer>
</PerformanceProfiler>
</ReportContext.Provider>
</GestureHandlerRootView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
backgroundColor: '#283593',
},
label: {
color: 'white',
fontSize: 28,
},
text: {
fontSize: 20,
color: 'white',
marginTop: 20,
},
});
APIリファレンス
このライブラリの情報、APIリファレンス、その他の詳細については、 公式ドキュメントのreact-native-performance-navigation-drawer(英語のみ)を参照してください。
関数
| 関数 | 説明 | 対応プラットフォーム |
|---|---|---|
createDrawerNavigator |
このユーティリティは、標準のcreateDrawerNavigatorをラップしたものです。さまざまなタブ内でホストされている画面のレンダリングにかかる時間をプロファイリングできます。 | すべて |
実装の詳細
- react-navigationのドロワーナビゲーターのフォーカス管理に関する既知の問題により、ドロワーナビゲーター内を移動するためのレンダリングパスレポートは、現在Vegaでは生成されません。
サポートされているバージョン
| パッケージのバージョン | ベース | @amazon-devices/react-native-keplerバージョン |
|---|---|---|
| 3.0.0 | @shopify/react-native-performance-navigation-drawer v3.0.0 | 2.0.x |
関連リソース
その他のライブラリについては、サポート対象のサードパーティのライブラリとサービスを参照してください。
Last updated: 2025年9月30日

