SystemBars
The SystemBars API provides methods for configuring the style and visibility of the device System Bars / Status Bar. This plugin is bundled with @capacitor/core.
This API differs from the Status Bar plugin in that it is only intended to support modern edge to edge use cases moving forward. For legacy functionality, use the Status Bar plugin.
| Feature | System Bars | Status Bar |
|---|---|---|
setOverlaysWebView() | Unsupported | Supported on iOS and Android <= 14 (or 15 if edge to edge opt-out is enabled) |
setBackgroundColor() | Unsupported | Supported |
setStyle() | Supported | Supported - top Status Bar only |
hide()/show() | Supported | Supported - top Status Bar only |
iOS Note
This plugin requires "View controller-based status bar appearance"
(UIViewControllerBasedStatusBarAppearance) set to YES in Info.plist. Read
about Configuring iOS for
help.
The status bar visibility defaults to visible and the style defaults to
Style.Default. You can change these defaults by adding
UIStatusBarHidden and/or UIStatusBarStyle in Info.plist.
Android Note
一部の古い Android WebView(140 未満)には不具合があり、CSS の safe-area-inset-x 環境変数(env)で正しいセーフエリアの値を取得できません。このプラグインは2つの回避方法を用意しており、insetsHandling で切り替えられます。
insetsHandling が disable でない場合、アプリの BridgeActivity.onCreate で EdgeToEdge.enable(this); を呼び出すことも検討してください。Capacitor 9 以降は insetsHandling のデフォルトが native となり、この呼び出しが自動で行われます。
Example
import { SystemBars, SystemBarsStyle, SystemBarType } from '@capacitor/core';
const setSystemBarStyleDark = async () => {
await SystemBars.setStyle({ style: SystemBarsStyle.Dark });
};
const setSystemBarStyleLight = async () => {
await SystemBars.setStyle({ style: SystemBarsStyle.Light });
};
const hideSystemBars = async () => {
await SystemBars.hide();
};
const showSystemBars = async () => {
await SystemBars.show();
};
const hideNavigationBar = async () => {
await SystemBars.hide({
bar: SystemBarType.NavigationBar
})
}
// Set the Status Bar animation, only on iOS
const setStatusBarAnimation = async () => {
await SystemBars.setAnimation({ animation: "NONE" });
}
Configuration
| Prop | Type | Description | Default |
|---|---|---|---|
insetsHandling | string | Android のセーフエリアのインセットの処理方法を指定します。 Android 専用です。 native(推奨): Chromium 140 未満では WebView にパディングを設け、env(safe-area-inset-*) を 0px に設定します。140 以降では WebView が viewport-fit メタタグに従います。viewport-fit="cover" の場合は画面の端まで表示され、env(safe-area-inset-*) に正しい値が入ります。たとえば、この値をパディングに使って表示を調整できます。css: native と同様の処理に加え、正しいセーフエリアのインセットを持つ CSS 変数(--safe-area-inset-*)を WebView に注入します。disable(非推奨): セーフエリアのインセット処理を完全に無効にします。この場合、アプリのコードでインセットを処理する必要があります。 ネイティブコードと WebView のコンテンツでセーフエリアを正しく処理しないと、表示が崩れる場合があります。 | css |
initialViewportFitValueHint | string | 検出対象のメタタグ viewport-fit= に初期値を設定します。エッ ジツーエッジに対応する多くのアプリでは、最終的な値は cover です。初期値を cover にすると、レイアウトのずれやちらつきを抑えられます。起動時から cover になることが分かっている場合は、ここで指定してください。ここで指定した値にかかわらず、最終的には検出された正しい値が使われます。 そのためには insetsHandling が native または css である必要があります。この初期値はレイアウトのずれやちらつきを抑えるためだけに使われます。 Android 専用のオプションです。 | undefined |
style | string | The style of the text and icons of the system bars. | DEFAULT |
hidden | boolean | Hide the system bars on start. | false |
animation | string | The type of status bar animation used when showing or hiding. This option is only supported on iOS. | FADE |
Example Configuration
In capacitor.config.json:
{
"plugins": {
"SystemBars": {
"insetsHandling": "css",
"style": "DARK",
"hidden": false,
"animation": "NONE"
}
}
}
In capacitor.config.ts:
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
plugins: {
SystemBars: {
insetsHandling: "css",
style: "DARK",
hidden: false,
animation: "NONE"
},
},
};
export default config;
API
setStyle(...)
setStyle(options: SystemBarsStyleOptions) => Promise<void>
Set the current style of the system bars.
| Param | Type |
|---|---|
options | |
Since: 8.0.0
show(...)
show(options?: SystemBarsVisibilityOptions) => Promise<void>
Show the system bars.
| Param | Type |
|---|---|
options | |
Since: 8.0.0
hide(...)
hide(options?: SystemBarsVisibilityOptions) => Promise<void>
Hide the system bars.
| Param | Type |
|---|---|
options | |
Since: 8.0.0
setAnimation(...)
setAnimation(options: SystemBarsAnimationOptions) => Promise<void>
Set the animation to use when showing / hiding the status bar.
Only available on iOS.
| Param | Type |
|---|---|
options | |
Since: 8.0.0
Interfaces
SystemBarsStyleOptions
| Prop | Type | Description | Default | Since |
|---|---|---|---|---|
style | | Style of the text and icons of the system bars. | 'DEFAULT' | 8.0.0 |
bar | | The system bar to which to apply the style. | null | 8.0.0 |
SystemBarsVisibilityOptions
| Prop | Type | Description | Default | Since |
|---|---|---|---|---|
bar | | The system bar to hide or show. | null | 8.0.0 |
animation | | The type of status bar animation used when showing or hiding. This option is only supported on iOS. | 'FADE' | 8.0.0 |
SystemBarsAnimationOptions
| Prop | Type | Description | Default | Since |
|---|---|---|---|---|
animation | | The type of status bar animation used when showing or hiding. This option is only supported on iOS. | 'FADE' | 8.0.0 |
Type Aliases
SystemBarsAnimation
Available status bar animations. iOS only.
'FADE' | 'NONE'
Enums
SystemBarsStyle
| Members | Value | Description | Since |
|---|---|---|---|
Dark | 'DARK' | Light system bar content on a dark background. | 8.0.0 |
Light | 'LIGHT' | For dark system bar content on a light background. | 8.0.0 |
Default | 'DEFAULT' | The style is based on the device appearance or the underlying content. If the device is using Dark mode, the system bars content will be light. If the device is using Light mode, the system bars content will be dark. | 8.0.0 |
SystemBarType
| Members | Value | Description | Since |
|---|---|---|---|
StatusBar | 'StatusBar' | The top status bar on both Android and iOS. | 8.0.0 |
NavigationBar | 'NavigationBar' | The navigation bar (or gesture bar on iOS) on both Android and iOS. | 8.0.0 |