You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
let cache = null;
|
|
function getSafeArea() {
|
|
return new Promise((resolve, reject) => {
|
|
if (cache != null) {
|
|
resolve(cache);
|
|
}
|
|
else {
|
|
wx.getSystemInfo({
|
|
success: ({ model, screenHeight, statusBarHeight }) => {
|
|
const iphoneX = /iphone x/i.test(model);
|
|
const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
|
|
cache = {
|
|
isIPhoneX: iphoneX || 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 });
|
|
});
|
|
}
|
|
});
|