diff --git a/packages/goods-action/index.ts b/packages/goods-action/index.ts index 4a9bf784..4dac3734 100644 --- a/packages/goods-action/index.ts +++ b/packages/goods-action/index.ts @@ -1,6 +1,9 @@ import { VantComponent } from '../common/component'; +import { iphonex } from '../mixins/iphonex'; VantComponent({ + mixins: [iphonex], + props: { safeAreaInsetBottom: { type: Boolean, diff --git a/packages/mixins/basic.ts b/packages/mixins/basic.ts index 9d6f5b21..50ede2fc 100644 --- a/packages/mixins/basic.ts +++ b/packages/mixins/basic.ts @@ -1,21 +1,6 @@ import { classNames } from '../common/class-names'; 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: { classNames, diff --git a/packages/mixins/iphonex.ts b/packages/mixins/iphonex.ts new file mode 100644 index 00000000..c8d9d0ef --- /dev/null +++ b/packages/mixins/iphonex.ts @@ -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 }); + }); + } +}); diff --git a/packages/popup/index.ts b/packages/popup/index.ts index d100fe0b..0db4abb8 100644 --- a/packages/popup/index.ts +++ b/packages/popup/index.ts @@ -1,8 +1,9 @@ import { VantComponent } from '../common/component'; import { transition } from '../mixins/transition'; +import { iphonex } from '../mixins/iphonex'; VantComponent({ - mixins: [transition(false)], + mixins: [transition(false), iphonex], props: { transition: String, diff --git a/packages/submit-bar/index.ts b/packages/submit-bar/index.ts index 8cf54459..4a363b93 100644 --- a/packages/submit-bar/index.ts +++ b/packages/submit-bar/index.ts @@ -1,4 +1,5 @@ import { VantComponent } from '../common/component'; +import { iphonex } from '../mixins/iphonex'; VantComponent({ classes: [ @@ -7,6 +8,8 @@ VantComponent({ 'button-class' ], + mixins: [iphonex], + props: { tip: null, type: Number, diff --git a/packages/tabbar/index.ts b/packages/tabbar/index.ts index ecb766fe..fa628965 100644 --- a/packages/tabbar/index.ts +++ b/packages/tabbar/index.ts @@ -1,4 +1,5 @@ import { VantComponent } from '../common/component'; +import { iphonex } from '../mixins/iphonex'; VantComponent({ relation: { @@ -18,6 +19,8 @@ VantComponent({ } }, + mixins: [iphonex], + props: { active: Number, fixed: {