Commencer
-
Installer the package
Fenêtre de terminal npm i @capgo/home-indicatorFenêtre de terminal pnpm add @capgo/home-indicatorFenêtre de terminal yarn add @capgo/home-indicatorFenêtre de terminal bun add @capgo/home-indicator -
Synchroniser with Natif projects
Fenêtre de terminal npx cap syncFenêtre de terminal pnpm cap syncFenêtre de terminal yarn cap syncFenêtre de terminal bunx cap sync -
Configure the plugin
Hide Home Indicator:
import { HomeIndicator } from '@capgo/home-indicator';// Hide the home indicatorawait HomeIndicator.hide();Show Home Indicator:
// Show the home indicatorawait HomeIndicator.show();// Check visibility statusconst { hidden } = await HomeIndicator.isHidden();console.log('Is hidden:', hidden);No additional Configuration required. The plugin only works on iOS Appareils with a Accueil indicator (iPhone X and later).
This plugin has no effect on Android Appareils as they don’t have an iOS-style Accueil indicator.
-
Auto-hide Configuration
import { HomeIndicator } from '@capgo/home-indicator';// Configure auto-hide behaviorawait HomeIndicator.setAutoHidden({autoHidden: true // Enable auto-hide});// The home indicator will automatically hide after a few seconds// and reappear when the user touches the screen -
Advanced Utilisation
import { HomeIndicator } from '@capgo/home-indicator';import { App } from '@capacitor/app';export class ImmersiveMode {private isImmersive = false;async enterImmersiveMode() {this.isImmersive = true;// Hide home indicatorawait HomeIndicator.hide();// Enable auto-hide for better UXawait HomeIndicator.setAutoHidden({ autoHidden: true });// Hide status bar for full immersion// StatusBar.hide(); // If using @capacitor/status-bar}async exitImmersiveMode() {this.isImmersive = false;// Show home indicatorawait HomeIndicator.show();// Disable auto-hideawait HomeIndicator.setAutoHidden({ autoHidden: false });// Show status bar// StatusBar.show(); // If using @capacitor/status-bar}async toggleImmersiveMode() {const { hidden } = await HomeIndicator.isHidden();if (hidden) {await this.exitImmersiveMode();} else {await this.enterImmersiveMode();}}setupAppLifecycle() {// Handle app state changesApp.addListener('appStateChange', async ({ isActive }) => {if (!isActive && this.isImmersive) {// App went to background, might want to show indicatorawait HomeIndicator.show();} else if (isActive && this.isImmersive) {// App came to foreground, restore immersive modeawait HomeIndicator.hide();}});}}
API Référence
Section titled “API Référence”Methods
Section titled “Methods”hide()
Section titled “hide()”Hide the Accueil indicator.
Returns: Promise<void>
show()
Section titled “show()”Show the Accueil indicator.
Returns: Promise<void>
isHidden()
Section titled “isHidden()”Vérifier if the Accueil indicator is currently hidden.
Returns: Promise<{ hidden: boolean }>
setAutoHidden(options: { autoHidden: boolean })
Section titled “setAutoHidden(options: { autoHidden: boolean })”Configure auto-hide behavior for the Accueil indicator.
Parameters:
options.autoHidden: boolean - Enable or disable auto-hide
Returns: Promise<void>
Interfaces
Section titled “Interfaces”interface AutoHiddenOptions { autoHidden: boolean;}
interface HiddenResult { hidden: boolean;}Platform Notes
Section titled “Platform Notes”- Only works on Appareils with Accueil indicator (iPhone X and later)
- Requires iOS 11.0 or later
- Auto-hide makes the indicator translucent and hides after inactivity
- The indicator reappears when Utilisateurs swipe from the bottom
Android
Section titled “Android”- This plugin has no effect on Android
- Android uses different navigation gestures/buttons
Common Use Cases
Section titled “Common Use Cases”- Games: Full-screen gaming without distractions
- Video Players: Immersive video playback
- Photo Viewers: Full-screen photo galleries
- Presentations: Distraction-free presentations
- Kiosk Apps: Public display applications
Best Practices
Section titled “Best Practices”-
Utilisateur Control: Always provide a way to exit immersive mode
// Add a gesture or button to toggle immersive modeconst toggleButton = document.getElementById('toggle-immersive');toggleButton.addEventListener('click', () => {immersiveMode.toggleImmersiveMode();}); -
Auto-Hide for Games: Use auto-hide for better gaming experience
// For games, auto-hide provides the best balanceawait HomeIndicator.setAutoHidden({ autoHidden: true }); -
Respect System Gestures: Don’t interfere with system navigation
-
Enregistrer State: Remember Utilisateur’s preference for immersive mode
Dépannage
Section titled “Dépannage”Home indicator not hiding:
- Verify the Appareil has a Accueil indicator (iPhone X+)
- Vérifier iOS Version is 11.0 or higher
- Ensure the Application has focus
Auto-hide not working:
- Auto-hide requires Utilisateur interaction to activate
- The indicator becomes translucent, not completely hidden
Indicator reappears unexpectedly:
- This is normal iOS behavior for system gestures
- Use auto-hide for less intrusive behavior