[new feature]: support safe-area-inset-top

#1327
This commit is contained in:
rex 2019-04-01 18:46:53 +08:00 committed by GitHub
parent 48596b6e35
commit f95cad50ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 141 additions and 96 deletions

View File

@ -11,7 +11,12 @@ Page({
duration: 1000, duration: 1000,
text: '通知内容', text: '通知内容',
selector: '#custom-selector', selector: '#custom-selector',
backgroundColor: '#1989fa' backgroundColor: '#1989fa',
safeAreaInsetTop: true
}); });
},
onClickLeft() {
wx.navigateBack();
} }
}); });

View File

@ -1,3 +1,4 @@
{ {
"navigationBarTitleText": "Notify 消息通知" "navigationBarTitleText": "Notify 消息通知",
"navigationStyle": "custom"
} }

View File

@ -1,3 +1,10 @@
<van-nav-bar
title="Notify 消息通知"
left-text="返回"
left-arrow
bind:click-left="onClickLeft"
/>
<demo-block padding title="基础用法"> <demo-block padding title="基础用法">
<van-button bind:click="showNotify">显示消息通知</van-button> <van-button bind:click="showNotify">显示消息通知</van-button>
</demo-block> </demo-block>
@ -6,6 +13,5 @@
<van-button bind:click="showNotify2">显示自定义消息通知</van-button> <van-button bind:click="showNotify2">显示自定义消息通知</van-button>
</demo-block> </demo-block>
<van-notify id="van-notify" /> <van-notify id="van-notify" safe-area-inset-top />
<van-notify id="custom-selector" /> <van-notify id="custom-selector" />

View File

@ -41,5 +41,9 @@ Page({
setTimeout(() => { setTimeout(() => {
this.toggle('top'); this.toggle('top');
}, 2000); }, 2000);
},
onClickLeft() {
wx.navigateBack();
} }
}); });

View File

@ -1,3 +1,4 @@
{ {
"navigationBarTitleText": "Popup 弹出层" "navigationBarTitleText": "Popup 弹出层",
"navigationStyle": "custom"
} }

View File

@ -1,3 +1,10 @@
<van-nav-bar
title="Popup 弹出层"
left-text="返回"
left-arrow
bind:click-left="onClickLeft"
/>
<demo-block title="基础用法" padding> <demo-block title="基础用法" padding>
<van-button bind:click="togglePopup">弹出 Popup</van-button> <van-button bind:click="togglePopup">弹出 Popup</van-button>
<van-popup <van-popup
@ -28,6 +35,7 @@
<van-popup <van-popup
show="{{ show.top }}" show="{{ show.top }}"
position="top" position="top"
safe-area-inset-top
overlay="{{ false }}" overlay="{{ false }}"
custom-class="top" custom-class="top"
bind:close="toggleTopPopup" bind:close="toggleTopPopup"
@ -40,6 +48,7 @@
<van-popup <van-popup
show="{{ show.right }}" show="{{ show.right }}"
position="right" position="right"
safe-area-inset-top
custom-class="right" custom-class="right"
bind:close="toggleRightPopup" bind:close="toggleRightPopup"
bind:transitionEnd="onTransitionEnd" bind:transitionEnd="onTransitionEnd"
@ -50,6 +59,7 @@
<van-popup <van-popup
show="{{ show.right2 }}" show="{{ show.right2 }}"
position="right" position="right"
safe-area-inset-top
custom-class="right" custom-class="right"
bind:close="toggleRightPopup2" bind:close="toggleRightPopup2"
bind:transitionEnd="onTransitionEnd" bind:transitionEnd="onTransitionEnd"

View File

@ -88,7 +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` | | safe-area-inset-bottom | 是否为iPhoneX留出底部安全距离 | `Boolean` | `true` |
### Event ### Event
@ -110,14 +110,3 @@ Page({
| disabled | 是否为禁用状态 | | disabled | 是否为禁用状态 |
| className | 为对应列添加额外的 class 类名 | | className | 为对应列添加额外的 class 类名 |
| openType | 微信开放能力,具体支持可参考 [微信官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/component/button.html) | | openType | 微信开放能力,具体支持可参考 [微信官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/component/button.html) |
### 更新日志
| 版本 | 类型 | 内容 |
|-----------|-----------|-----------|
| 0.0.1 | feature | 新增组件 |
| 0.3.0 | breaking change | 由 Actionsheet 重命名为 ActionSheet |
| 0.3.0 | feature | 支持微信开放能力 |
| 0.3.0 | bugfix | 修复 subname 属性不生效的问题 |
| 0.3.3 | feature | 新增 z-index 属性 |
| 0.3.4 | bugfix | 修复边框缺失的问题 |

View File

@ -1,8 +1,8 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { iphonex } from '../mixins/iphonex'; import { safeArea } from '../mixins/safe-area';
VantComponent({ VantComponent({
mixins: [iphonex], mixins: [safeArea()],
props: { props: {
show: Boolean, show: Boolean,

View File

@ -118,3 +118,6 @@
@stepper-button-disabled-color: #f7f8fa; @stepper-button-disabled-color: #f7f8fa;
@stepper-input-disabled-color: @active-color; @stepper-input-disabled-color: @active-color;
@stepper-border-radius: 4px; @stepper-border-radius: 4px;
// NavBar
@nav-bar-height: 44px;

View File

@ -68,7 +68,7 @@ Page({
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------| |-----------|-----------|-----------|-------------|
| safe-area-inset-bottom | 是否适配iPhoneX | `Boolean` | `true` | | safe-area-inset-bottom | 是否为iPhoneX留出底部安全距离 | `Boolean` | `true` |
### GoodsActionIcon API ### GoodsActionIcon API

View File

@ -1,6 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { iphonex } from '../mixins/iphonex'; import { safeArea } from '../mixins/safe-area';
VantComponent({ VantComponent({
mixins: [iphonex] mixins: [safeArea()]
}); });

View File

@ -1,34 +0,0 @@
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({
properties: {
safeAreaInsetBottom: {
type: Boolean,
value: true
}
},
created() {
getIsIPhoneX().then(isIPhoneX => {
this.set({ isIPhoneX });
});
}
});

View File

@ -0,0 +1,47 @@
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 });
});
}
});

View File

@ -56,6 +56,7 @@ Page({
| fixed | 是否固定在顶部 | `Boolean` | `false` | | fixed | 是否固定在顶部 | `Boolean` | `false` |
| border | 是否显示下边框 | `Boolean` | `true` | | border | 是否显示下边框 | `Boolean` | `true` |
| z-index | 元素 z-index | `Number` | `1` | | z-index | 元素 z-index | `Number` | `1` |
| safe-area-inset-top | 是否留出顶部安全距离(状态栏高度) | `Boolean` | `true` |
### Slot ### Slot
@ -78,9 +79,3 @@ Page({
|-----------|-----------| |-----------|-----------|
| custom-class | 根节点样式类 | | custom-class | 根节点样式类 |
| title-class | 标题样式类 | | title-class | 标题样式类 |
### 更新日志
| 版本 | 类型 | 内容 |
|-----------|-----------|-----------|
| 0.0.1 | feature | 新增组件 |

View File

@ -2,8 +2,8 @@
.van-nav-bar { .van-nav-bar {
position: relative; position: relative;
height: 46px; height: @nav-bar-height;
line-height: 46px; line-height: @nav-bar-height;
text-align: center; text-align: center;
background-color: @white; background-color: @white;
user-select: none; user-select: none;

View File

@ -1,6 +1,9 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { safeArea } from '../mixins/safe-area';
VantComponent({ VantComponent({
mixins: [safeArea({ safeAreaInsetTop: true })],
classes: ['title-class'], classes: ['title-class'],
props: { props: {
@ -15,7 +18,7 @@ VantComponent({
}, },
zIndex: { zIndex: {
type: Number, type: Number,
value: 1 value: 120
} }
}, },

View File

@ -1,6 +1,8 @@
<wxs src="../wxs/utils.wxs" module="utils" />
<view <view
class="custom-class van-nav-bar {{ border ? 'van-hairline--bottom' : '' }} {{ fixed ? 'van-nav-bar--fixed' : '' }}" class="{{ utils.bem('nav-bar', { fixed }) }} custom-class {{ border ? 'van-hairline--bottom' : '' }}"
style="z-index: {{ zIndex }}" style="z-index: {{ zIndex }}; {{ safeAreaInsetTop ? 'padding-top: ' + statusBarHeight + 'px;' : '' }}"
> >
<view class="van-nav-bar__left" bind:tap="onClickLeft"> <view class="van-nav-bar__left" bind:tap="onClickLeft">
<block wx:if="{{ leftArrow || leftText }}"> <block wx:if="{{ leftArrow || leftText }}">

View File

@ -49,9 +49,4 @@ Notify({
| color | 字体颜色 | `String` | `#fff` | | | color | 字体颜色 | `String` | `#fff` | |
| backgroundColor | 背景色 | `String` | `#f44` | | backgroundColor | 背景色 | `String` | `#f44` |
| context | 选择器的选择范围,可以传入自定义组件的 this 作为上下文 | `Object` | 当前页面 | | context | 选择器的选择范围,可以传入自定义组件的 this 作为上下文 | `Object` | 当前页面 |
| safe-area-inset-top | 是否留出顶部安全距离(状态栏高度 + 导航栏高度) | `Boolean` | `false` |
### 更新日志
| 版本 | 类型 | 内容 |
|-----------|-----------|-----------|
| 0.0.1 | feature | 新增组件 |

View File

@ -11,4 +11,8 @@
text-align: center; text-align: center;
word-break: break-all; word-break: break-all;
box-sizing: border-box; box-sizing: border-box;
&__safe-top {
height: @nav-bar-height;
}
} }

View File

@ -1,7 +1,10 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { RED } from '../common/color'; import { RED } from '../common/color';
import { safeArea } from '../mixins/safe-area';
VantComponent({ VantComponent({
mixins: [safeArea()],
props: { props: {
text: String, text: String,
color: { color: {

View File

@ -2,7 +2,8 @@
name="slide-down" name="slide-down"
show="{{ show }}" show="{{ show }}"
custom-class="van-notify" custom-class="van-notify"
custom-style="background-color:{{ backgroundColor }}; color: {{ color }}" custom-style="background-color:{{ backgroundColor }}; color: {{ color }};"
> >
<view wx:if="{{ safeAreaInsetTop }}" class="van-notify__safe-top" style="padding-top: {{ statusBarHeight }}px"></view>
{{ text }} {{ text }}
</van-transition> </van-transition>

View File

@ -1,9 +1,13 @@
import { isObj } from '../common/utils'; import { isObj } from '../common/utils';
type NotifyOptions = { type NotifyOptions = {
selector?: string; text: string;
color?: string;
backgroundColor?: string;
duration?: number; duration?: number;
selector?: string;
context?: any; context?: any;
safeAreaInsetTop?: boolean;
}; };
const defaultOptions = { const defaultOptions = {
@ -11,8 +15,8 @@ const defaultOptions = {
duration: 3000 duration: 3000
}; };
function parseOptions(text) { function parseOptions(text: NotifyOptions | string): NotifyOptions {
return isObj(text) ? text : { text }; return isObj(text) ? text as NotifyOptions : { text } as NotifyOptions;
} }
function getContext() { function getContext() {
@ -20,7 +24,7 @@ function getContext() {
return pages[pages.length - 1]; return pages[pages.length - 1];
} }
export default function Notify(options: NotifyOptions = {}) { export default function Notify(options: NotifyOptions | string) {
options = Object.assign({}, defaultOptions, parseOptions(options)); options = Object.assign({}, defaultOptions, parseOptions(options));
const context = options.context || getContext(); const context = options.context || getContext();

View File

@ -54,7 +54,8 @@ 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` | | safe-area-inset-bottom | 是否为iPhoneX留出底部安全距离 | `Boolean` | `true` |
| safe-area-inset-top | 是否留出顶部安全距离(状态栏高度 + 导航栏高度) | `Boolean` | `false` |
### Event ### Event

View File

@ -50,9 +50,20 @@
transform: translate3d(0, -50%, 0); transform: translate3d(0, -50%, 0);
} }
&--safe { &--bottom&--safe {
padding-bottom: @safe-area-inset-bottom; padding-bottom: @safe-area-inset-bottom;
} }
&--left &__safe-top,
&--right &__safe-top,
&--top &__safe-top {
height: @nav-bar-height;
}
&--center &__safe-top,
&--bottom &__safe-top {
padding-top: 0 !important;
}
} }
.van-scale-enter-active, .van-scale-enter-active,

View File

@ -1,6 +1,6 @@
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'; import { safeArea } from '../mixins/safe-area';
VantComponent({ VantComponent({
classes: [ classes: [
@ -12,7 +12,7 @@ VantComponent({
'leave-to-class' 'leave-to-class'
], ],
mixins: [transition(false), iphonex], mixins: [transition(false), safeArea()],
props: { props: {
transition: { transition: {

View File

@ -11,9 +11,10 @@
/> />
<view <view
wx:if="{{ inited }}" wx:if="{{ inited }}"
class="custom-class {{ classes }} {{ utils.bem('popup', [position, { safe: isIPhoneX && safeAreaInsetBottom && position === 'bottom' }]) }}" class="custom-class {{ classes }} {{ utils.bem('popup', [position, { safe: isIPhoneX && safeAreaInsetBottom }]) }}"
style="z-index: {{ zIndex }}; -webkit-transition-duration:{{ currentDuration }}ms; transition-duration:{{ currentDuration }}ms; {{ display ? '' : 'display: none;' }} {{ customStyle }}" style="z-index: {{ zIndex }}; -webkit-transition-duration:{{ currentDuration }}ms; transition-duration:{{ currentDuration }}ms; {{ display ? '' : 'display: none;' }} {{ customStyle }}"
bind:transitionend="onTransitionEnd" bind:transitionend="onTransitionEnd"
> >
<view wx:if="{{ safeAreaInsetTop }}" class="van-popup__safe-top" style="padding-top: {{ statusBarHeight }}px;"></view>
<slot /> <slot />
</view> </view>

View File

@ -74,7 +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` | | safe-area-inset-bottom | 是否为iPhoneX留出底部安全距离 | `Boolean` | `true` |
### Event ### Event
@ -98,10 +98,3 @@
| price-class | 价格样式类 | | price-class | 价格样式类 |
| button-class | 按钮样式类 | | button-class | 按钮样式类 |
| bar-class | 订单栏样式类 | | bar-class | 订单栏样式类 |
### 更新日志
| 版本 | 类型 | 内容 |
|-----------|-----------|-----------|
| 0.3.3 | feature | 新增组件 |
| 0.3.4 | bugfix | 修复金额为空时仍然显示合计的问题 |

View File

@ -1,8 +1,8 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { iphonex } from '../mixins/iphonex'; import { safeArea } from '../mixins/safe-area';
VantComponent({ VantComponent({
mixins: [iphonex], mixins: [safeArea()],
classes: [ classes: [
'bar-class', 'bar-class',

View File

@ -109,7 +109,7 @@ Page({
| active-color | 选中标签的颜色 | `String` | `#1989fa` | | active-color | 选中标签的颜色 | `String` | `#1989fa` |
| 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` | | safe-area-inset-bottom | 是否为iPhoneX留出底部安全距离 | `Boolean` | `true` |
### Tabbar Event ### Tabbar Event

View File

@ -1,8 +1,8 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { iphonex } from '../mixins/iphonex'; import { safeArea } from '../mixins/safe-area';
VantComponent({ VantComponent({
mixins: [iphonex], mixins: [safeArea()],
relation: { relation: {
name: 'tabbar-item', name: 'tabbar-item',