はじめから
このプラグインのインストールステップとフルマークダウンガイドまでのステップを含むセットアッププロンプトをコピーしてください。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-native-navigation`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/native-navigation/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」のセクションCapgoのAI-Assisted Setupを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを実行してください。
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次に、以下のプロンプトを使用してください。
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-native-navigation` plugin in my project.Manual Setupを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
-
パッケージをインストールする
ターミナル画面 npm i @capgo/capacitor-native-navigation -
ネイティブプロジェクトを同期する
ターミナル画面 npx cap sync -
ネイティブブラウザを設定する
import { NativeNavigation } from '@capgo/capacitor-native-navigation';await NativeNavigation.configure({contentInsetMode: 'css',animationDuration: 360,colors: {tint: '#0f172a',inactiveTint: '#64748b',},}); -
ネイティブナビゲーションバーをレンダリングする
await NativeNavigation.setNavbar({title: 'Home',subtitle: 'Native chrome',transparent: true,backButton: { visible: false },rightItems: [{id: 'compose',title: 'Compose',icon: {svg: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',},},],}); -
ネイティブタブバーをレンダリングする
await NativeNavigation.setTabbar({selectedId: 'home',labelVisibilityMode: 'selected',icons: true,colors: {dynamic: true,tint: '#0f172a',inactiveTint: '#64748b',},tabs: [{id: 'home',title: 'Home',icon: {svg: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 10.5 12 3l9 7.5"/><path d="M5 10v10h14V10"/></svg>',},},{id: 'settings',title: 'Settings',badge: '2',icon: {svg: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3"/></svg>',},},],}); -
ネイティブ インテント イベントを処理する
await NativeNavigation.addListener('navbarBack', () => {router.back();});await NativeNavigation.addListener('navbarItemTap', ({ id }) => {if (id === 'compose') router.push('/compose');});await NativeNavigation.addListener('tabSelect', ({ id }) => {router.push(`/${id}`);});
フロー
「フロー」のセクションネイティブ トランジションは、通常の JavaScript ルート変更のトランザクションです:
const transition = await NativeNavigation.beginTransition({ direction: 'forward',});
router.push('/detail');await router.ready?.();
await NativeNavigation.setNavbar({ title: 'Detail', backButton: { visible: true, title: 'Back' },});
await NativeNavigation.finishTransition({ id: transition.id, direction: 'forward',});ズーム トランジション
「ズーム トランジション」のセクションカードから詳細へのフローまたはメディア プレビュー フローでズーム ヘルパーを使用します。タップされた要素をルーターがコンテンツを変更する前に渡し、詳細ページが準備されている後には終了します。
import { beginZoomTransition, finishZoomTransition } from '@capgo/capacitor-native-navigation';
const card = document.querySelector('[data-message-card]');if (card) { const transition = await beginZoomTransition(card, { cornerRadius: 18 });
router.push('/message/42'); await router.ready?.();
await NativeNavigation.setNavbar({ title: 'Message', backButton: { visible: true, title: 'Inbox' }, });
await finishZoomTransition(undefined, { id: transition.id, cornerRadius: 18, });}「@capgo/capacitor-transitions」で使用する
「@capgo/capacitor-transitions」で使用する」のセクションNative Navigationを使用して、ネイティブのナビゲーションバー、タブバー、セーフエリアのインセット、ネイティブのイベントを使用します。 @capgo/capacitor-transitions WebViewページスタックの下のネイティブのChromeを使用する。
npm install @capgo/capacitor-native-navigation @capgo/capacitor-transitionsnpx cap sync両方のパッケージを一度に初期化します:
import { NativeNavigation } from '@capgo/capacitor-native-navigation';import '@capgo/capacitor-transitions';import { initTransitions, setupRouterOutlet, setDirection } from '@capgo/capacitor-transitions/react';
initTransitions({ platform: 'auto' });
const outlet = document.querySelector('cap-router-outlet');if (outlet) { setupRouterOutlet(outlet, { platform: 'auto', swipeGesture: 'auto' });}
await NativeNavigation.configure({ contentInsetMode: 'css',});__CAPGO_KEEP_0__ cap-router-outlet ページにフォーカスし、重複したWebバーを避ける:
<cap-router-outlet platform="auto" swipe-gesture="auto"> <cap-page> <cap-content slot="content" fullscreen> <main class="page">Inbox content</main> </cap-content> </cap-page></cap-router-outlet>両方のパッケージから同じルーターアクションを使用します:
async function openMessage(id: string) { setDirection('forward'); await router.push(`/messages/${id}`); await NativeNavigation.setNavbar({ title: 'Message', backButton: { visible: true, title: 'Inbox' }, });}
await NativeNavigation.addListener('navbarBack', () => { setDirection('back'); router.back();});
await NativeNavigation.addListener('tabSelect', ({ id }) => { setDirection('root'); router.push(`/${id}`);});ルート変更ごとにアニメーション層を1つ選択します。 @capgo/capacitor-transitions アニメーションを使用して通常のページをプッシュし、共有要素またはズームルートのみに使用するNative Navigationのズームヘルパー。
CSSのインセット
セクション「CSSのインセット」そして contentInsetMode: 'css'プラグインは、 document.documentElement.
.page { padding-top: var(--cap-native-navigation-top); padding-bottom: var(--cap-native-navigation-bottom);}利用可能な変数:
--cap-native-navigation-top--cap-native-navigation-right--cap-native-navigation-bottom--cap-native-navigation-left--cap-native-navbar-height--cap-native-tabbar-height
アイコンの説明
セクション「アイコンの説明」アイコンは、ネイティブUIがレンダリングするため、シリアライズ可能でなければなりません。共通のアイコンセットであるLucideやFeatherなどのアイコンに焦点を当てたサブセットをサポートするインラインSVGを使用できます。
const icon = { svg: '<svg viewBox="0 0 24 24"><path d="M3 10.5 12 3l9 7.5"/></svg>', width: 24, height: 24, template: true, src: 'fallback_asset_name', ios: { svg: '<svg viewBox="0 0 24 24"><path d="M3 10.5 12 3l9 7.5"/></svg>', sfSymbol: 'house.fill', image: 'BundledAssetName', }, android: { svg: '<svg viewBox="0 0 24 24"><path d="M3 10.5 12 3l9 7.5"/></svg>', resource: 'ic_menu_view', image: 'bundled_drawable_name', },};インラインSVGは、共通のアイコンセットであるLucideやFeatherなどのアイコンに焦点を当てたサブセットをサポートします。 path, line, polyline, polygon, circle, and rectデフォルトでは、SVG アイコンはテンプレート画像としてレンダリングされるため、ネイティブのタント色で色を付けることができます。
オプションのWebコンポーネント
「オプションのWebコンポーネント」パッケージは、フレームワーク非依存の宣言的設定でカスタム要素を登録できます。
import { defineNativeNavigationElements } from '@capgo/capacitor-native-navigation';
defineNativeNavigationElements();<cap-native-navigation-provider enabled="true" content-inset-mode="css"></cap-native-navigation-provider>
<cap-native-navbar title="Home" transparent right-items='[{"id":"compose","title":"Compose","icon":{"svg":"<svg viewBox=\"0 0 24 24\"><path d=\"M12 20h9\"/></svg>"}}]'></cap-native-navbar>
<cap-native-tabbar selected-id="home" tabs='[{"id":"home","title":"Home","icon":{"ios":{"sfSymbol":"house.fill"}}}]'></cap-native-tabbar>プラットフォームに関する注意
「プラットフォームに関する注意」- iOSがレンダリング
UINavigationBarとUITabBar; iOS 26+ではシステムのLiquid Glassバーの動作を使用 - AndroidはAppCompatツールバーとMaterialの下部ナビゲーションをレンダリング
- Webのフォールバックはネイティブバーを描画せず、イベントとブラウザ開発用のインセット変数をミラーリング
- プラグインは1つのフルスクリーンのCapacitor WebViewを保持
続けてください
「続けてください」あなたが使用している 「Getting Started」 を計画するネイティブメディアとインターフェイスの動作に使用している場合 「@capgo/capacitor-native-navigation」を接続 for the native capability in Using @capgo/capacitor-native-navigation, Using @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-live-activities, Using @capgo/capacitor-video-player for the native capability in Using @capgo/capacitor-video-player, and @capgo/capacitor-video-player for the implementation detail in @capgo/capacitor-video-player.