diff --git a/index.js b/index.js index 2027947..f33eaa7 100644 --- a/index.js +++ b/index.js @@ -1,25 +1,32 @@ import React from 'react'; import { StyleSheet, Text, View, Modal, TextInput, TouchableOpacity, - Platform } from 'react-native'; + ActivityIndicator, Platform } from 'react-native'; class DialogInput extends React.Component{ constructor(props){ super(props); - this.state = { inputModal: '', openning: true } + this.state = { + inputModal: props.value || '' + } + } + + onShow() { + this.setState({inputModal:this.props.value || ''}); + } + + onClose() { + this.props.closeDialog(); + this.setState({inputModal:''}); } render(){ let title = this.props.title || ''; let hintInput = this.props.hintInput || ''; - let value = null; - - if (!this.state.openning) { - value = this.state.inputModal - } let textProps = this.props.textInputProps || null; let modalStyleProps = this.props.modalStyle || {}; let dialogStyleProps = this.props.dialogStyle || {}; + let animationType = this.props.animationType || 'fade'; var cancelText = this.props.cancelText || 'Cancel'; var submitText = this.props.submitText || 'Submit'; cancelText = (Platform.OS === 'ios')? cancelText:cancelText.toUpperCase(); @@ -27,52 +34,44 @@ class DialogInput extends React.Component{ return( { - this.props.closeDialog(); - this.state = { inputModal: '' }; - }}> - - { this.props.closeDialog(); this.setState({ openning: true })}} > - - - {title} - {this.props.message} - this.setState({ openning: false })} - underlineColorAndroid='transparent' - placeholder={hintInput} - onChangeText={(inputModal) => this.setState({inputModal})} - value={value} - /> - - - { - this.props.closeDialog(); - this.setState({ openning: true }) - }}> - {cancelText} - - - { - this.props.submitInput(this.state.inputModal); - this.setState({ openning: true }) - }}> - {submitText} - - + onShow={() => {this.onShow();}} + onRequestClose={() => {this.onClose();}}> + + + + {title} + {this.props.message} + this.setState({inputModal})} + value={this.state.inputModal} + autoFocus={(textProps && textProps.autoFocus===false)?false:true} + /> + + + {this.onClose();}}> + {cancelText} + + + { + this.props.submitInput(this.state.inputModal); + }}> + {submitText} + - + );