diff --git a/src/Dialog/index.js b/src/Dialog/index.js new file mode 100644 index 0000000000000000000000000000000000000000..3b021e144672b2f06a0f40f50244099cee6da797 --- /dev/null +++ b/src/Dialog/index.js @@ -0,0 +1,147 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { + Modal, + View, + Text, + ScrollView, + TouchableOpacity +} from 'react-native'; +import * as Animatable from 'react-native-animatable'; +import styles from './styles'; + +class Dialog extends React.Component { + static propTypes = { + payload: PropTypes.object, + show: PropTypes.bool, + customDesign: PropTypes.array, + title: PropTypes.string, + content: PropTypes.string, + buttonTxt: PropTypes.string, + cancelTxt: PropTypes.string, + confirmFun: PropTypes.func, + cancelFun: PropTypes.func, + showCancel: PropTypes.bool, + contentStyle: PropTypes.object, + titleStyle: PropTypes.object, + }; + + static defaultProps = { + payload: {}, + show: false, + customDesign: [], + title: '', + content: '', + buttonTxt: '登出', + cancelTxt: '取消', + confirmFun: () => {}, + cancelFun: () => {}, + showCancel: false, + contentStyle: {}, + titleStyle: {} + }; + + constructor(props) { + super(props); + const { + show, title, content, buttonTxt, cancelTxt, showCancel, payload, customDesign + } = this.props; + this.state = { + show, + title, + content, + buttonTxt, + cancelTxt, + showCancel, + customDesign + }; + this.payload = payload; + this.doConfirm = this.doConfirm.bind(this); + this.doCancel = this.doCancel.bind(this); + } + + componentWillReceiveProps(nextProps) { + const { + show, title, content, payload + } = nextProps; + if (show !== this.props.show) { + this.payload = payload; + this.setState({ show, title, content }); + } + } + + doConfirm() { + this.setState({ show: false }, () => this.props.confirmFun(this.payload)); + } + + doCancel() { + this.setState({ show: false }, () => this.props.cancelFun()); + } + + render() { + const { + showCancel, show, title, cancelTxt, customDesign + } = this.state; + const { contentStyle, titleStyle } = this.props; + if (!this.props.show && !show) { + return null; + } + const buttonStyle = (showCancel) ? { borderLeftWidth: 1, borderLeftColor: '#BCBBC1' } : {}; + return ( + { + this.doCancel(); + }} + > + + {customDesign && customDesign.length > 0 ? customDesign : ( + + {title !== '' ? ( + + {title} + + ) : []} + + + + {this.state.content} + + + + + {(showCancel) + ? ( + this.doCancel()} + > + + {cancelTxt} + + + ) : [] + } + this.doConfirm()} + > + + {this.state.buttonTxt} + + + + )} + + + ); + } +} + +export default Dialog; \ No newline at end of file