UNPKG

tdesign-miniprogram

Version:
1 lines 2.25 kB
import{__decorate}from"tslib";import{wxComponent,SuperComponent}from"../common/src/index";import config from"../common/config";import props from"./props";import{getRect}from"../common/utils";import{getWindowInfo}from"../common/wechat";const{prefix:prefix}=config,classPrefix=`${prefix}-tab-bar`;function getSafeAreaBottom(){try{const e=getWindowInfo();if(e&&e.safeArea&&"number"==typeof e.screenHeight)return Math.max(0,e.screenHeight-e.safeArea.bottom)}catch(e){}return 0}let Tabbar=class extends SuperComponent{constructor(){super(...arguments),this.relations={"../tab-bar-item/tab-bar-item":{type:"descendant"}},this.externalClasses=[`${prefix}-class`],this.backupValue=-1,this.data={prefix:prefix,classPrefix:classPrefix,placeholderHeight:56,safeAreaBottomHeight:0,safeAreaBottomReady:!1},this.properties=props,this.controlledProps=[{key:"value",event:"change"}],this.observers={value(){this.updateChildren()},"fixed, placeholder, shape, safeAreaInsetBottom"(){this.setPlaceholderHeight()},safeAreaInsetBottom(){this.setSafeAreaBottomHeight()}},this.lifetimes={ready(){this.showChildren(),this.setSafeAreaBottomHeight()}},this.methods={setSafeAreaBottomHeight(){this.properties.safeAreaInsetBottom?wx.nextTick(()=>{const e=getSafeAreaBottom();this.setData({safeAreaBottomHeight:e,safeAreaBottomReady:!0},()=>{this.setPlaceholderHeight()})}):(this.data.safeAreaBottomReady||0!==this.data.safeAreaBottomHeight)&&this.setData({safeAreaBottomHeight:0,safeAreaBottomReady:!1})},setPlaceholderHeight(){this.properties.fixed&&this.properties.placeholder&&wx.nextTick(()=>{getRect(this,`.${classPrefix}`).then(e=>{let{height:t}=e;"round"===this.properties.shape&&this.properties.safeAreaInsetBottom&&(t+=getSafeAreaBottom()),this.setData({placeholderHeight:t})})})},showChildren(){const{value:e}=this.data;this.$children.forEach(t=>{t.setData({crowded:this.$children.length>3}),t.properties.value===e&&t.showSpread()})},updateChildren(){const{value:e}=this.data;this.$children.forEach(t=>{t.checkActive(e)})},updateValue(e){this._trigger("change",{value:e})},changeOtherSpread(e){this.$children.forEach(t=>{t.properties.value!==e&&t.closeSpread()})},initName(){return this.backupValue+=1}}}};Tabbar=__decorate([wxComponent()],Tabbar);export default Tabbar;