feat(ios): show splash screen when app pause

This commit is contained in:
Tom Fong 2022-10-21 12:00:17 +08:00
parent 9263e05a2d
commit 01de9b31c9

View file

@ -1,4 +1,7 @@
import { Component } from '@angular/core';
import { App } from '@capacitor/app';
import { SplashScreen } from '@capacitor/splash-screen';
import { Toast } from '@capacitor/toast';
import { Platform } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { EnvService } from './services/env.service';
@ -17,5 +20,29 @@ export class AppComponent {
) {
translate.addLangs(this.env.languages);
translate.setDefaultLang('en');
if (this.platform.is('ios')) {
App.addListener('appStateChange', async ({ isActive }) => {
if (env.isDebugging) {
this.presentToast(`App state changed. Is active?: ${isActive}`, "short", "bottom");
}
if (isActive) {
setTimeout(async () => {
await SplashScreen.hide();
}, 300);
} else {
await SplashScreen.show({
autoHide: false
});
}
});
}
}
async presentToast(msg: string, duration: "short" | "long", pos: "top" | "center" | "bottom") {
await Toast.show({
text: msg,
duration: duration,
position: pos
});
}
}