PersonalInfoDialog.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. Button,
  19. StatusBar,
  20. Modal,
  21. TouchableHighlight,
  22. DeviceEventEmitter
  23. } from "react-native";
  24. type Props = {};
  25. export default class PersonalInfoDialog extends Component<Props> {
  26. state = {
  27. modalVisible: false,
  28. title: "title",
  29. placeholder: "",
  30. touchcolor: "white",
  31. touchtextcolor: "#58A8FA",
  32. touch_cancel_color: "white",
  33. touch_cancel_textcolor: "#58A8FA",
  34. input_text: "",
  35. updateType: 0 //1修改昵称,2修改学校名称
  36. };
  37. setModalVisible(visible, type) {
  38. this.setState({
  39. modalVisible: visible,
  40. updateType: type,
  41. input_text: ""
  42. });
  43. }
  44. setInfo(mytitle, holder) {
  45. this.setState({
  46. title: mytitle,
  47. placeholder: holder
  48. });
  49. }
  50. touchDown() {
  51. this.setState({
  52. touchcolor: "#58A8FA",
  53. touchtextcolor: "white"
  54. });
  55. }
  56. touchUp() {
  57. this.setState({
  58. touchcolor: "white",
  59. touchtextcolor: "#58A8FA"
  60. });
  61. }
  62. touchCancelDown() {
  63. this.setState({
  64. touch_cancel_color: "#58A8FA",
  65. touch_cancel_textcolor: "white"
  66. });
  67. }
  68. touchCancelUp() {
  69. this.setState({
  70. touch_cancel_color: "white",
  71. touch_cancel_textcolor: "#58A8FA"
  72. });
  73. }
  74. setParentState() {
  75. let data;
  76. if (this.state.updateType == 1) {
  77. data = { nickName: this.state.input_text };
  78. } else if (this.state.updateType == 2) {
  79. data = { schoolName: this.state.input_text };
  80. }
  81. this.props.updateParentState(data);
  82. this.setModalVisible(false);
  83. }
  84. render() {
  85. return (
  86. <Modal
  87. animationType="fade"
  88. transparent={true}
  89. visible={this.state.modalVisible}
  90. onRequestClose={() => {
  91. this.setState({ modalVisible: false });
  92. }}
  93. >
  94. <View
  95. style={{
  96. flex: 1,
  97. width: "100%",
  98. height: "100%",
  99. alignItems: "center",
  100. justifyContent: "center",
  101. backgroundColor: "rgba(0, 0, 0, 0.3)",
  102. flexDirection: "row"
  103. }}
  104. >
  105. <View
  106. style={{
  107. flex: 111,
  108. alignItems: "center",
  109. justifyContent: "center",
  110. backgroundColor: "white"
  111. }}
  112. >
  113. <View
  114. style={{
  115. height: 150,
  116. width: "100%",
  117. backgroundColor: "white"
  118. }}
  119. >
  120. <View
  121. style={{
  122. flex: 1,
  123. alignItems: "center",
  124. justifyContent: "center"
  125. }}
  126. >
  127. <Text
  128. style={{
  129. flex: 1,
  130. textAlignVertical: "center",
  131. fontSize: 25,
  132. color: "black"
  133. }}
  134. >
  135. {this.state.title}
  136. </Text>
  137. </View>
  138. <View
  139. style={{
  140. flex: 1,
  141. alignItems: "center",
  142. justifyContent: "center"
  143. }}
  144. >
  145. <TextInput
  146. placeholder={this.state.placeholder}
  147. editable={true} //是否可编辑
  148. style={{
  149. width: "90%",
  150. height: "90%",
  151. borderColor: "black",
  152. borderWidth: 0,
  153. marginLeft: 5,
  154. fontSize: 20
  155. }}
  156. onChangeText={text => this.setState({ input_text: text })}
  157. />
  158. </View>
  159. <View
  160. style={{
  161. flex: 0.8,
  162. flexDirection: "row",
  163. alignItems: "center"
  164. }}
  165. >
  166. <View
  167. style={{
  168. flex: 4
  169. }}
  170. />
  171. <View
  172. style={{
  173. flex: 2,
  174. backgroundColor: this.state.touchcolor,
  175. height: "100%",
  176. borderRadius: 30
  177. }}
  178. >
  179. <TouchableOpacity
  180. activeOpacity={1}
  181. onPressIn={() => this.touchDown()}
  182. onPressOut={() => this.touchUp()}
  183. onPress={() => {
  184. this.setParentState();
  185. }}
  186. >
  187. <Text
  188. style={{
  189. textAlignVertical: "center",
  190. textAlign: "center",
  191. fontSize: 25,
  192. borderRadius: 30,
  193. color: this.state.touchtextcolor
  194. }}
  195. >
  196. 确定
  197. </Text>
  198. </TouchableOpacity>
  199. </View>
  200. <View style={{ flex: 0.5 }} />
  201. <View
  202. style={{
  203. flex: 2,
  204. backgroundColor: this.state.touch_cancel_color,
  205. height: "100%",
  206. borderRadius: 30
  207. }}
  208. >
  209. <TouchableOpacity
  210. activeOpacity={1}
  211. onPressIn={() => this.touchCancelDown()}
  212. onPressOut={() => this.touchCancelUp()}
  213. onPress={() => this.setModalVisible(false)}
  214. >
  215. <Text
  216. style={{
  217. textAlignVertical: "center",
  218. textAlign: "center",
  219. fontSize: 25,
  220. color: this.state.touch_cancel_textcolor
  221. }}
  222. >
  223. 取消
  224. </Text>
  225. </TouchableOpacity>
  226. </View>
  227. <View style={{ flex: 0.5 }} />
  228. </View>
  229. <View style={{ flex: 0.2 }} />
  230. </View>
  231. </View>
  232. </View>
  233. </Modal>
  234. );
  235. }
  236. }