/** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow */ import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View, Image, TouchableOpacity, ImageBackground, TextInput, Keyboard, Button, StatusBar, Modal, TouchableHighlight, DeviceEventEmitter } from 'react-native'; import ModalView from '../utils/ModalUtil'; type Props = {}; export default class PersonalInfoDialog extends Component { state = { modalVisible: false, title: 'title', placeholder: '', touchcolor: 'white', touchtextcolor: '#58A8FA', touch_cancel_color: 'white', touch_cancel_textcolor: '#58A8FA', input_text: '', updateType: 0, //1修改昵称,2修改学校名称, keyBoardHeight: 0 }; setModalVisible(visible, type) { this.setState({ modalVisible: visible, updateType: type, input_text: '' }); } setInfo(mytitle, holder) { this.setState({ title: mytitle, placeholder: holder }); } touchDown() { this.setState({ touchcolor: '#58A8FA', touchtextcolor: 'white' }); } touchUp() { this.setState({ touchcolor: 'white', touchtextcolor: '#58A8FA' }); } touchCancelDown() { this.setState({ touch_cancel_color: '#58A8FA', touch_cancel_textcolor: 'white' }); } touchCancelUp() { this.setState({ touch_cancel_color: 'white', touch_cancel_textcolor: '#58A8FA' }); } setParentState() { this.props.updateParentState(this.state.input_text, this.state.updateType); this.setModalVisible(false); } componentWillMount() { this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow); this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide); } componentWillUnmount() { this.keyboardDidShowListener.remove(); this.keyboardDidHideListener.remove(); } _keyboardDidShow = (e) => { this.setState({ keyBoardHeight: 0 }); }; _keyboardDidHide = () => { this.setState({ keyBoardHeight: 0 }); }; render() { return ( { this.setState({ modalVisible: false }); }} visible={this.state.modalVisible} customerlayout={{ flex: 1, justifyContent: 'flex-end' }} contentView={this.getView} /> ); } getView = () => { return ( { this.setState({ modalVisible: false }); }} > {this.state.title} this.setState({ input_text: text })} /> this.touchDown()} onPressOut={() => this.touchUp()} onPress={() => { this.setParentState(); }} > 确定 this.touchCancelDown()} onPressOut={() => this.touchCancelUp()} onPress={() => this.setModalVisible(false)} > 取消 ); }; }