capacitor-status-bar-area
v0.0.1
Published
The StatusBar API Provides methods for configuring the style of the Status Bar
Downloads
1
Readme
Capacitor Status Bar Area
Forked from @capacitor/status-bar with additional feature
The StatusBar API Provides methods for getting height, configuring the style of the Status Bar, along with showing or hiding it.
Install
npm install capacitor-status-bar-area
npx cap sync
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
.
setBackgroundColor
and setOverlaysWebView
are currently not supported on
iOS devices.
Example
import { StatusBarArea, Style } from 'capacitor-status-bar-area';
// iOS only
window.addEventListener('statusTap', function () {
console.log('statusbar tapped');
});
// Display content under transparent status bar (Android only)
StatusBarArea.setOverlaysWebView({ overlay: true });
StatusBarArea.getHeight().then((info) => {
document.documentElement.style.setProperty(
'--status-bar-safe-area',
`${info?.height || 24}px`
);
});
const setStatusBarStyleDark = async () => {
await StatusBarArea.setStyle({ style: Style.Dark });
};
const setStatusBarStyleLight = async () => {
await StatusBarArea.setStyle({ style: Style.Light });
};
const hideStatusBar = async () => {
await StatusBarArea.hide();
};
const showStatusBar = async () => {
await StatusBarArea.show();
};
API
setStyle(...)
setBackgroundColor(...)
show(...)
hide(...)
getInfo()
getHeight()
setOverlaysWebView(...)
- Interfaces
- Enums
setStyle(...)
setStyle(options: StyleOptions) => Promise<void>
Set the current style of the status bar.
| Param | Type |
| ------------- | ----------------------------------------------------- |
| options
| StyleOptions |
setBackgroundColor(...)
setBackgroundColor(options: BackgroundColorOptions) => Promise<void>
Set the background color of the status bar.
This method is only supported on Android.
| Param | Type |
| ------------- | ------------------------------------------------------------------------- |
| options
| BackgroundColorOptions |
show(...)
show(options?: AnimationOptions | undefined) => Promise<void>
Show the status bar.
| Param | Type |
| ------------- | ------------------------------------------------------------- |
| options
| AnimationOptions |
hide(...)
hide(options?: AnimationOptions | undefined) => Promise<void>
Hide the status bar.
| Param | Type |
| ------------- | ------------------------------------------------------------- |
| options
| AnimationOptions |
getInfo()
getInfo() => Promise<StatusBarInfo>
Get info about the current state of the status bar.
Returns: Promise<StatusBarInfo>
getHeight()
getHeight() => Promise<StatusBarHeight>
Get the current style of the status bar in pixels.
Returns: Promise<StatusBarHeight>
setOverlaysWebView(...)
setOverlaysWebView(options: SetOverlaysWebViewOptions) => Promise<void>
Set whether or not the status bar should overlay the webview to allow usage of the space underneath it.
This method is only supported on Android.
| Param | Type |
| ------------- | ------------------------------------------------------------------------------- |
| options
| SetOverlaysWebViewOptions |
Interfaces
StyleOptions
| Prop | Type | Description |
| ----------- | --------------------------------------- | --------------------------------------------------------- |
| style
| Style | Style of the text of the status bar. |
BackgroundColorOptions
| Prop | Type | Description |
| ----------- | ------------------- | ------------------------------------------------------------------------------------------- |
| color
| string | A hex color to which the status bar color is set. This option is only supported on Android. |
AnimationOptions
| Prop | Type | Description |
| --------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| animation
| Animation | The type of status bar animation used when showing or hiding. This option is only supported on iOS. |
StatusBarInfo
| Prop | Type | Description |
| -------------- | --------------------------------------- | ----------------------------------------------------------------------------------- |
| height
| number | The height of the status bar (in pixels). |
| visible
| boolean | Whether the status bar is visible or not. |
| style
| Style | The current status bar style. |
| color
| string | The current status bar color. This option is only supported on Android. |
| overlays
| boolean | Whether the statusbar is overlaid or not. This option is only supported on Android. |
StatusBarHeight
| Prop | Type |
| ------------ | ------------------- |
| height
| number |
SetOverlaysWebViewOptions
| Prop | Type | Description |
| ------------- | -------------------- | ----------------------------------------- |
| overlay
| boolean | Whether to overlay the status bar or not. |
Enums
Style
| Members | Value | Description |
| ------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Dark
| 'DARK' | Light text for dark backgrounds. |
| Light
| 'LIGHT' | Dark text for light backgrounds. |
| Default
| 'DEFAULT' | On iOS 13 and newer the style is based on the device appearance. If the device is using Dark mode, the statusbar text will be light. If the device is using Light mode, the statusbar text will be dark. On iOS 12 and older the statusbar text will be dark. On Android the default will be the one the app was launched with. |
Animation
| Members | Value | Description |
| ----------- | -------------------- | --------------------------------- |
| None
| 'NONE' | No animation during show/hide. |
| Slide
| 'SLIDE' | Slide animation during show/hide. |
| Fade
| 'FADE' | Fade animation during show/hide. |