始めてから
このプラグインのインストール手順とフルマークダウンガイドのセットアッププロンプトをコピーする。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-transitions`
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/transitions/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.
-
パッケージをインストール
ターミナル画面 npm install @capgo/capacitor-transitions -
ウェブコンポーネントを登録
import '@capgo/capacitor-transitions'; -
ルーティングされたページをラップ
<cap-router-outlet platform="auto" swipe-gesture="auto"><cap-page><cap-header slot="header"><h1>Inbox</h1></cap-header><cap-content slot="content"><button>Open message</button></cap-content><cap-footer slot="footer"><nav>Tabs</nav></cap-footer></cap-page></cap-router-outlet> -
ルーターがルートを変更する前に方向を設定
import { setDirection } from '@capgo/capacitor-transitions/react';setDirection('forward');router.push('/message/42');setDirection('back');router.back();
React セットアップ
React セットアップimport { useEffect, useRef } from 'react';import { useNavigate } from 'react-router-dom';import { initTransitions, setDirection, setupPage, setupRouterOutlet } from '@capgo/capacitor-transitions/react';import '@capgo/capacitor-transitions';
initTransitions({ platform: 'auto' });
export function AppShell() { const outletRef = useRef<HTMLElement>(null);
useEffect(() => { if (!outletRef.current) return;
setupRouterOutlet(outletRef.current, { platform: 'auto', swipeGesture: 'auto', }); }, []);
return ( <cap-router-outlet ref={outletRef}> {/* Your router renders cap-page children here. */} </cap-router-outlet> );}
export function InboxPage() { const navigate = useNavigate(); const pageRef = useRef<HTMLElement>(null);
useEffect(() => { if (!pageRef.current) return;
return setupPage(pageRef.current, { onDidEnter: () => console.log('Inbox visible'), }); }, []);
return ( <cap-page ref={pageRef}> <cap-header slot="header"> <h1>Inbox</h1> </cap-header>
<cap-content slot="content"> <button onClick={() => { setDirection('forward'); navigate('/message/42'); }} > Open message </button> </cap-content> </cap-page> );}React JSX TypeScript
React JSX TypeScriptインポート @capgo/capacitor-transitions/react JSX の型定義を含み、 cap-router-outlet, cap-page, cap-header, cap-content、を含みます。 cap-footerほとんどの React プロジェクトでは、そのインポートは TSX でカスタム要素を有効にします。
TypeScript が依然として Property 'cap-router-outlet' does not exist on type 'JSX.IntrinsicElements'を報告する場合、プロジェクト宣言ファイルを追加してください。
import '@capgo/capacitor-transitions/react';Vite、Create React App、およびほとんどのwebpack Reactアプリでは、そのファイルを src/ に置くだけで十分です。Next.jsの場合、 src/ またはプロジェクトのルートに置き、 tsconfig.json を含むようにしてください:
{ "include": ["src", "src/capgo-transitions.d.ts"]}カスタムのTypeScriptまたはwebpackの設定で、別の types/ フォルダを使用している場合、そのフォルダを含めてください:
{ "include": ["src", "types"]}スワイプバック
「スワイプバック」のセクションiOS エッジ ゲストをマークアップから有効または無効にします:
<cap-router-outlet swipe-gesture="auto"></cap-router-outlet><cap-router-outlet swipe-gesture="true"></cap-router-outlet><cap-router-outlet swipe-gesture="false"></cap-router-outlet>または、JavaScript から:
const outlet = document.querySelector('cap-router-outlet');
outlet?.setSwipeGesture('auto');outlet?.setSwipeGesture(true);outlet?.setSwipeGesture(false);auto iOS 本来のランタイムを報告する Capacitor が native iOS ランタイムである場合にのみ、ジェスチャーを有効にします。ジェスチャー中、ページのトランジションは指の動きに従います。ユーザーがリリースすると、トランジションは完了し、ブラウザの履歴に戻るよう求めるか、キャンセルし、現在のページを復元します。
ページのジェスチャーを開始しないようにするには、 data-swipe-gesture-ignore:
<button data-swipe-gesture-ignore>Open drawer</button>Native Navigation を使用します
Native NavigationNative Navigation を使用する場合の設定 @capgo/capacitor-transitions Native Navigation を使用する場合の設定 @capgo/native-navigation Native Navigation を使用する場合の設定
-
Install and sync the native navigation package:
Terminal window npm install @capgo/native-navigationnpx cap sync -
Configure native chrome:
import { NativeNavigation } from '@capgo/native-navigation';await NativeNavigation.configure({contentInsetMode: 'css',});await NativeNavigation.setNavbar({title: 'Inbox',backButton: { visible: false },}); -
Keep the web transition outlet responsible for pages only:
<cap-router-outlet platform="auto" swipe-gesture="auto"><cap-page><cap-content slot="content" fullscreen><main class="native-page">Inbox content</main></cap-content></cap-page></cap-router-outlet>.native-page {padding-top: var(--cap-native-navigation-top);padding-bottom: var(--cap-native-navigation-bottom);} -
Drive both systems from the same router events:
import { NativeNavigation } from '@capgo/native-navigation';import { setDirection } from '@capgo/capacitor-transitions/react';import { router } from './router';await NativeNavigation.addListener('navbarBack', () => {setDirection('back');router.back();});async function openMessage(id: string) {setDirection('forward');router.push(`/message/${id}`);await NativeNavigation.setNavbar({title: 'Message',backButton: { visible: true, title: 'Inbox' },});}
Do not render the native top bar again as a moving <cap-header>. Let @capgo/native-navigation native UI を保持し、 @capgo/capacitor-transitions WebView の下のページコンテンツを使用します。
コンポーネント
「コンポーネント」タイトル<cap-router-outlet>
「<cap-router-outlet>」タイトル| 属性 | タイプ | デフォルト | 説明 |
|---|---|---|---|
platform | 'ios' | 'android' | 'auto' | 'auto' | アニメーションスタイル |
duration | number | プラットフォームのデフォルト | アニメーション時間(ミリ秒) |
keep-in-dom | boolean | true | __CAPGO_KEEP_0__をDOMに保持 |
max-cached | number | 10 | __CAPGO_KEEP_1__ |
swipe-gesture | boolean | 'auto' | 'auto' | iOSのエッジジェスチャーを有効、無効、またはネイティブ検出 |
Methods:
push(element, config?)pop(config?)setRoot(element, config?)setSwipeGesture(true | false | 'auto')
<cap-page>
タイトル「<cap-page>」1つのページをwrapし、ライフサイクルイベントを発行する:
cap-will-entercap-did-entercap-will-leavecap-did-leave
<cap-content>
タイトル「<cap-content>」| 属性 | 型 | デフォルト | 説明 |
|---|---|---|---|
fullscreen | boolean | false | ヘッダー後ろにコンテンツをスクロールする |
scroll-x | boolean | true | __CAPGO_KEEP_0__ |
scroll-y | boolean | true | __CAPGO_KEEP_0__ |
フレームワーク ヘルパー
フレームワーク ヘルパーフレームワーク エントリポイントは、同じコア ヘルパーを公開しています:
import { initTransitions, setDirection, setupPage, setupRouterOutlet } from '@capgo/capacitor-transitions/react';
initTransitions({ platform: 'auto' });setDirection('forward');setupRouterOutlet(element, { platform: 'auto', swipeGesture: 'auto' });setupPage(element, { onWillEnter, onDidEnter, onWillLeave, onDidLeave });利用可能なエントリポイント:
@capgo/capacitor-transitions/react@capgo/capacitor-transitions/vue@capgo/capacitor-transitions/angular@capgo/capacitor-transitions/svelte@capgo/capacitor-transitions/solid
Getting Startedから続けてください
Getting Startedから続けてください企業の移行とエンタープライズ オペレーションを計画する場合は、接続してください Getting Started 計画とエンタープライズ オペレーションを計画する場合は、接続してください 使用@capgo/capacitor-トランジション ネイティブ機能のために使用する@capgo/capacitor-トランジション Capgo エンタープライズ Capgo エンタープライズの製品ワークフロー イオニック エンタープライズ プラグインの代替 イオニック エンタープライズ プラグインの代替の製品ワークフロー Capgo の代替 Capgo の代替の製品ワークフロー Capgo のコンサルティング Capgo のコンサルティングの製品ワークフロー