标签页未隐藏在Ionic 5的子页面上

问题描述 投票:0回答:1

在Ionic 4或5中,选项卡栏未隐藏在子页面上。当然,它在离子2或离子3中效果很好。请让我知道如何解决此问题。

ionic-framework hide tabbar
1个回答
0
投票

这是我的解决方案。但希望是最好的解决方案。

  1. 创建TabsService
  2. 将其导入app.module.ts这是TabsService
  3. 的完整代码
import { Injectable } from '@angular/core';
import { filter } from 'rxjs/operators';
import { NavigationEnd, Router } from '@angular/router';
import { Platform } from '@ionic/angular';

@Injectable({
  providedIn: 'root'
})
export class TabsService {
  constructor(private router: Router, private platform: Platform) {
    this.platform.ready().then(() => {
      this.navEvents();
    });
  }

  public hideTabs() {
    const tabBar = document.getElementById('kidesiaTabBar');
    if (tabBar && tabBar.style.display !== 'none') {
      tabBar.style.display = 'none';
    }
  }

  public showTabs() {
    const tabBar = document.getElementById('kidesiaTabBar');
    if (tabBar && tabBar.style.display !== 'flex') {
      tabBar.style.display = 'flex';
    }
  }

  private navEvents() {
    this.router.events
      .pipe(filter(e => e instanceof NavigationEnd))
      .subscribe((e: any) => {
        this.showHideTabs(e);
      });
  }

  private showHideTabs(e: any) {
    const urlArray = e.url.split('/');
    if (urlArray.length >= 3) {
      let shouldHide = true;
      if (urlArray.length === 3 && urlArray[1] === 'tabs') {
        shouldHide = false;
      }
      try {
        setTimeout(() => (shouldHide ? this.hideTabs() : this.showTabs()), 300);
      } catch (err) {}
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.