mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
48 lines
1015 B
TypeScript
48 lines
1015 B
TypeScript
let cache = null;
|
|
|
|
function getSafeArea() {
|
|
return new Promise((resolve, reject) => {
|
|
if (cache != null) {
|
|
resolve(cache);
|
|
} else {
|
|
wx.getSystemInfo({
|
|
success: ({ model, statusBarHeight }) => {
|
|
const deviceType = model.replace(/\s/g, '-');
|
|
const iphoneNew = /iphone-x|iPhone11|iPhone12|iPhone13/i.test(deviceType);
|
|
|
|
cache = {
|
|
isIPhoneX: iphoneNew,
|
|
statusBarHeight
|
|
};
|
|
|
|
resolve(cache);
|
|
},
|
|
fail: reject
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
export const safeArea = ({
|
|
safeAreaInsetBottom = true,
|
|
safeAreaInsetTop = false
|
|
} = {}) =>
|
|
Behavior({
|
|
properties: {
|
|
safeAreaInsetTop: {
|
|
type: Boolean,
|
|
value: safeAreaInsetTop
|
|
},
|
|
safeAreaInsetBottom: {
|
|
type: Boolean,
|
|
value: safeAreaInsetBottom
|
|
}
|
|
},
|
|
|
|
created() {
|
|
getSafeArea().then(({ isIPhoneX, statusBarHeight }) => {
|
|
this.set({ isIPhoneX, statusBarHeight });
|
|
});
|
|
}
|
|
});
|