mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
perf: iPhoneX适配提取到独立behaviors @rex-zsd (#1048)
This commit is contained in:
parent
163d0da836
commit
cd0544e68d
@ -1,6 +1,9 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
|
mixins: [iphonex],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
safeAreaInsetBottom: {
|
safeAreaInsetBottom: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
@ -1,21 +1,6 @@
|
|||||||
import { classNames } from '../common/class-names';
|
import { classNames } from '../common/class-names';
|
||||||
|
|
||||||
export const basic = Behavior({
|
export const basic = Behavior({
|
||||||
created() {
|
|
||||||
wx.getSystemInfo({
|
|
||||||
success: ({ model, screenHeight }) => {
|
|
||||||
const isIphoneX = /iphone x/i.test(model);
|
|
||||||
const isIphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
|
|
||||||
|
|
||||||
if (isIphoneX || isIphoneNew) {
|
|
||||||
this.set({
|
|
||||||
isIPhoneX: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
classNames,
|
classNames,
|
||||||
|
|
||||||
|
27
packages/mixins/iphonex.ts
Normal file
27
packages/mixins/iphonex.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
let isIPhoneX = null;
|
||||||
|
|
||||||
|
function getIsIPhoneX() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (isIPhoneX !== null) {
|
||||||
|
resolve(isIPhoneX);
|
||||||
|
} else {
|
||||||
|
wx.getSystemInfo({
|
||||||
|
success: ({ model, screenHeight }) => {
|
||||||
|
const iphoneX = /iphone x/i.test(model);
|
||||||
|
const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
|
||||||
|
isIPhoneX = iphoneX || iphoneNew;
|
||||||
|
resolve(isIPhoneX);
|
||||||
|
},
|
||||||
|
fail: reject
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const iphonex = Behavior({
|
||||||
|
created() {
|
||||||
|
getIsIPhoneX().then(isIPhoneX => {
|
||||||
|
this.set({ isIPhoneX });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -1,8 +1,9 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { transition } from '../mixins/transition';
|
import { transition } from '../mixins/transition';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
mixins: [transition(false)],
|
mixins: [transition(false), iphonex],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
transition: String,
|
transition: String,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
classes: [
|
classes: [
|
||||||
@ -7,6 +8,8 @@ VantComponent({
|
|||||||
'button-class'
|
'button-class'
|
||||||
],
|
],
|
||||||
|
|
||||||
|
mixins: [iphonex],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
tip: null,
|
tip: null,
|
||||||
type: Number,
|
type: Number,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
relation: {
|
relation: {
|
||||||
@ -18,6 +19,8 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mixins: [iphonex],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
active: Number,
|
active: Number,
|
||||||
fixed: {
|
fixed: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user