Index.ets 1.29 KB
import { BottomNavBean } from 'wdBean';
import { BottomNavigationComponent, PageViewModel } from 'wdComponent';
import { BreakpointConstants } from 'wdConstant';
import { BreakpointSystem, Logger } from 'wdKit';

const TAG = 'Index';

@Entry
@Component
struct Index {
  private breakpointSystem: BreakpointSystem = new BreakpointSystem()
  @StorageLink('currentBreakpoint') @Watch('watchCurrentBreakpoint') currentBreakpoint: string = BreakpointConstants.BREAKPOINT_XS;
  @State bottomNavList: BottomNavBean[] = []

  watchCurrentBreakpoint() {
    Logger.info(TAG, `watchCurrentBreakpoint, this.currentBreakpoint: ${this.currentBreakpoint}`);
  }

  build() {
    Column() {
      BottomNavigationComponent({ bottomNavList: this.bottomNavList })
    }
  }

  aboutToAppear() {
    this.breakpointSystem.register()
    let bottomNav = PageViewModel.getBottomNavData(getContext(this))
    if (bottomNav) {
      Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.length}`);
      this.bottomNavList = bottomNav
    }
  }

  aboutToDisappear() {
    this.breakpointSystem.unregister()
    Logger.info(TAG, 'aboutToDisappear');
  }

  onPageShow() {
    Logger.info(TAG, 'onPageShow');
  }

  onPageHide() {
    Logger.info(TAG, 'onPageHide');
  }

  onBackPress() {
    Logger.info(TAG, 'onBackPress');
  }
}