@capgo/capacitor-native-navigation
@capgo/capacitor-native-navigation ネイティブのトップナビゲーション、ボトムタブのChrome、ルートのトランジションシェルを1つのフルスクリーンのCapacitor WebView上にレンダリングします。ウェブフレームワークはルートとコンテンツを管理し、ネイティブはアプリケーションフレームを管理します。
インストールと同期
npm install @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: 'Inbox',
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: 'inbox',
labelVisibilityMode: 'selected',
icons: true,
colors: {
dynamic: true,
tint: '#0f172a',
inactiveTint: '#64748b',
},
tabs: [
{
id: 'inbox',
title: 'Inbox',
icon: {
svg: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 4h16v16H4z"/><path d="m4 13 4 4h8l4-4"/></svg>',
},
},
{
id: 'search',
title: 'Search',
icon: {
svg: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><path d="m20 20-3-3"/></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}`);
});
ルート変更のアニメーション
通常のウェブルートの更新にトランジショントランザクションを使用してください:
const transition = await NativeNavigation.beginTransition({
direction: 'forward',
});
router.push('/message/42');
await router.ready?.();
await NativeNavigation.setNavbar({
title: 'Message',
backButton: { visible: true, title: 'Inbox' },
});
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,
});
}
ネイティブインセットでコンテンツをパディング
When contentInsetMode は css, native bars に対して CSS 変数を書き込むプラグイン:
.page {
padding-top: var(--cap-native-navigation-top);
padding-bottom: var(--cap-native-navigation-bottom);
}
アイコンの選択肢
アイコンは、React または Vue ノードではなく、native の記述子です。native アセットをバンドルしない場合、SVG を使用してください:
const icon = {
svg: '<svg viewBox="0 0 24 24"><path d="M3 10.5 12 3l9 7.5"/></svg>',
template: true,
ios: { sfSymbol: 'house.fill' },
android: { resource: 'ic_menu_view' },
};
Inline SVG は path, line, polyline, polygon, circle, rect,
Combine with @capgo/capacitor-transitions
を組み合わせて@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-transitions @capgo/capacitor-transitions Native Navigation を使用して、native navbar、tabbar、safe-area insets、native intent イベントを使用してください。
npm install @capgo/capacitor-native-navigation @capgo/capacitor-transitions
npx cap sync
WebView ページ スタックの下にnative chrome を使用する場合、を使用してください。
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',
});
両方のパッケージを一度に初期化してください。
<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つのアニメーションレイヤーをルート変更ごとに選択する。通常のページのプッシュはアニメーションするが、共有要素またはズーム ルートの場合のみ、Native Navigationのズーム ヘルパーを使用する。 @capgo/capacitor-transitions フル リファレンス
__CAPGO_KEEP_0__:
- https://GitHub.com/Cap-go/__CAPGO_KEEP_1__-native-navigation/ https://github.com/Cap-go/capacitor-native-navigation/
- 使用中の@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-native-navigationから続けてください。
capgo/capacitor-native-navigationを使用している場合
@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-native-navigationを使用して、ネイティブ メディアとインターフェイスの動作を計画する場合、Native Navigationと接続する。 @capgo/capacitor-native-navigationを使用してください。 ドキュメント: /docs/plugins/native-navigation/ capgo/capacitor-native-navigationを使用している場合 実装詳細については @capgo/capacitor-native-navigation に Getting Started 実装詳細については Getting Started に 使用中の @capgo/capacitor-live-activities 使用中の @capgo/capacitor-live-activities のネイティブ機能について @capgo/capacitor-live-activities 実装詳細については @capgo/capacitor-live-activities に 使用中の @capgo/capacitor-video-player 使用中の @capgo/capacitor-video-player のネイティブ機能について