123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- /**
- * 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,
- Button,
- StatusBar,
- Modal,
- ScrollView,
- TouchableHighlight,
- DeviceEventEmitter,
- findNodeHandle,
- UIManager
- } from "react-native";
- import CitysData from "../../data/citys.json";
- type Props = {};
- export default class GradeSelectionModal extends Component<Props> {
- state = {
- modalVisible: false,
- click_index: this.props.grade_index,
- item_width: 0,
- item_height: 0,
- grade_data: [
- "一年级",
- "二年级",
- "三年级",
- "四年级",
- "五年级",
- "六年级",
- "七年级",
- "八年级",
- "九年级"
- ]
- };
- render() {
- return (
- <Modal
- // animationType="fade"
- animationType="none"
- transparent={true}
- visible={this.state.modalVisible}
- onRequestClose={() => {
- this.setState({ modalVisible: false });
- }}
- >
- <View
- style={{
- flex: 1,
- justifyContent: "center",
- alignItems: "center"
- }}
- >
- <View
- style={{
- width: "92%",
- backgroundColor: "white",
- height: "80%",
- borderRadius: 20,
- flexDirection: "column",
- overflow: "hidden",
- alignItems: "center",
- justifyContent: "center"
- }}
- >
- <View
- style={{
- flex: 1,
- justifyContent: "center",
- alignItems: "center"
- }}
- >
- <Text
- style={{
- textAlign: "center",
- fontSize: 22,
- color: "rgba(58, 58, 58, 1)"
- }}
- >
- 我所在的年级
- </Text>
- </View>
- <View
- style={{
- flex: 3,
- width: "100%",
- marginTop: 5
- }}
- >
- {this.centerView()}
- </View>
- <View style={{ flex: 2, width: "90%" }}>
- <ImageBackground
- source={require("../images/userInfo/logoutbg1.png")}
- style={{
- flex: 1,
- width: "100%",
- alignItems: "center",
- justifyContent: "center",
- height: "100%"
- }}
- imageStyle={{
- resizeMode: "contain"
- }}
- >
- <TouchableOpacity
- style={{
- width: "100%",
- alignItems: "center",
- height: "40%",
- justifyContent: "center"
- }}
- activeOpacity={1}
- onPress={() => this.commit()}
- >
- <Text
- style={{
- fontSize: 30,
- color: "white",
- width: "100%",
- textAlign: "center"
- }}
- >
- 确定
- </Text>
- </TouchableOpacity>
- </ImageBackground>
- </View>
- <View style={{ flex: 0.5 }} />
- </View>
- </View>
- </Modal>
- );
- }
- centerView() {
- return (
- <View
- style={{
- flex: 1,
- flexDirection: "column",
- alignItems: "center",
- justifyContent: "center"
- }}
- >
- <View
- style={{
- flex: 1,
- justifyContent: "space-evenly",
- width: "90%",
- flexDirection: "row",
- //换行显示
- flexWrap: "wrap",
- alignItems: "center"
- }}
- onLayout={event => this.onLayout(event)}
- >
- {this.centerItem()}
- </View>
- </View>
- );
- }
- onLayout(event) {
- // alert(event.nativeEvent.layout.width);
- // alert(event.nativeEvent.layout.width / 3);
- this.setState({
- item_width: event.nativeEvent.layout.width / 3.5,
- item_height: event.nativeEvent.layout.height / 3
- });
- }
- centerItem() {
- let arr = [];
- for (let i = 0; i < this.state.grade_data.length; i++) {
- let index = i;
- let color = "";
- if (this.state.click_index == i) {
- color = "rgba(88, 168, 250, 1)";
- } else {
- color = "rgba(61, 192, 252, 0.15)";
- }
- arr[i] = (
- <TouchableOpacity
- activeOpacity={1}
- key={i}
- style={{
- margin: 1,
- height: this.state.item_height,
- alignItems: "center",
- justifyContent: "center"
- }}
- onPress={() => this.clickGrade(index)}
- >
- <View
- style={{
- width: this.state.item_width,
- height: this.state.item_height / 2,
- backgroundColor: color,
- borderRadius: 20
- }}
- >
- <Text style={styles.item_text}>{this.state.grade_data[i]}</Text>
- </View>
- </TouchableOpacity>
- );
- }
- return arr;
- }
- commit() {
- this.props.commitGrade(
- this.state.grade_data[this.state.click_index],
- this.state.click_index
- );
- this.setModalVisible(false);
- }
- setModalVisible(visible) {
- this.setState({
- modalVisible: visible
- });
- }
- clickGrade(index) {
- this.setState({
- click_index: index
- });
- }
- }
- const styles = StyleSheet.create({
- item_text: {
- flex: 1,
- textAlign: "center",
- textAlignVertical: "center",
- color: "rgba(58, 58, 58, 1)",
- fontSize: 16
- }
- });
|