Showing
2 changed files
with
131 additions
and
21 deletions
| @@ -5,6 +5,7 @@ import { | @@ -5,6 +5,7 @@ import { | ||
| 5 | Text, | 5 | Text, |
| 6 | View, | 6 | View, |
| 7 | ScrollView, | 7 | ScrollView, |
| 8 | + TextInput, | ||
| 8 | TouchableOpacity, | 9 | TouchableOpacity, |
| 9 | TouchableHighlight, | 10 | TouchableHighlight, |
| 10 | Image, | 11 | Image, |
| @@ -15,22 +16,43 @@ export default class PersonalInfo extends Component { | @@ -15,22 +16,43 @@ export default class PersonalInfo extends Component { | ||
| 15 | constructor(props) { | 16 | constructor(props) { |
| 16 | super(props); | 17 | super(props); |
| 17 | this.state = { | 18 | this.state = { |
| 18 | - modalVisible: false | 19 | + modalVisible: false, |
| 20 | + title: "更改昵称", | ||
| 21 | + type: "name", | ||
| 22 | + text: "", | ||
| 23 | + name: this.props.name, | ||
| 24 | + identity: this.props.identity, | ||
| 19 | }; | 25 | }; |
| 20 | } | 26 | } |
| 21 | 27 | ||
| 22 | - setModalVisible(visible) { | 28 | + setModalVisible(visible,type) { |
| 23 | this.setState({ modalVisible: visible }); | 29 | this.setState({ modalVisible: visible }); |
| 30 | + this.setState({ | ||
| 31 | + type: type, | ||
| 32 | + title: type == "name" ? "更改昵称" : "更改职业" | ||
| 33 | + }) | ||
| 34 | + } | ||
| 35 | + confirmChange() { | ||
| 36 | + console.log("看看拿到方法没",this); | ||
| 37 | + if (this.state.type == "name") { | ||
| 38 | + this.setState({name: this.state.text}) | ||
| 39 | + } else { | ||
| 40 | + this.setState({identity: this.state.text}) | ||
| 41 | + } | ||
| 42 | + this.setState({ | ||
| 43 | + modalVisible: false, | ||
| 44 | + }); | ||
| 45 | + // 修改mine组件的属性值,该方法是从mine组件传过来的 | ||
| 46 | + this.props.changeInfo(this.state.type,this.state.text); | ||
| 24 | } | 47 | } |
| 25 | - | ||
| 26 | render() { | 48 | render() { |
| 27 | - const { name, identity } = this.props; | 49 | + const { name, identity } = this.state; |
| 28 | return ( | 50 | return ( |
| 29 | <View style={styles.container}> | 51 | <View style={styles.container}> |
| 30 | <TouchableOpacity | 52 | <TouchableOpacity |
| 31 | style={styles.itemContainer} | 53 | style={styles.itemContainer} |
| 32 | onPress={() => { | 54 | onPress={() => { |
| 33 | - this.setModalVisible(true); | 55 | + this.setModalVisible(true,"name"); |
| 34 | }} | 56 | }} |
| 35 | > | 57 | > |
| 36 | <Text style={styles.itemLeft}>昵称</Text> | 58 | <Text style={styles.itemLeft}>昵称</Text> |
| @@ -45,7 +67,7 @@ export default class PersonalInfo extends Component { | @@ -45,7 +67,7 @@ export default class PersonalInfo extends Component { | ||
| 45 | <TouchableOpacity | 67 | <TouchableOpacity |
| 46 | style={styles.itemContainer} | 68 | style={styles.itemContainer} |
| 47 | onPress={() => { | 69 | onPress={() => { |
| 48 | - this.setModalVisible(true); | 70 | + this.setModalVisible(true,"identity"); |
| 49 | }} | 71 | }} |
| 50 | > | 72 | > |
| 51 | <Text style={styles.itemLeft}>职业</Text> | 73 | <Text style={styles.itemLeft}>职业</Text> |
| @@ -58,24 +80,44 @@ export default class PersonalInfo extends Component { | @@ -58,24 +80,44 @@ export default class PersonalInfo extends Component { | ||
| 58 | </View> | 80 | </View> |
| 59 | </TouchableOpacity> | 81 | </TouchableOpacity> |
| 60 | 82 | ||
| 83 | + {/* 弹出框 */} | ||
| 61 | <Modal | 84 | <Modal |
| 62 | animationType={"slide"} | 85 | animationType={"slide"} |
| 63 | - transparent={false} | 86 | + transparent={true} |
| 64 | visible={this.state.modalVisible} | 87 | visible={this.state.modalVisible} |
| 65 | - onRequestClose={() => { | ||
| 66 | - alert("Modal has been closed."); | ||
| 67 | - }} | ||
| 68 | > | 88 | > |
| 69 | - <View style={{ marginTop: 22 }}> | 89 | + <View style={styles.modalConatier}> |
| 70 | - <View> | 90 | + <View style={styles.modalWrapper}> |
| 71 | - <Text>Hello World!</Text> | 91 | + <Text style={styles.title}>{this.state.title}</Text> |
| 72 | - <TouchableOpacity | 92 | + <TextInput |
| 73 | - onPress={() => { | 93 | + style={styles.textInput} |
| 74 | - this.setModalVisible(!this.state.modalVisible); | 94 | + autoFocus={true} |
| 75 | - }} | 95 | + value={this.state.text} |
| 76 | - > | 96 | + onChangeText={ text => this.setState({ text })} |
| 77 | - <Text>Hide Modal</Text> | 97 | + selectionColor="#0076FF" |
| 78 | - </TouchableOpacity> | 98 | + clearTextOnFocus={true} |
| 99 | + numberOfLines={1} | ||
| 100 | + clearButtonMode="always" | ||
| 101 | + keyboardType="default" | ||
| 102 | + /> | ||
| 103 | + <View style={styles.btns}> | ||
| 104 | + <TouchableOpacity | ||
| 105 | + style={styles.btn} | ||
| 106 | + onPress={() => { | ||
| 107 | + this.setModalVisible(!this.state.modalVisible); | ||
| 108 | + }} | ||
| 109 | + > | ||
| 110 | + <Text style={styles.btnText}>取消</Text> | ||
| 111 | + </TouchableOpacity> | ||
| 112 | + <TouchableOpacity | ||
| 113 | + style={styles.btn} | ||
| 114 | + onPress={() => { | ||
| 115 | + this.confirmChange() | ||
| 116 | + }} | ||
| 117 | + > | ||
| 118 | + <Text style={styles.btnText}>确定</Text> | ||
| 119 | + </TouchableOpacity> | ||
| 120 | + </View> | ||
| 79 | </View> | 121 | </View> |
| 80 | </View> | 122 | </View> |
| 81 | </Modal> | 123 | </Modal> |
| @@ -119,5 +161,61 @@ const styles = StyleSheet.create({ | @@ -119,5 +161,61 @@ const styles = StyleSheet.create({ | ||
| 119 | itemArrow: { | 161 | itemArrow: { |
| 120 | width: 14, | 162 | width: 14, |
| 121 | height: 14 | 163 | height: 14 |
| 164 | + }, | ||
| 165 | + modalConatier: { | ||
| 166 | + alignItems: "center", | ||
| 167 | + justifyContent: "center", | ||
| 168 | + flex: 1, | ||
| 169 | + backgroundColor: "rgba(0, 0, 0, 0.5)" | ||
| 170 | + }, | ||
| 171 | + modalWrapper: { | ||
| 172 | + width: 270, | ||
| 173 | + height: 180, | ||
| 174 | + borderRadius: 10, | ||
| 175 | + backgroundColor: "white", | ||
| 176 | + // paddingLeft: 20, | ||
| 177 | + // paddingRight: 20, | ||
| 178 | + paddingBottom: 10, | ||
| 179 | + justifyContent: "center", | ||
| 180 | + alignItems: "center", | ||
| 181 | + }, | ||
| 182 | + title: { | ||
| 183 | + fontSize: 17, | ||
| 184 | + color: "#030303", | ||
| 185 | + marginLeft: 20, | ||
| 186 | + position: "absolute", | ||
| 187 | + top: 38, | ||
| 188 | + left: 20 | ||
| 189 | + }, | ||
| 190 | + textInput: { | ||
| 191 | + marginTop: 20, | ||
| 192 | + marginLeft: 20, | ||
| 193 | + marginRight: 20, | ||
| 194 | + width: 150, | ||
| 195 | + borderStyle: "solid", | ||
| 196 | + borderColor: "#ccc", | ||
| 197 | + borderBottomWidth: 0.5, | ||
| 198 | + }, | ||
| 199 | + btns: { | ||
| 200 | + position: "absolute", | ||
| 201 | + bottom: 0, | ||
| 202 | + height: 44, | ||
| 203 | + flexDirection: "row", | ||
| 204 | + borderStyle: "solid", | ||
| 205 | + borderColor: "#ccc", | ||
| 206 | + borderTopWidth: 0.5, | ||
| 207 | + }, | ||
| 208 | + btn: { | ||
| 209 | + width: 135, | ||
| 210 | + height: 44, | ||
| 211 | + justifyContent: "center", | ||
| 212 | + alignItems: "center", | ||
| 213 | + borderStyle: "solid", | ||
| 214 | + borderColor: "#ccc", | ||
| 215 | + borderLeftWidth: 0.5, | ||
| 216 | + }, | ||
| 217 | + btnText: { | ||
| 218 | + color: "#0076FF", | ||
| 219 | + fontSize: 17, | ||
| 122 | } | 220 | } |
| 123 | }); | 221 | }); |
| @@ -29,7 +29,8 @@ export default class Mine extends Component { | @@ -29,7 +29,8 @@ export default class Mine extends Component { | ||
| 29 | component: PersonalInfo, | 29 | component: PersonalInfo, |
| 30 | passProps: { | 30 | passProps: { |
| 31 | name: this.state.name, | 31 | name: this.state.name, |
| 32 | - identity: this.state.identity | 32 | + identity: this.state.identity, |
| 33 | + changeInfo: (type,text) => this.changeInfo(type,text), | ||
| 33 | } | 34 | } |
| 34 | }); | 35 | }); |
| 35 | }} | 36 | }} |
| @@ -108,6 +109,17 @@ export default class Mine extends Component { | @@ -108,6 +109,17 @@ export default class Mine extends Component { | ||
| 108 | console.log("看看this是什么", this); | 109 | console.log("看看this是什么", this); |
| 109 | this.props.onLogin(false); | 110 | this.props.onLogin(false); |
| 110 | } | 111 | } |
| 112 | + changeInfo(type,text) { | ||
| 113 | + if (type == "name") { | ||
| 114 | + this.setState({ | ||
| 115 | + name: text | ||
| 116 | + }) | ||
| 117 | + } else { | ||
| 118 | + this.setState({ | ||
| 119 | + identity: text | ||
| 120 | + }) | ||
| 121 | + } | ||
| 122 | + } | ||
| 111 | } | 123 | } |
| 112 | 124 | ||
| 113 | class BarList extends Component { | 125 | class BarList extends Component { |
-
Please register or login to post a comment