メインコンテンツにジャンプ
@capgo/capacitor-トランジション UI & システム オープンソース

トランジション Capacitor プラグイン

アイオニックスタイルのページトランジションとiOSエッジスワイプバックジェスチャーを追加する

インストール

bun add @capgo/capacitor-transitions bunx cap sync
npm、pnpm、またはyarn
  • npm install @capgo/capacitor-transitions
  • pnpm add @capgo/capacitor-transitions
  • yarn add @capgo/capacitor-transitions

デモ

トランジションのデモ

iOSスタイルのCapacitorページのアニメーションWebPデモを表示するReactルーターフロー

ソースアセット
アニメーション付きのReactページ遷移デモ、Capacitorスタイルのシェル内で前方と後方のナビゲーションを表示します。
Reactトランジションフロー

ガイド

Capacitorでトランジションを使用する方法

デバイスでテスト

Capgoアプリをダウンロードし、QR codeをスキャンしてください。

トランジション プラグイン プレビュー QR code

Using @capgo/capacitor-transitions

@capgo/capacitor-transitions Capacitorは、Ionic UIを採用することなく、Ionicスタイルのルート トランジションをCapacitorアプリに追加できます。 これは、Web層で実行され、既存のルーターを維持し、iOSエッジ スワイプ バック ゲストラを自動的に有効にすることができます。ただし、これはネイティブCapacitor iOSのみで機能します。

インストール

npm install @capgo/capacitor-transitions

Native sync のステップはありません。パッケージはネイティブ プラグイン code を追加していないためです。

要素を登録する

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 の例

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}>{/* routes */}</cap-router-outlet>;
}

export function InboxPage() {
  const navigate = useNavigate();
  const pageRef = useRef<HTMLElement>(null);

  useEffect(() => {
    if (!pageRef.current) return;
    return setupPage(pageRef.current);
  }, []);

  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 がまだ、 cap-router-outlet に存在しないと報告している場合、 JSX.IntrinsicElementsを追加してください。

// src/capgo-transitions.d.ts
import '@capgo/capacitor-transitions/react';

Vite、Create React App、およびほとんどの webpack React アプリでは、そのファイルを src/ の下に保つだけで十分です。Next.js またはカスタムの TypeScript 設定の場合、含まれていることを確認してください。 tsconfig.json:

{
  "include": ["src", "src/capgo-transitions.d.ts"]
}

スワイプバックを有効にする

を使用 swipe-gesture="auto" CapacitorがiOSネイティブランタイムを報告する場合にのみジェスチャーを有効にする:

<cap-router-outlet swipe-gesture="auto"></cap-router-outlet>

JavaScriptから強制することもできます:

const outlet = document.querySelector('cap-router-outlet');

outlet?.setSwipeGesture(true);
outlet?.setSwipeGesture(false);
outlet?.setSwipeGesture('auto');

ジェスチャーはトランジション中、指を追跡し、ユーザーが指を離すと完了またはキャンセルします。 data-swipe-gesture-ignore onボタン、スライダー、ドロワーに追加して、エッジジェスチャーを開始しないようにします。

ネイティブナビゲーションと組み合わせて使用

インストール @capgo/native-navigation ネイティブレイヤーがナビゲーションバーまたはタブバーを所有する場合に使用:

npm install @capgo/native-navigation
npx cap sync

ネイティブクロームを設定し、WebViewページにトランジションを集中させます:

import { NativeNavigation } from '@capgo/native-navigation';
import { setDirection } from '@capgo/capacitor-transitions/react';
import { router } from './router';

await NativeNavigation.configure({
  contentInsetMode: 'css',
});

await NativeNavigation.setNavbar({
  title: 'Inbox',
  backButton: { visible: false },
});

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-content アニメーションページボディとネイティブナビゲーションCSS変数のインセット

<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);
}

Nativeナビゲーションバーを移動するWebヘッダーとして複製しないでください。 @capgo/native-navigation nativeバーを維持します。 @capgo/capacitor-transitions ページコンテンツの下にアニメーションを実行します。

フルリファレンス

Using @capgo/capacitor-transitionsから続けてください。

あなたが使用している場合 Using @capgo/capacitor-transitions プラグインを使用してネイティブメディアとインターフェイスの動作を計画し、接続する @capgo/capacitor-トランジション Capacitor-トランジション用の実装詳細については、@capgo/capacitor-トランジションを参照してください。 はじめに Capacitor-transitionsの実装詳細については、Getting Startedを参照してください。 @capgo/capacitorライブアクティビティ Capacitor-ライブアクティビティ用の実装詳細については、@capgo/capacitor-ライブアクティビティを参照してください。 @capgo/capacitor-ライブアクティビティ Capacitor-ビデオプレーヤー用の実装詳細については、@capgo/capacitor-ビデオプレーヤーを参照してください。 @Capacitor-capgo/capacitor-video-player Capacitor のネイティブ機能のために @capgo/capacitor-video-player を使用します。

FAQ

トランジション プラグインの FAQ

Capacitor Transitions プラグインを Capacitor アプリにインストールする方法は何ですか。

Run &quot;bun add @capgo/capacitor-transitions&quot; (or &quot;npm install @capgo/capacitor-transitions&quot;), then run &quot;bunx cap sync&quot; so the iOS and Android projects pick up the native code. Import it from &quot;@capgo/capacitor-transitions&quot; in your app code.

Does @capgo/capacitor-transitions work with React, Vue and Angular?

Yes. Transitions is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-transitions support?

Capgo plugins follow Capacitor&#39;s major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

@capgo/capacitorは無料でオープンソースですか?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-transitions/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Transitions without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

アプリレビューを待たずにトランジションの変更を配信する

プラグインがストアビルドに追加された後、Capgoライブアップデートにより、JavaScript、HTML、CSSの変更がユーザーに数分で反映されます。

Start with Capgo