PersonalInfoDialog.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Component } from 'react';
  9. import {
  10. Platform,
  11. StyleSheet,
  12. Text,
  13. View,
  14. Image,
  15. TouchableOpacity,
  16. ImageBackground,
  17. TextInput,
  18. Keyboard,
  19. Button,
  20. StatusBar,
  21. Modal,
  22. TouchableHighlight,
  23. DeviceEventEmitter
  24. } from 'react-native';
  25. import ModalView from '../utils/ModalUtil';
  26. type Props = {};
  27. export default class PersonalInfoDialog extends Component<Props> {
  28. state = {
  29. modalVisible: false,
  30. title: 'title',
  31. placeholder: '',
  32. touchcolor: 'white',
  33. touchtextcolor: '#58A8FA',
  34. touch_cancel_color: 'white',
  35. touch_cancel_textcolor: '#58A8FA',
  36. input_text: '',
  37. updateType: 0, //1修改昵称,2修改学校名称,
  38. keyBoardHeight: 0
  39. };
  40. setModalVisible(visible, type) {
  41. this.setState({
  42. modalVisible: visible,
  43. updateType: type,
  44. input_text: ''
  45. });
  46. }
  47. setInfo(mytitle, holder) {
  48. this.setState({
  49. title: mytitle,
  50. placeholder: holder
  51. });
  52. }
  53. touchDown() {
  54. this.setState({
  55. touchcolor: '#58A8FA',
  56. touchtextcolor: 'white'
  57. });
  58. }
  59. touchUp() {
  60. this.setState({
  61. touchcolor: 'white',
  62. touchtextcolor: '#58A8FA'
  63. });
  64. }
  65. touchCancelDown() {
  66. this.setState({
  67. touch_cancel_color: '#58A8FA',
  68. touch_cancel_textcolor: 'white'
  69. });
  70. }
  71. touchCancelUp() {
  72. this.setState({
  73. touch_cancel_color: 'white',
  74. touch_cancel_textcolor: '#58A8FA'
  75. });
  76. }
  77. setParentState() {
  78. this.props.updateParentState(this.state.input_text, this.state.updateType);
  79. this.setModalVisible(false);
  80. }
  81. componentWillMount() {
  82. this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
  83. this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
  84. }
  85. componentWillUnmount() {
  86. this.keyboardDidShowListener.remove();
  87. this.keyboardDidHideListener.remove();
  88. }
  89. _keyboardDidShow = (e) => {
  90. this.setState({
  91. keyBoardHeight: 0
  92. });
  93. };
  94. _keyboardDidHide = () => {
  95. this.setState({
  96. keyBoardHeight: 0
  97. });
  98. };
  99. render() {
  100. return (
  101. <ModalView
  102. close={() => {
  103. this.setState({ modalVisible: false });
  104. }}
  105. visible={this.state.modalVisible}
  106. customerlayout={{ flex: 1, justifyContent: 'flex-end' }}
  107. contentView={this.getView}
  108. />
  109. );
  110. }
  111. getView = () => {
  112. return (
  113. <Modal
  114. animationType="slide"
  115. transparent={true}
  116. visible={this.state.modalVisible}
  117. onRequestClose={() => {
  118. this.setState({ modalVisible: false });
  119. }}
  120. >
  121. <View
  122. style={{
  123. flex: 1,
  124. width: '100%',
  125. height: '100%',
  126. flexDirection: 'column',
  127. justifyContent: 'flex-end'
  128. }}
  129. >
  130. <View
  131. style={{
  132. width: '100%',
  133. height: 150,
  134. backgroundColor: 'white',
  135. bottom: this.state.keyBoardHeight
  136. }}
  137. >
  138. <View
  139. style={{
  140. height: '100%',
  141. width: '100%',
  142. backgroundColor: 'white'
  143. }}
  144. >
  145. <View
  146. style={{
  147. flex: 1,
  148. alignItems: 'center',
  149. justifyContent: 'center'
  150. }}
  151. >
  152. <Text
  153. style={{
  154. flex: 1,
  155. textAlignVertical: 'center',
  156. fontSize: 16,
  157. color: 'black'
  158. }}
  159. >
  160. {this.state.title}
  161. </Text>
  162. </View>
  163. <View
  164. style={{
  165. flex: 1,
  166. alignItems: 'center',
  167. justifyContent: 'center'
  168. }}
  169. >
  170. <TextInput
  171. placeholder={this.state.placeholder}
  172. editable={true} //是否可编辑
  173. autoFocus={true}
  174. style={{
  175. width: '90%',
  176. height: '90%',
  177. borderColor: 'black',
  178. borderWidth: 0,
  179. marginLeft: 5,
  180. fontSize: 16
  181. }}
  182. onChangeText={(text) =>
  183. this.setState({
  184. input_text: text
  185. })}
  186. />
  187. </View>
  188. <View
  189. style={{
  190. flex: 0.8,
  191. flexDirection: 'row',
  192. alignItems: 'center'
  193. }}
  194. >
  195. <View
  196. style={{
  197. flex: 5
  198. }}
  199. />
  200. <View
  201. style={{
  202. flex: 2,
  203. height: '100%',
  204. borderRadius: 30,
  205. backgroundColor: this.state.touchcolor,
  206. alignItems: 'center'
  207. }}
  208. >
  209. <TouchableOpacity
  210. activeOpacity={1}
  211. onPressIn={() => this.touchDown()}
  212. onPressOut={() => this.touchUp()}
  213. onPress={() => {
  214. this.setParentState();
  215. }}
  216. >
  217. <Text
  218. style={{
  219. height: '100%',
  220. width: '100%',
  221. textAlignVertical: 'center',
  222. textAlign: 'center',
  223. fontSize: 18,
  224. borderRadius: 30,
  225. color: this.state.touchtextcolor
  226. }}
  227. >
  228. 确定
  229. </Text>
  230. </TouchableOpacity>
  231. </View>
  232. <View style={{ flex: 0.5 }} />
  233. <View
  234. style={{
  235. flex: 2,
  236. height: '100%',
  237. backgroundColor: this.state.touch_cancel_color,
  238. alignItems: 'center',
  239. borderRadius: 30
  240. }}
  241. >
  242. <TouchableOpacity
  243. activeOpacity={1}
  244. onPressIn={() => this.touchCancelDown()}
  245. onPressOut={() => this.touchCancelUp()}
  246. onPress={() => this.setModalVisible(false)}
  247. >
  248. <Text
  249. style={{
  250. textAlignVertical: 'center',
  251. textAlign: 'center',
  252. height: '100%',
  253. width: '100%',
  254. fontSize: 18,
  255. color: this.state.touch_cancel_textcolor
  256. }}
  257. >
  258. 取消
  259. </Text>
  260. </TouchableOpacity>
  261. </View>
  262. <View style={{ flex: 0.5 }} />
  263. </View>
  264. <View style={{ flex: 0.2 }} />
  265. </View>
  266. </View>
  267. </View>
  268. </Modal>
  269. );
  270. };
  271. }