feat: 适配 headerbar ios26
This commit is contained in:
32
hooks/useSafeAreaWithPadding.ts
Normal file
32
hooks/useSafeAreaWithPadding.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
|
||||
/**
|
||||
* 获取安全区域距离并添加额外间距的 hook
|
||||
* @param extraPadding 额外的间距对象,默认所有方向都是 0
|
||||
* @returns 包含所有方向安全区域距离加上额外间距的对象
|
||||
*/
|
||||
export const useSafeAreaWithPadding = (extraPadding: {
|
||||
top?: number;
|
||||
bottom?: number;
|
||||
left?: number;
|
||||
right?: number;
|
||||
} = {}) => {
|
||||
const insets = useSafeAreaInsets();
|
||||
|
||||
return {
|
||||
top: insets.top + (extraPadding.top || 40),
|
||||
bottom: insets.bottom + (extraPadding.bottom || 0),
|
||||
left: insets.left + (extraPadding.left || 0),
|
||||
right: insets.right + (extraPadding.right || 0),
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取安全区域顶部距离的 hook
|
||||
* @param extraPadding 额外的间距,默认为 20 像素
|
||||
* @returns 顶部安全区域距离加上额外间距的总值
|
||||
*/
|
||||
export const useSafeAreaTop = (extraPadding: number = 50) => {
|
||||
const insets = useSafeAreaInsets();
|
||||
return insets.top + extraPadding;
|
||||
};
|
||||
Reference in New Issue
Block a user