import React from 'react' import { View, Text, TouchableOpacity, Dimensions, TextStyle } from 'react-native' import { SlideModal, SlideModalProps } from '../SlideModal' import styleUtils from '../../common/styles/utils' import bottomModalStyles from './styles' const window = Dimensions.get('window') export interface BottomModalProps extends SlideModalProps { testID?: string titleContainer?: any title?: string titleStyle?: TextStyle rightLabel?: any rightLabelText?: string rightLabelTextStyle?: TextStyle rightCallback?: Function leftLabel?: any leftLabelText?: string leftLabelTextStyle?: TextStyle leftCallback?: Function } export class BottomModal extends SlideModal { static defaultProps = { ...SlideModal.defaultProps, cancelable: true, screenWidth: window.width, titleContainer: null, title: '标题', titleStyle: {}, rightLabel: null, rightLabelText: '完成', rightLabelTextStyle: {}, rightCallback: null, leftLabel: null, leftLabelText: '取消', leftLabelTextStyle: {}, leftCallback: null, } constructor (props) { super(props) } getHeader () { const styles = bottomModalStyles const { titleContainer, title, titleStyle, rightLabel, rightLabelText, rightLabelTextStyle, rightCallback, leftLabel, leftLabelText, leftLabelTextStyle, leftCallback } = this.props let rightEl = null if (rightLabel || rightLabelText) { rightEl = ( { this.close().then(() => { rightCallback && rightCallback() }) }}> { React.isValidElement(rightLabel) ? rightLabel : {rightLabelText} } ) } let leftEl = null if (leftLabel || leftLabelText) { leftEl = ( { this.close().then(() => { leftCallback && leftCallback() }) }} > { React.isValidElement(leftLabel) ? leftLabel : {leftLabelText} } ) } let titleContainerEl = null if (titleContainer || title) { titleContainerEl = React.isValidElement(titleContainer) ? titleContainer : ( {title} ) } return ( {leftEl} {titleContainerEl} {rightEl} ) } getBody () { return this.props.children } getContent () { const styles = bottomModalStyles const inner = ( {this.getHeader()} {/* TouchableOpacity 没设置高度时 onPress 有问题*/} {this.getBody()} ) return SlideModal.prototype.getContent.call(this, inner) } }