shopify-react-native-performance-navigation-bottom-tabs
shopify-react-native-performance-navigation-bottom-tabsは、@shopify/react-native-performance-navigation上にある拡張ライブラリです。@react-navigation/bottom-tabsライブラリ用のヘルパーメソッドが追加されています。
インストール
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-bottom-tabs": "npm:@amazon-devices/shopify__react-native-performance-navigation-bottom-tabs@~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 { createProfiledBottomTabNavigator } from '@shopify/react-native-performance-navigation-bottom-tabs';
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';
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 BottomTabScreenA = () => {
const { findReport } = useReportContext();
const report = findReport('bottomTabScreenA', 'BottomTabBar');
return (
<ReactNavigationPerformanceView
screenName="bottomTabScreenA"
interactive={true}
>
<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 "Bottom Tab Bar" to
"Bottom Tab Screen A"
</Text>
<Text style={styles.text}>{JSON.stringify(report)}</Text>
</View>
</ReactNavigationPerformanceView>
);
};
const BottomTabScreenB = () => {
const { findReport } = useReportContext();
const report = findReport('bottomTabScreenB', 'BottomTabBar');
return (
<ReactNavigationPerformanceView
screenName="bottomTabScreenB"
interactive={true}
>
<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 "Bottom Tab Bar" to
"Bottom Tab Screen B"
</Text>
<Text style={styles.text}>{JSON.stringify(report)}</Text>
</View>
</ReactNavigationPerformanceView>
);
};
const { Tab, buildProfiledBottomTabBarButton } =
createProfiledBottomTabNavigator();
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}
logLevel={LogLevel.Debug}
>
<NavigationContainer>
<Tab.Navigator initialRouteName="ボトムタブ画面A">
<Tab.Screen
name="Bottom Tab Screen A"
component={BottomTabScreenA}
options={{
// @ts-ignore
tabBarButton: buildProfiledBottomTabBarButton(),
}}
/>
<Tab.Screen
name="Bottom Tab Screen B"
component={BottomTabScreenB}
options={{
// @ts-ignore
tabBarButton: buildProfiledBottomTabBarButton(),
}}
/>
</Tab.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-bottom-tabs(英語のみ)を参照してください。
関数
| 関数 | 説明 | 対応プラットフォーム |
|---|---|---|
createProfiledBottomTabNavigator |
このユーティリティは、標準のcreateBottomTabNavigatorをラップしたものです。さまざまなタブ内でホストされている画面のレンダリングにかかる時間をプロファイリングできます。 | すべて |
実装の詳細
- ボトムタブ間を移動するためのレンダリングパスレポートは、現在Vegaでは正しく生成されません。
サポートされているバージョン
| パッケージのバージョン | ベース | @amazon-devices/react-native-keplerバージョン |
|---|---|---|
| 3.0.0 | @shopify/react-native-performance-navigation-bottom-tabs v3.0.0 | 2.0.x |
関連リソース
その他のライブラリについては、サポート対象のサードパーティのライブラリとサービスを参照してください。
Last updated: 2025年9月30日

