diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 278b5a0..2ec0981 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -29,35 +29,39 @@ const AppPage: React.FC = () => { let restoredResultHandler: PluginListenerHandle; useIonViewDidEnter(() => { - stateChangeHandler = App.addListener( + setListeners(); + + getLaunchUrl(); + }); + + const setListeners = async () => { + stateChangeHandler = await App.addListener( 'appStateChange', (state: AppState) => { console.log('App state changed', state); }, ); - pauseHandler = App.addListener('pause', async () => { + pauseHandler = await App.addListener('pause', async () => { console.log('App paused'); }); - resumeHandler = App.addListener('resume', () => { + resumeHandler = await App.addListener('resume', () => { console.log('App resumed'); }); - urlOpenHandler = App.addListener('appUrlOpen', (data: any) => { + urlOpenHandler = await App.addListener('appUrlOpen', (data: any) => { alert('APP URL OPEN: ' + data.url); }); - restoredResultHandler = App.addListener( + restoredResultHandler = await App.addListener( 'appRestoredResult', (data: any) => { alert('Got restored result'); console.log('Restored result:', data); }, ); - - getLaunchUrl(); - }); + }; const getLaunchUrl = async () => { const ret = await App.getLaunchUrl(); diff --git a/src/pages/Browser.tsx b/src/pages/Browser.tsx index 5396172..b996f9e 100644 --- a/src/pages/Browser.tsx +++ b/src/pages/Browser.tsx @@ -28,7 +28,7 @@ const BrowserPage: React.FC = () => { const autoCloseAfterDelay = async () => { loadedHandler?.remove(); - loadedHandler = Browser.addListener('browserPageLoaded', async () => { + loadedHandler = await Browser.addListener('browserPageLoaded', async () => { await timeout(1000); await Browser.close(); await timeout(200); @@ -37,12 +37,14 @@ const BrowserPage: React.FC = () => { }; useIonViewDidEnter(() => { - finishedHandler = Browser.addListener('browserFinished', async () => { + setListeners(); + }); + const setListeners = async () => { + finishedHandler = await Browser.addListener('browserFinished', async () => { await timeout(200); alert(`You closed the window`); }); - }); - + }; useIonViewDidLeave(() => { finishedHandler?.remove(); loadedHandler?.remove(); diff --git a/src/pages/Keyboard.tsx b/src/pages/Keyboard.tsx index 375c67a..3a822a1 100644 --- a/src/pages/Keyboard.tsx +++ b/src/pages/Keyboard.tsx @@ -23,13 +23,17 @@ const KeyboardPage: React.FC = () => { let scrollEnabled = true; useIonViewDidEnter(() => { - showHandler = Keyboard.addListener('keyboardWillShow', info => { + setListeners(); + }); + + const setListeners = async () => { + showHandler = await Keyboard.addListener('keyboardWillShow', info => { console.log('keyboard show', info); }); - hideHandler = Keyboard.addListener('keyboardWillHide', () => { + hideHandler = await Keyboard.addListener('keyboardWillHide', () => { console.log('keyboard hide'); }); - }); + }; useIonViewDidLeave(() => { hideHandler.remove(); diff --git a/src/pages/Network.tsx b/src/pages/Network.tsx index 48cbc15..2b5a575 100644 --- a/src/pages/Network.tsx +++ b/src/pages/Network.tsx @@ -33,7 +33,11 @@ class NetworkPage extends React.Component<{}, NetworkPageState> { ionViewDidEnter() { this.updateNetworkStatus(); - const handler = Network?.addListener( + this.setListeners(); + } + + setListeners = async () => { + const handler = await Network?.addListener( 'networkStatusChange', (status: ConnectionStatus) => { this.setState({ @@ -42,7 +46,7 @@ class NetworkPage extends React.Component<{}, NetworkPageState> { }, ); this.setState({ handler: handler }); - } + }; ionViewDidLeave() { this.state.handler?.remove(); diff --git a/src/pages/ScreenReader.tsx b/src/pages/ScreenReader.tsx index cf486a8..d32c821 100644 --- a/src/pages/ScreenReader.tsx +++ b/src/pages/ScreenReader.tsx @@ -24,10 +24,14 @@ const ScreenReaderPage: React.FC = () => { const [sentence, setSentence] = useState('Hello World?'); useIonViewDidEnter(() => { - handler = ScreenReader.addListener('stateChange', ({ value }: any) => + setListeners(); + }); + + const setListeners = async () => { + handler = await ScreenReader.addListener('stateChange', ({ value }: any) => alert(`State Change! Screen Reader on? ${value}`), ); - }); + }; useIonViewDidLeave(() => { handler.remove();