import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styles: []
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar
  ) {
    this.initializeApp();
    this.initEvent();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }

  initEvent() {
    window.addEventListener('orientationchange', function (e) {
      console.log(e);
      if (window.orientation === 180 || window.orientation === 0) {
        console.log('竖屏');
        window.location.reload();
      } else if (window.orientation === 90 || window.orientation === -90) {
        console.log('横屏');
        window.location.reload();
      }
    });
  }
}
