@capgo/capacitor-screen-orientation を使用
Capacitor スクリーン オリエンテーション プラグイン インターフェイス
インストール
bun add @capgo/capacitor-screen-orientation
bunx cap sync
bunx cap sync プラグインのネイティブ code をあなたのネイティブ プロジェクトにコピーします。プラグインのアップグレード後は、もう一度実行してください。
インポート
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
API の概要
| 方法 | 説明 |
|---|---|
orientation |
現在のスクリーン オリエンテーションを取得する |
lock |
特定のタイプのスクリーン オリエンテーションにロックする |
unlock |
スクリーン オリエンテーションをアンロックする |
startOrientationTracking |
モーション センサを使用してデバイス オリエンテーションを追跡する |
stopOrientationTracking |
モーション センサを使用してデバイス オリエンテーションを停止する |
isOrientationLocked |
デバイス オリエンテーション ロックが現在有効かどうかを確認する |
isDeviceFoldable |
スクリーン オリエンテーション変更をリスンする |
getFoldState |
現在の折りたたみを読み取る |
getHingeAngle |
角度を読み取る |
getReservedRegions |
スクリーンを覆うものも含めて折りたたみを読み取る |
getBarPlacement |
iPhone Duoがネイティブのタブバーとツールバーを配置する場所を読み取る |
setVerticalBarBehavior |
iPhone Duoがこのアプリのバーをサイドに移動できるかどうかを選択する |
getSizeClass |
ウィンドウサイズのクラスを読み取る |
例
orientation()
現在の画面の向きを取得する
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();
console.log('Current orientation:', result.type);
lock()
画面の向きを特定のタイプに固定する
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Standard lock
await ScreenOrientation.lock({ orientation: 'landscape' });
// Lock with motion tracking on iOS
await ScreenOrientation.lock({
orientation: 'portrait',
bypassOrientationLock: true
});
unlock()
画面の向きを解除する
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();
startOrientationTracking()
モーションセンサを使用してデバイスの向きを追跡する
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.startOrientationTracking({
bypassOrientationLock: true
});
// Listen for changes
ScreenOrientation.addListener('screenOrientationChange', (result) => {
console.log('Orientation changed:', result.type);
});
stopOrientationTracking()
モーションセンサを使用してデバイスの向きを追跡を停止する
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();
isOrientationLocked()
デバイスの向きロックが現在有効になっているかどうかを確認します。
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Start motion tracking first
await ScreenOrientation.startOrientationTracking({
bypassOrientationLock: true
});
// Check lock status
const status = await ScreenOrientation.isOrientationLocked();
if (status.locked) {
console.log('Orientation lock is ON');
console.log('Physical:', status.physicalOrientation);
console.log('UI:', status.uiOrientation);
}
上の表には、13の基本メソッドがリストされています。リスナーとバージョンヘルパー、各メソッドの完全な契約書は、__CAPGO_KEEP_0__ リポジトリにドキュメントされています。 GitHub リポジトリ.
イベントをリスンする
addListener ハンドルを返します。画面がアンマウントされたとき、またはすべてのリスナーをクリアするときに呼び出してください。 handle.remove() 全体のリファレンス ScreenOrientation.removeAllListeners() ドキュメント
__CAPGO_KEEP_0__ リファレンス
@capgo/capacitor-screen-orientationを継続して使用してください。
Capacitor を使用している場合 Capacitor の @capgo/capacitor-screen-orientation native media とインターフェイスの動作を計画するには、を接続する Capacitor の @capgo/capacitor-screen-orientation @capgo/capacitor スクリーンオリエンテーション実装詳細 Capacitor の Getting Started Capacitor の Getting Started の実装詳細については、Getting Started を参照してください。 Capacitor の @capgo/capacitor-live-activities Capacitor の @capgo/capacitor-live-activities Capacitor の @capgo/capacitor-live-activities の実装詳細については、@capgo/capacitor-live-activities を参照してください。 Capacitor の @capgo/capacitor-live-activities Capacitor の @capgo/capacitor-video-player native capability in Using @capgo/capacitor-video-player.