From cd0544e68d89c5eeffcf9e3be0b97250dfdd5628 Mon Sep 17 00:00:00 2001 From: rex Date: Tue, 11 Dec 2018 14:55:34 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20iPhoneX=E9=80=82=E9=85=8D=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E7=8B=AC=E7=AB=8Bbehaviors=20@rex-zsd=20(#10?= =?UTF-8?q?48)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/goods-action/index.ts | 3 +++ packages/mixins/basic.ts | 15 --------------- packages/mixins/iphonex.ts | 27 +++++++++++++++++++++++++++ packages/popup/index.ts | 3 ++- packages/submit-bar/index.ts | 3 +++ packages/tabbar/index.ts | 3 +++ 6 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 packages/mixins/iphonex.ts 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: {