import { useState, useEffect } from 'react' import Taro from '@tarojs/taro' /** * 获取可滚动区域高度,替代 calc(100vh - Npx) * 小程序不支持 vh/vw 单位,此 hook 动态计算可用高度 * @param minus 需要减去的高度(rpx 或 px),默认 0 */ export function useScrollHeight(minus: number = 0) { const [height, setHeight] = useState('100vh') useEffect(() => { try { const systemInfo = Taro.getSystemInfoSync() // windowHeight 已经减去了导航栏等系统 UI const available = systemInfo.windowHeight - minus setHeight(`${available}px`) } catch { setHeight('100vh') } }, [minus]) return height }