【问题标题】:How remove/hide back arrow in Cordova UWP (Ionic 4)?如何在 Cordova UWP(Ionic 4)中删除/隐藏后退箭头?
【发布时间】:2020-02-25 23:00:44
【问题描述】:

我目前正在开发适用于 Windows 10 (UWP) 的 Ionic 4 应用程序 (Angular)。

我想隐藏箭头:

Showing arrow back

我尝试了这些解决方案,在我的 app.component 构造函数中使用 initializeApp() :How to hide/remove Ionic 4 Cordova Windows 10 app back button?

但没有任何效果,我也尝试在 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}`);
    }
  }

离子信息:

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

【问题讨论】:

    标签: angular cordova ionic-framework uwp ionic4


    【解决方案1】:

    终于找到解决办法了,

    最初的解决方案是对的,但解释来自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 在页面订阅后退事件后显示后退按钮。在 Ionic 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}`);
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多