Как убрать / скрыть стрелку назад в Кордове UWP (Ioni c 4)? - PullRequest
0 голосов
/ 24 февраля 2020

В настоящее время я работаю над приложением Ioni c 4 (Angular), доступным для Windows 10 (UWP).

Я хотел бы скрыть стрелку назад:

Показ стрелки назад

Я попробовал эти решения в своем конструкторе app.component с initializeApp (): Как скрыть / удалить Ioni c 4 Cordova Windows 10 Кнопка возврата приложения?

Но ничего не работает, я также пытался использовать в ionViewDidEnter, а также на первой странице моего приложения с 5-секундным таймаутом.

Метод для Windows .core вызывается после того, как все загружено. Мой app.component.ts направляется через вкладки на мою страницу аутентификации.

app.component.ts

    constructor(
...
  ) {
    this.initializeApp();
    this.setLanguageSettings();
  }

  private async initializeApp() {
    await this.platform.ready();
    if (this.platform.is('cordova') && cordova.platformId === 'windows') {
      setTimeout(() => this.hideWindowsTitleBackArrow(), 1000);
    }


  private hideWindowsTitleBackArrow(): void {
    console.log('hiding-first');
    try {
      const w: any = window;
      if (w.cordova.platformId === 'windows') {
        const currentView = w.Windows.UI.Core.SystemNavigationManager.getForCurrentView();
        currentView.AppViewBackButtonVisibility =
          w.Windows.UI.Core.AppViewBackButtonVisibility.collapsed;
      }
    } catch (error) {
      console.error(`Error in hideWindowsTitleBackArrow: ${error}`);
    }
  }

Иони c информация:

ionic info

Ionic:

   Ionic CLI                     : 5.4.6
   Ionic Framework               : @ionic/angular 4.11.8
   @angular-devkit/build-angular : 0.10.7
   @angular-devkit/schematics    : 7.0.7
   @angular/cli                  : 7.0.7
   @ionic/angular-toolkit        : 1.5.1

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : windows 7.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.1, (and 11 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 0.2.9

System:

   NodeJS : v10.15.3 (C:\Tools\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

1 Ответ

0 голосов
/ 25 февраля 2020

Наконец, найдите решение,

Первоначальное решение было правильным, но объяснение исходит от cordova. js код:

     if (navigator.appVersion.indexOf('MSAppHost/3.0') !== -1) { // Windows 10 UWP (PC/Tablet/Phone)
    var navigationManager = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
    // Inject a listener for the backbutton on the document.
    backButtonChannel.onHasSubscribersChange = function () {
        // If we just attached the first handler or detached the last handler,
        // let native know we need to override the back button.
        navigationManager.appViewBackButtonVisibility = (this.numHandlers > 0) ?
            Windows.UI.Core.AppViewBackButtonVisibility.visible :
            Windows.UI.Core.AppViewBackButtonVisibility.collapsed;
    };

Cordova показывает кнопку «Назад» после страницы Подпишись на обратное событие. В случае Ioni c 4 мне нужно реализовать, как в примере, но мне пришлось потратить больше времени, чтобы загрузить мое приложение.

Вот код для реализации в app.component.ts:

initializeApp() {
    this.platform.ready().then(() => {
      if (this.platform.is('cordova')) {
        // Waiting cordova.js to load it to override it after the real loading
        setTimeout(() => {
          this.hideUWPBackButton();
        }, 3000);
      }
    });
  }

  public hideUWPBackButton() {
    try {
      const win: any = window;
      if (cordova.platformId === 'windows') {
        const currentView = win.Windows.UI.Core.SystemNavigationManager.getForCurrentView();
        currentView.appViewBackButtonVisibility =
          win.Windows.UI.Core.AppViewBackButtonVisibility.collapsed;
      }
    } catch (error) {
      console.error(`Error in hideWindowsTitleBackArrow: ${error}`);
    }
  }
...