feat: adapt iPhoneX @rex-zsd (#989)

This commit is contained in:
rex 2018-12-05 17:41:48 +08:00 committed by neverland
parent f97cd506f6
commit 43a9989673
24 changed files with 123 additions and 14 deletions

View File

@ -1,5 +1,5 @@
<demo-block title="基础用法"> <demo-block title="基础用法">
<van-goods-action custom-class="goods-action"> <van-goods-action custom-class="goods-action" safe-area-inset-bottom="{{ false }}">
<van-goods-action-icon <van-goods-action-icon
icon="chat" icon="chat"
text="客服" text="客服"
@ -23,7 +23,7 @@
</demo-block> </demo-block>
<demo-block title="图标提示"> <demo-block title="图标提示">
<van-goods-action custom-class="goods-action"> <van-goods-action custom-class="goods-action" safe-area-inset-bottom="{{ false }}">
<van-goods-action-icon icon="chat" text="客服" /> <van-goods-action-icon icon="chat" text="客服" />
<van-goods-action-icon icon="cart" text="购物车" info="5" /> <van-goods-action-icon icon="cart" text="购物车" info="5" />
<van-goods-action-icon icon="shop" text="店铺" /> <van-goods-action-icon icon="shop" text="店铺" />

View File

@ -4,6 +4,7 @@
button-text="提交订单" button-text="提交订单"
bind:submit="onClickButton" bind:submit="onClickButton"
custom-class="van-submit-bar" custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/> />
</demo-block> </demo-block>
@ -15,6 +16,7 @@
tip="您的收货地址不支持同城送, 我们已为您推荐快递" tip="您的收货地址不支持同城送, 我们已为您推荐快递"
bind:submit="onClickButton" bind:submit="onClickButton"
custom-class="van-submit-bar" custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/> />
</demo-block> </demo-block>
@ -25,6 +27,7 @@
button-text="提交订单" button-text="提交订单"
bind:submit="onClickButton" bind:submit="onClickButton"
custom-class="van-submit-bar" custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/> />
</demo-block> </demo-block>
@ -35,6 +38,7 @@
bind:submit="onClickButton" bind:submit="onClickButton"
custom-class="van-submit-bar" custom-class="van-submit-bar"
tip="{{ true }}" tip="{{ true }}"
safe-area-inset-bottom="{{ false }}"
> >
<van-tag type="primary" custom-class="van-tag">标签</van-tag> <van-tag type="primary" custom-class="van-tag">标签</van-tag>
<view slot="tip"> <view slot="tip">

View File

@ -1,5 +1,5 @@
<demo-block title="基础用法"> <demo-block title="基础用法">
<van-tabbar active="{{ active }}" custom-class="tabbar" bind:change="onChange"> <van-tabbar active="{{ active }}" custom-class="tabbar" bind:change="onChange" safe-area-inset-bottom="{{ false }}">
<van-tabbar-item icon="shop">标签</van-tabbar-item> <van-tabbar-item icon="shop">标签</van-tabbar-item>
<van-tabbar-item icon="chat" dot>标签</van-tabbar-item> <van-tabbar-item icon="chat" dot>标签</van-tabbar-item>
<van-tabbar-item icon="records" info="5">标签</van-tabbar-item> <van-tabbar-item icon="records" info="5">标签</van-tabbar-item>
@ -8,7 +8,7 @@
</demo-block> </demo-block>
<demo-block title="自定义图标"> <demo-block title="自定义图标">
<van-tabbar active="{{ active2 }}" custom-class="tabbar" bind:change="onChange"> <van-tabbar active="{{ active2 }}" custom-class="tabbar" bind:change="onChange" safe-area-inset-bottom="{{ false }}">
<van-tabbar-item> <van-tabbar-item>
<span>自定义</span> <span>自定义</span>
<image slot="icon" src="{{ icon.normal }}" class="icon" mode="aspectFit" /> <image slot="icon" src="{{ icon.normal }}" class="icon" mode="aspectFit" />

View File

@ -88,6 +88,7 @@ Page({
| cancel-text | 取消按钮文字 | `String` | - | | cancel-text | 取消按钮文字 | `String` | - |
| overlay | 是否显示遮罩层 | `Boolean` | - | | overlay | 是否显示遮罩层 | `Boolean` | - |
| close-on-click-overlay | 点击遮罩是否关闭菜单 | `Boolean` | - | | close-on-click-overlay | 点击遮罩是否关闭菜单 | `Boolean` | - |
| safe-area-inset-bottom | 是否适配iPhoneX | `Boolean` | `true` |
### Event ### Event

View File

@ -20,6 +20,10 @@ VantComponent({
closeOnClickOverlay: { closeOnClickOverlay: {
type: Boolean, type: Boolean,
value: true value: true
},
safeAreaInsetBottom: {
type: Boolean,
value: true
} }
}, },

View File

@ -4,6 +4,7 @@
z-index="{{ zIndex }}" z-index="{{ zIndex }}"
overlay="{{ overlay }}" overlay="{{ overlay }}"
custom-class="van-action-sheet" custom-class="van-action-sheet"
safe-area-inset-bottom="{{ safeAreaInsetBottom }}"
close-on-click-overlay="{{ closeOnClickOverlay }}" close-on-click-overlay="{{ closeOnClickOverlay }}"
bind:close="onClose" bind:close="onClose"
> >

View File

@ -55,3 +55,6 @@
@toast-default-padding: 15px; @toast-default-padding: 15px;
@toast-default-width: 90px; @toast-default-width: 90px;
@toast-default-min-height: 90px; @toast-default-min-height: 90px;
// iPhoneX
@safe-area-inset-bottom: 34px;

View File

@ -64,6 +64,12 @@ Page({
</van-goods-action> </van-goods-action>
``` ```
### GoodsAction API
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| safe-area-inset-bottom | 是否适配iPhoneX | `Boolean` | `true` |
### GoodsActionIcon API ### GoodsActionIcon API
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |

View File

@ -1,9 +1,14 @@
@import '../common/style/var.less'; @import '../common/style/var.less';
.van-goods-action { .van-goods-action {
left: 0; position: fixed;
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0;
display: flex; display: flex;
position: fixed; background-color: @white;
&--safe {
padding-bottom: @safe-area-inset-bottom;
}
} }

View File

@ -1,3 +1,19 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent(); VantComponent({
props: {
safeAreaInsetBottom: {
type: Boolean,
value: true
}
},
computed: {
rootClass() {
const { safeAreaInsetBottom, isIPhoneX } = this.data;
return this.classNames('van-goods-action', 'custom-class', {
[`van-goods-action--safe`]: isIPhoneX && safeAreaInsetBottom
});
}
}
});

View File

@ -1,3 +1,3 @@
<view class="van-goods-action custom-class"> <view class="{{ rootClass }}">
<slot /> <slot />
</view> </view>

View File

@ -1,6 +1,21 @@
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.setData({
isIPhoneX: true
});
}
}
});
},
methods: { methods: {
classNames, classNames,

View File

@ -54,6 +54,7 @@ Page({
| custom-style | 自定义弹出层样式 | `String` | `` | | custom-style | 自定义弹出层样式 | `String` | `` |
| overlay-style | 自定义背景蒙层样式 | `String` | `` | | overlay-style | 自定义背景蒙层样式 | `String` | `` |
| close-on-click-overlay | 点击蒙层是否关闭 Popup | `Boolean` | `true` | | close-on-click-overlay | 点击蒙层是否关闭 Popup | `Boolean` | `true` |
| safe-area-inset-bottom | 是否适配iPhoneX | `Boolean` | `true` |
### Event ### Event

View File

@ -44,6 +44,10 @@
bottom: auto; bottom: auto;
left: 0; left: 0;
} }
&--safe {
padding-bottom: @safe-area-inset-bottom;
}
} }
@keyframes van-center-enter { @keyframes van-center-enter {

View File

@ -23,6 +23,20 @@ VantComponent({
position: { position: {
type: String, type: String,
value: 'center' value: 'center'
},
safeAreaInsetBottom: {
type: Boolean,
value: true
}
},
computed: {
popupClass() {
const { position, safeAreaInsetBottom, isIPhoneX } = this.data;
return this.classNames('custom-class', 'van-popup', {
[`van-popup--${position}`]: position,
[`van-popup--safe`]: isIPhoneX && safeAreaInsetBottom && position === 'bottom'
});
} }
}, },

View File

@ -8,7 +8,7 @@
/> />
<view <view
wx:if="{{ inited }}" wx:if="{{ inited }}"
class="custom-class van-popup {{ position ? 'van-popup--' + position : '' }}" class="{{ popupClass }}"
style="z-index: {{ zIndex }}; -webkit-animation: van-{{ transition || position }}-{{ type }} {{ duration }}ms both; animation: van-{{ transition || position }}-{{ type }} {{ duration }}ms both; {{ display ? '' : 'display: none;' }}{{ customStyle }}" style="z-index: {{ zIndex }}; -webkit-animation: van-{{ transition || position }}-{{ type }} {{ duration }}ms both; animation: van-{{ transition || position }}-{{ type }} {{ duration }}ms both; {{ display ? '' : 'display: none;' }}{{ customStyle }}"
bind:animationend="onAnimationEnd" bind:animationend="onAnimationEnd"
> >

View File

@ -74,6 +74,7 @@
| disabled | 是否禁用按钮 | `Boolean` | `false` | | disabled | 是否禁用按钮 | `Boolean` | `false` |
| loading | 是否显示加载中的按钮 | `Boolean` | `false` | | loading | 是否显示加载中的按钮 | `Boolean` | `false` |
| currency | 货币符号 | `String` | `¥` | | currency | 货币符号 | `String` | `¥` |
| safe-area-inset-bottom | 是否适配iPhoneX | `Boolean` | `true` |
### Event ### Event

View File

@ -22,6 +22,10 @@
height: 50px; height: 50px;
background-color: @white; background-color: @white;
font-size: 14px; font-size: 14px;
&--safe {
padding-bottom: @safe-area-inset-bottom;
}
} }
&__text { &__text {

View File

@ -22,6 +22,10 @@ VantComponent({
buttonType: { buttonType: {
type: String, type: String,
value: 'danger' value: 'danger'
},
safeAreaInsetBottom: {
type: Boolean,
value: true
} }
}, },
@ -37,6 +41,13 @@ VantComponent({
tipStr() { tipStr() {
const { tip } = this.data; const { tip } = this.data;
return typeof tip === 'string' ? tip : ''; return typeof tip === 'string' ? tip : '';
},
barClass() {
const { isIPhoneX, safeAreaInsetBottom } = this.data;
return this.classNames('van-submit-bar__bar', 'bar-class', {
'van-submit-bar__bar--safe': safeAreaInsetBottom && isIPhoneX
});
} }
}, },

View File

@ -5,7 +5,7 @@
{{ tipStr }}<slot name="tip" /> {{ tipStr }}<slot name="tip" />
</view> </view>
<view class="van-submit-bar__bar bar-class"> <view class="{{ barClass }}">
<slot /> <slot />
<view class="van-submit-bar__text"> <view class="van-submit-bar__text">
<block wx:if="{{ hasPrice }}"> <block wx:if="{{ hasPrice }}">

View File

@ -75,6 +75,7 @@ Page({
| active | 当前选中标签的索引 | `Number` | - | | active | 当前选中标签的索引 | `Number` | - |
| fixed | 是否固定在底部 | `Boolean` | `true` | | fixed | 是否固定在底部 | `Boolean` | `true` |
| z-index | 元素 z-index | `Number` | `1` | | z-index | 元素 z-index | `Number` | `1` |
| safe-area-inset-bottom | 是否适配iPhoneX | `Boolean` | `true` |
### Tabbar Event ### Tabbar Event

View File

@ -1,14 +1,18 @@
@import '../common/style/var.less'; @import '../common/style/var.less';
.van-tabbar { .van-tabbar {
display: flex;
width: 100%; width: 100%;
height: 50px; height: 50px;
display: flex;
background-color: @white; background-color: @white;
&--fixed { &--fixed {
left: 0;
bottom: 0;
position: fixed; position: fixed;
bottom: 0;
left: 0;
}
&--safe {
padding-bottom: @safe-area-inset-bottom;
} }
} }

View File

@ -27,6 +27,10 @@ VantComponent({
zIndex: { zIndex: {
type: Number, type: Number,
value: 1 value: 1
},
safeAreaInsetBottom: {
type: Boolean,
value: true
} }
}, },
@ -35,6 +39,16 @@ VantComponent({
currentActive: -1 currentActive: -1
}, },
computed: {
tabbarClass() {
const { fixed, isIPhoneX, safeAreaInsetBottom } = this.data;
return this.classNames('custom-class', 'van-tabbar', 'van-hairline--top-bottom', {
'van-tabbar--fixed': fixed,
'van-tabbar--safe': isIPhoneX && safeAreaInsetBottom
});
}
},
watch: { watch: {
active(active) { active(active) {
this.setData({ currentActive: active }); this.setData({ currentActive: active });

View File

@ -1,5 +1,5 @@
<view <view
class="custom-class van-tabbar van-hairline--top-bottom {{ fixed ? 'van-tabbar--fixed' : '' }}" class="{{ tabbarClass }}"
style="{{ zIndex ? 'z-index: ' + zIndex : '' }}" style="{{ zIndex ? 'z-index: ' + zIndex : '' }}"
> >
<slot /> <slot />