import React,{Component} from "react"; import {View, Text, StyleSheet, Dimensions, TouchableOpacity} from "react-native"; import {connect} from 'react-redux'; import {hideDialog} from './Dialog'; import {DialogState} from './Dialog'; var { width, height } = Dimensions.get("window"); interface IDispatch { hideDialog: ()=> void; } class DialogComponent extends Component{ buttonPress = (type:String) => { if(type === 'primary'){ if(this.props.primaryButtonPress) this.props.primaryButtonPress(); this.props.hideDialog(); } if(type === 'secondary'){ if(this.props.secondaryButtonPress) this.props.secondaryButtonPress(); this.props.hideDialog(); } } render(){ let buttonContainer ; if(this.props.buttonAlignment === 'center'){ buttonContainer = styles.buttonContainerCenter; } else if(this.props.buttonAlignment === 'left'){ buttonContainer = styles.buttonContainerLeft; } else { buttonContainer = styles.buttonContainer; } if(this.props.show){ return( {this.props.header} {this.props.info} this.buttonPress('primary')}> {this.props.primaryButtonText} { this.props.secondaryButtonPress && this.buttonPress('secondary')}> {this.props.secondaryButtonText} } ) } else { return null } } } function mapStateToProps(state : DialogState){ return state } export default connect(mapStateToProps, {hideDialog})(DialogComponent); const styles = StyleSheet.create({ backdrop:{ flex:1, alignItems:"center", justifyContent:"center", position:"absolute", top:0, left:0, backgroundColor: "rgba(0,0,0,0.6)", height: height, width: width, elevation:1 }, dialogStyle: { backgroundColor: "white", width: 350, height: 190, elevation: 3, borderRadius: 5, padding:10 }, header:{ padding:10, paddingHorizontal: 30 }, headerText:{ fontWeight:"bold", color: "black", fontSize: 20 }, buttonContainer:{ flexDirection: "row", justifyContent: "flex-end" }, buttonContainerLeft:{ flexDirection: "row", justifyContent: "flex-start" }, buttonContainerCenter:{ flexDirection: "row", justifyContent: "center" }, buttonPrimary:{ alignItems:"center", backgroundColor:"white", padding:10, paddingHorizontal: 20 }, buttonPrimaryText:{ color:"black", fontWeight:"bold" }, buttonSecondary:{ alignItems:"center", backgroundColor:"white", padding:10, paddingHorizontal: 20, marginHorizontal: 10 }, buttonSecondaryText:{ color:"black", fontWeight:"bold" }, infoContainer:{ flex:1, justifyContent:"center", alignItems:"flex-start", paddingHorizontal: 30 }, info:{ fontSize: 16 } });