UNPKG

@mijadesign/mjui-react-taro

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

40 lines (39 loc) 1.38 kB
import Taro, { getEnv } from "@tarojs/taro"; const isObject = (val) => val !== null && typeof val === "object"; const isFunction = (val) => typeof val === "function"; const isPromise = (val) => { return isObject(val) && isFunction(val.then) && isFunction(val.catch); }; function preventDefault(event, isStopPropagation) { if (typeof event.cancelable !== "boolean" || event.cancelable) { event.preventDefault(); } { event.stopPropagation(); } } function getHeaderHeight() { if (getEnv() !== "WEAPP") return 0; const globalData = {}; globalData.systemInfo = Taro.getSystemInfoSync(); if (!globalData.headerBtnPosition) globalData.headerBtnPosition = Taro.getMenuButtonBoundingClientRect(); const statusBarHeight = globalData.systemInfo.statusBarHeight; const headerPosition = globalData.headerBtnPosition; headerPosition.left; const btnPosition = { height: headerPosition.height, width: headerPosition.width, // 胶囊bottom - 胶囊height - 状态栏height (胶囊实际bottom 为距离导航栏底部的长度) bottom: headerPosition.bottom - headerPosition.height - statusBarHeight, right: globalData.systemInfo.windowWidth - headerPosition.right }; const headHeight = headerPosition.bottom + btnPosition.bottom; return headHeight; } export { getHeaderHeight as g, isPromise as i, preventDefault as p };