Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion src/pages/SystemBars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,71 @@
IonButtons,
IonContent,
IonHeader,
IonItem,
IonLabel,
IonList,
IonListHeader,
IonPage,
IonMenuButton,
IonTitle,
IonToolbar,
} from '@ionic/react';
import React from 'react';
import React, { useEffect, useState } from 'react';
import { SystemBars, SystemBarsStyle, SystemBarType } from '@capacitor/core';

const SystemBarsPage: React.FC = () => {
const [log, setLog] = useState<string[]>([]);
const [statusTapCount, setStatusTapCount] = useState(0);

const addLog = (message: string) => {
setLog(previous => [`${new Date().toISOString()} ${message}`, ...previous]);
};

useEffect(() => {
const handle = SystemBars.addListener('statusTap', () => {

Check failure on line 27 in src/pages/SystemBars.tsx

View workflow job for this annotation

GitHub Actions / Build Web

Property 'addListener' does not exist on type 'SystemBarsPlugin'.
setStatusTapCount(count => count + 1);
addLog('statusTap (plugin listener)');
});

return () => {
handle.then(h => h.remove());

Check failure on line 33 in src/pages/SystemBars.tsx

View workflow job for this annotation

GitHub Actions / Build Web

Parameter 'h' implicitly has an 'any' type.
};
}, []);

const getStyle = async (bar: SystemBarType) => {
try {
const result = await SystemBars.getStyle({ bar });

Check failure on line 39 in src/pages/SystemBars.tsx

View workflow job for this annotation

GitHub Actions / Build Web

Property 'getStyle' does not exist on type 'SystemBarsPlugin'. Did you mean 'setStyle'?
addLog(`getStyle(${bar}) -> ${result.style}`);
} catch (e) {
addLog(`getStyle(${bar}) failed: ${(e as Error).message}`);
}
};

const removeAllListeners = async () => {
await SystemBars.removeAllListeners();

Check failure on line 47 in src/pages/SystemBars.tsx

View workflow job for this annotation

GitHub Actions / Build Web

Property 'removeAllListeners' does not exist on type 'SystemBarsPlugin'.
addLog('removeAllListeners() called');
};

const setSystemBarStyleDefault = async () => {
SystemBars.setStyle({
style: SystemBarsStyle.Default,
});
};

const setStatusBarStyleDefault = async () => {
await SystemBars.setStyle({
style: SystemBarsStyle.Default,
bar: SystemBarType.StatusBar,
});
};

const setNavigationBarStyleDefault = async () => {
await SystemBars.setStyle({
style: SystemBarsStyle.Default,
bar: SystemBarType.NavigationBar,
});
};

const setSystemBarStyleLight = async () => {
await SystemBars.setStyle({ style: SystemBarsStyle.Light });
};
Expand Down Expand Up @@ -60,6 +110,12 @@
<IonButton expand="block" onClick={setSystemBarStyleDark}>
Change System Bars Style Dark
</IonButton>
<IonButton expand="block" onClick={setStatusBarStyleDefault}>
Change Status Bar Style Default
</IonButton>
<IonButton expand="block" onClick={setNavigationBarStyleDefault}>
Change Navigation Bar Style Default
</IonButton>
<IonButton expand="block" onClick={showSystemBars}>
Show System Bars
</IonButton>
Expand All @@ -69,6 +125,29 @@
<IonButton expand="block" onClick={hideNavigationBar}>
Hide Navigation Bar
</IonButton>
<IonButton
expand="block"
onClick={() => getStyle(SystemBarType.StatusBar)}
>
Get Style (StatusBar)
</IonButton>
<IonButton
expand="block"
onClick={() => getStyle(SystemBarType.NavigationBar)}
>
Get Style (NavigationBar)
</IonButton>
<IonButton expand="block" onClick={removeAllListeners}>
Remove All Listeners
</IonButton>
<IonList>
<IonListHeader>Status tap count: {statusTapCount}</IonListHeader>
{log.map(entry => (
<IonItem key={entry}>
<IonLabel className="ion-text-wrap">{entry}</IonLabel>
</IonItem>
))}
</IonList>
</IonContent>
</IonPage>
);
Expand Down
Loading