yylib-quick-mobile
Version:
yylib-quick-mobile
66 lines • 1.9 kB
JavaScript
import React, {Component} from 'react';
import { SwipeAction } from 'antd-mobile';
class YYSwipeAction extends Component {
firstPress = (event) => {
event.stopPropagation()
if(this.props.firstPress){
this.props.firstPress();
}
}
secondPress = (event) => {
event.stopPropagation()
if(this.props.secondPress){
this.props.secondPress();
}
}
onOpen = () => {
if(this.props.onOpen){
this.props.onOpen();
}
}
onClose = () => {
if(this.props.onClose){
this.props.onClose();
}
}
render() {
let {first,second,autoClose,disabled,disabledFirst,disabledSecond,children,left,right,visible,...restProps} = this.props;
let rightButtons = [];
if (disabledFirst) {
rightButtons.push({
text: first||'取消',
onPress: this.firstPress.bind(this),
style: { backgroundColor: '#ddd', color: 'white' },
});
}
if (disabledSecond) {
rightButtons.push({
text: second||'删除',
onPress: this.secondPress.bind(this),
style: { backgroundColor: '#F4333C', color: 'white' },
});
}
return (
<SwipeAction
{...restProps}
className={!visible&&'hidden'}
autoClose
left={left&&left.length>0}
right={right&&right.length>0||rightButtons}
onOpen={this.onOpen.bind(this)}
onClose={this.onClose.bind(this)}
disabled={disabled}
>
{this.props.RunInDesign&&!children?<div>测试滑动-只有右侧按钮-两个</div>:children}
</SwipeAction>
);
}
}
YYSwipeAction.defaultProps = {
left:[],//作为组件使用需要传递左侧按钮组
right:[],//作为组件使用需要传递右侧按钮组
disabled: false,
autoClose: true,
visible: true
}
export default YYSwipeAction;