スタートガイド
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
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.
インストール
「インストール」セクションAIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いの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-transitions` plugin in my project.手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
-
パッケージをインストール
ターミナル npm install @capgo/capacitor-transitions -
Webコンポーネントを登録する
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"]}別の types/ フォルダ、代わりにそのフォルダを含めてください:
{ "include": ["src", "types"]}スワイプバック
「Swipe Back」セクションマークアップから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 Capacitor がネイティブの iOS ランタイムを報告している場合のみ、ジェスチャーが有効になります。ジェスチャー中、ページ遷移は指の動きに追従します。ユーザーが指を離すと、遷移が完了してブラウザ履歴が戻るか、あるいは遷移がキャンセルされて現在のページが復元されます。
特定の要素でジェスチャーを開始させないようにするには、以下を追加します: data-swipe-gesture-ignore:
<button data-swipe-gesture-ignore>Open drawer</button>Native Navigation と併用
「Native Navigation を使用する場合」セクション使用する @capgo/capacitor-transitions を使用して @capgo/native-navigation ウェブコンテンツは Ionic スタイルのページモーションを維持しつつ、ネイティブ側でトップバーとボトムバーを制御したい場合に使用します。
-
ネイティブナビゲーションパッケージをインストールして同期します:
ターミナル npm install @capgo/native-navigationnpx cap sync -
ネイティブUIクロームを設定:
import { NativeNavigation } from '@capgo/native-navigation';await NativeNavigation.configure({contentInsetMode: 'css',});await NativeNavigation.setNavbar({title: 'Inbox',backButton: { visible: false },}); -
Web transition outlet はページのみを担当させる:
<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);} -
両方のシステムを同じルーターイベントで動かす:
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' },});}
ネイティブのトップバーを動く要素として再レンダリングしない <cap-header>。〜に任せ、 @capgo/native-navigation バーはネイティブのままにして、 @capgo/capacitor-transitions その下のWebViewページコンテンツに使います。
コンポーネント
「Components」セクション<cap-router-outlet>
「<cap-router-outlet>」セクション| 属性 | 種類 | デフォルト | 説明 |
|---|---|---|---|
platform | 'ios' | 'android' | 'auto' | 'auto' | アニメーションスタイル |
duration | number | プラットフォームのデフォルト | アニメーションの継続時間 (ms) |
keep-in-dom | boolean | true | 非アクティブなページをDOMに保持 |
max-cached | number | 10 | キャッシュする最大ページ数 |
swipe-gesture | boolean | 'auto' | 'auto' | iOSのエッジジェスチャを有効化、無効化、またはネイティブ検知に設定 |
メソッド:
push(element, config?)pop(config?)setRoot(element, config?)setSwipeGesture(true | false | 'auto')
<cap-page>
「<cap-page>」セクション1つのページをラップし、ライフサイクルイベントを発行します:
cap-will-entercap-did-entercap-will-leavecap-did-leave
<cap-content>
「<cap-content>」セクション| 属性 | 種類 | デフォルト | 説明 |
|---|---|---|---|
fullscreen | boolean | false | コンテンツをヘッダーの背後でスクロールさせる |
scroll-x | boolean | true | 水平スクロールを有効にする |
scroll-y | boolean | true | 垂直スクロールを有効にする |
フレームワーク用ヘルパー
「Framework Helpers」セクション各フレームワークのエントリポイントでは、以下の共通コアヘルパーが利用可能です:
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 からの続き」セクション使用している場合 スタートガイド 移行とエンタープライズ運用を計画するには、次と連携してください @capgo/capacitor-transitions の活用 「@capgo/capacitor-transitions の使用」のネイティブ機能については、 Capgo エンタープライズ Capgo Enterprise のプロダクトワークフロー向けに、 Ionic Enterprise プラグインの代替案 Ionic Enterprise Plugin Alternatives のプロダクトワークフロー向けに、 Capgo の代替案 Capgo Alternatives のプロダクトワークフロー向け、および Capgo コンサルティング Capgo Consulting のプロダクトワークフロー向けに。