Getting Started
Copas prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-screen-orientation`
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/screen-orientation/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.
Install
Bagian berjudul “Install”Anda dapat menggunakan Setup Bantuan AI kami untuk menginstal plugin ini. Tambahkan Capgo kemampuan ke alat AI Anda menggunakan perintah berikut:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsLalu gunakan prompt berikut:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-screen-orientation` plugin in my project.Jika Anda lebih suka Setup Manual, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah:
bun add @capgo/capacitor-screen-orientationbunx cap syncImport
Bagian berjudul “Import”import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';API Ringkasan
Judul Bagian “API Pengantar”orientation
Judul Bagian “orientasi”Peroleh orientasi layar saat ini.
Mengembalikan orientasi layar perangkat saat ini.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();console.log('Current orientation:', result.type);Blokir orientasi layar ke jenis tertentu.
Mengunci layar ke orientasi yang ditentukan. Di iOS, jika bypassOrientationLock adalah true, maka akan mulai mengikuti orientasi fisik perangkat menggunakan sensor gerakan.
Perlu diingat: UI akan tetap menghormati pengaturan lock orientasi pengguna. Pengikutan gerakan memungkinkan Anda mendeteksi bagaimana perangkat dipegang meskipun UI tidak berputar.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Standard lockawait ScreenOrientation.lock({ orientation: 'landscape' });
// Lock with motion tracking on iOSawait ScreenOrientation.lock({ orientation: 'portrait', bypassOrientationLock: true});unlock
Judul Bagian “buka”Membuka orientasi layar.
Memungkinkan layar untuk berputar bebas berdasarkan posisi perangkat. Juga menghentikan penggunaan orientasi berdasarkan gerakan jika sudah diaktifkan.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();startOrientationTracking
Bab berjudul “startOrientationTracking”Mulai mengikuti orientasi perangkat menggunakan sensor gerakan.
Methode ini berguna ketika Anda ingin mengikuti orientasi fisik perangkat secara independen dari penguncian orientasi layar. Menggunakan Core Motion pada iOS untuk mendeteksi perubahan orientasi.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.startOrientationTracking({ bypassOrientationLock: true});
// Listen for changesScreenOrientation.addListener('screenOrientationChange', (result) => { console.log('Orientation changed:', result.type);});stopOrientationTracking
Bab berjudul “stopOrientationTracking”Menghentikan pengikutan orientasi perangkat menggunakan sensor gerakan.
Menghentikan penggunaan orientasi berdasarkan gerakan jika sudah diaktifkan.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();isOrientationLocked
Bab berjudul “isOrientationLocked”Periksa jika penguncian orientasi perangkat sudah diaktifkan.
Metode ini membandingkan orientasi perangkat fisik (dari sensor gerak) dengan orientasi UI. Jika mereka berbeda, penguncian orientasi diaktifkan.
Catatan: Ini memerlukan tracking gerak aktif melalui startOrientationTracking() atau lock() dengan bypassOrientationLock: true. Berfungsi pada baik iOS (Core Motion) dan Android (Accelerometer).
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Start motion tracking firstawait ScreenOrientation.startOrientationTracking({ bypassOrientationLock: true});
// Check lock statusconst status = await ScreenOrientation.isOrientationLocked();if (status.locked) { console.log('Orientation lock is ON'); console.log('Physical:', status.physicalOrientation); console.log('UI:', status.uiOrientation);}Referensi Tipe
Judul Bagian “Referensi Tipe”ScreenOrientationResult
Hasil yang dikembalikan oleh metode orientation().Salin ke clipboard
export interface ScreenOrientationResult { /** * The current orientation type. * * @since 1.0.0 */ type: OrientationType;}OrientationLockOptions
Opsi untuk mengunci orientasi layar.Salin ke clipboard
export interface OrientationLockOptions { /** * The orientation type to lock to. * * @since 1.0.0 */ orientation: OrientationLockType;
/** * Whether to track physical device orientation using motion sensors. * When true, uses device motion sensors to detect the true physical * orientation of the device, even when the device orientation lock is enabled. * * **Important:** This does NOT bypass the UI orientation lock. * The screen will still respect the user's orientation lock setting. * This option only affects orientation detection/tracking - you'll receive * orientation change events based on how the device is physically held, * but the UI will not rotate if orientation lock is enabled. * * Supported on iOS (Core Motion) and Android (Accelerometer). * * @default false * @since 1.0.0 */ bypassOrientationLock?: boolean;}StartOrientationTrackingOptions
Judul Bagian “Orientasi Layar”Opsi untuk memulai pengawasan orientasi menggunakan sensor gerakan.
export interface StartOrientationTrackingOptions { /** * Whether to track physical device orientation using motion sensors. * When true, uses device motion sensors to detect the true physical * orientation of the device, even when the device orientation lock is enabled. * * **Important:** This does NOT bypass the UI orientation lock. * This only enables detection of the physical orientation. * * Supported on iOS (Core Motion) and Android (Accelerometer). * * @default false * @since 1.0.0 */ bypassOrientationLock?: boolean;}OrientationLockStatusResult
Bab berjudul “Status Pemutus Orientasi”Hasil yang dikembalikan oleh metode isOrientationLocked().
export interface OrientationLockStatusResult { /** * Whether the device orientation lock is currently enabled. * * This is determined by comparing the physical device orientation * (from motion sensors) with the UI orientation. If they differ, * orientation lock is enabled. * * Available on iOS (Core Motion) and Android (Accelerometer) when motion tracking is active. * * @since 1.0.0 */ locked: boolean;
/** * The physical orientation of the device from motion sensors. * Available when motion tracking is active (iOS and Android). * * @since 1.0.0 */ physicalOrientation?: OrientationType;
/** * The current UI orientation reported by the system. * * @since 1.0.0 */ uiOrientation: OrientationType;}OrientationType
Bab berjudul “Tipe Orientasi”Tipe orientasi yang menjelaskan status orientasi perangkat.
export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';OrientationLockType
Bab berjudul “Tipe Pemutus Orientasi”Tipe pemutus orientasi yang dapat digunakan untuk memutuskan orientasi perangkat.
export type OrientationLockType = | 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';Sumber Kebenaran
Judul Bagian: Sumber KebenaranHalaman ini dibuat dari plugin’s src/definitions.tsRe-run sinkronisasi ketika API publik berubah di atas
Teruskan dari Getting Started
Judul Bagian: Teruskan dari Getting StartedJika Anda menggunakan Getting Started untuk merencanakan perilaku media dan antarmuka asli, hubungkannya dengan Menggunakan @capgo/capacitor-orientasi-layar untuk kemampuan asli di Menggunakan @capgo/capacitor-orientasi-layar, Menggunakan @capgo/capacitor-aktivitas-hidup untuk kemampuan asli di Menggunakan @capgo/capacitor-aktivitas-hidup, @capgo/capacitor-aktivitas-nyata untuk detail implementasi di @capgo/capacitor-aktivitas-nyata, Menggunakan @capgo/capacitor-pemain-video untuk kemampuan asli di Menggunakan @capgo/capacitor-pemain-video, dan @capgo/capacitor-pemain-video untuk detail implementasi di @capgo/capacitor-pemain-video.