Getting Started
此内容尚不支持你的语言。
-
Install the package
Terminal window npm i @capgo/home-indicatorTerminal window pnpm add @capgo/home-indicatorTerminal window yarn add @capgo/home-indicatorTerminal window bun add @capgo/home-indicator -
Sync with native projects
Terminal window npx cap syncTerminal window pnpm cap syncTerminal window yarn cap syncTerminal window 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 setup required. The plugin only works on iOS devices with a home indicator (iPhone X and later).
This plugin has no effect on Android devices as they don’t have an iOS-style home 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 usage
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 Reference
Methods
hide()
Hide the home indicator.
Returns: Promise<void>
show()
Show the home indicator.
Returns: Promise<void>
isHidden()
Check if the home indicator is currently hidden.
Returns: Promise<{ hidden: boolean }>
setAutoHidden(options: { autoHidden: boolean })
Configure auto-hide behavior for the home indicator.
Parameters:
options.autoHidden
: boolean - Enable or disable auto-hide
Returns: Promise<void>
Interfaces
interface AutoHiddenOptions { autoHidden: boolean;}
interface HiddenResult { hidden: boolean;}
Platform Notes
iOS
- Only works on devices with home 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 users swipe from the bottom
Android
- This plugin has no effect on Android
- Android uses different navigation gestures/buttons
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
-
User 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
-
Save State: Remember user’s preference for immersive mode
Troubleshooting
Home indicator not hiding:
- Verify the device has a home indicator (iPhone X+)
- Check iOS version is 11.0 or higher
- Ensure the app has focus
Auto-hide not working:
- Auto-hide requires user 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