antd-mini
Version:
antd-mini 是支付宝小程序 UI 组件库,遵循 Ant Design 规范。
53 lines (52 loc) • 1.8 kB
JavaScript
import { Component, triggerEventOnly, getValueFromProps, } from '../_util/simply';
import { PopupDefaultProps } from './props';
import { isOldSDKVersion } from '../_util/platform';
var isOldVersion = isOldSDKVersion();
Component(PopupDefaultProps, {
onTapMask: function () {
var closing = this.data.closing;
if (closing) {
return;
}
triggerEventOnly(this, 'close');
},
onAnimationEnd: function () {
var closing = this.data.closing;
if (closing) {
this.setData({ closing: false });
}
var _a = getValueFromProps(this, [
'visible',
'duration',
'animation',
]), visible = _a[0], duration = _a[1], animation = _a[2];
var enableAnimation = animation && duration > 0;
if (enableAnimation) {
triggerEventOnly(this, visible ? 'afterShow' : 'afterClose');
}
},
}, {
closing: false,
isOldVersion: isOldVersion,
}, undefined, {
didUpdate: function (prevProps) {
var _this = this;
var _a = getValueFromProps(this, [
'visible',
'duration',
'animation',
]), visible = _a[0], duration = _a[1], animation = _a[2];
var enableAnimation = animation && duration > 0;
if (prevProps.visible !== visible) {
if (enableAnimation && !visible) {
setTimeout(function () {
// 这里需要用setTimeout包一下,解决支付宝小程序Picker中导致 targetId not match
_this.setData({ closing: true });
});
}
if (!enableAnimation) {
triggerEventOnly(this, visible ? 'afterShow' : 'afterClose');
}
}
},
});