37 lines
902 B
TypeScript
37 lines
902 B
TypeScript
import Taro from '@tarojs/taro';
|
|
|
|
import { useRef } from 'react';
|
|
|
|
function useNavigation() {
|
|
const statusBarHeight = useRef(0);
|
|
const barHeight = useRef(0);
|
|
|
|
const systemInfo = Taro.getWindowInfo();
|
|
if (systemInfo.statusBarHeight) {
|
|
statusBarHeight.current = systemInfo.statusBarHeight;
|
|
}
|
|
|
|
// #ifndef MP
|
|
// if (process.env.TARO_ENV !== 'weapp') {
|
|
// barHeight.current = statusBarHeight.current + (systemInfo.platform === 'android' ? 50 : 40);
|
|
// }
|
|
// #endif
|
|
|
|
// #ifdef MP-WEIXIN
|
|
if (process.env.TARO_ENV === 'weapp') {
|
|
const custom = Taro.getMenuButtonBoundingClientRect();
|
|
barHeight.current = custom.bottom + custom.top - statusBarHeight.current;
|
|
}
|
|
// #endif
|
|
// #ifdef MP-ALIPAY
|
|
// barHeight.current = statusBarHeight.current + systemInfo.titleBarHeight!;
|
|
// #endif
|
|
|
|
return {
|
|
barHeight,
|
|
statusBarHeight,
|
|
};
|
|
}
|
|
|
|
export default useNavigation;
|