|
@@ -32,6 +32,9 @@ 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: [
|
|
|
"一年级",
|
|
|
"二年级",
|
|
@@ -151,72 +154,79 @@ export default class GradeSelectionModal extends Component<Props> {
|
|
|
style={{
|
|
|
flex: 1,
|
|
|
flexDirection: "column",
|
|
|
- alignItems: "center"
|
|
|
+ alignItems: "center",
|
|
|
+ justifyContent: "center"
|
|
|
}}
|
|
|
>
|
|
|
<View
|
|
|
style={{
|
|
|
flex: 1,
|
|
|
- justifyContent: "space-between",
|
|
|
+ justifyContent: "space-evenly",
|
|
|
width: "90%",
|
|
|
- flexDirection: "row"
|
|
|
- }}
|
|
|
- >
|
|
|
- <TouchableOpacity
|
|
|
- onPress={() => this.clickGrade()}
|
|
|
- style={styles.item}
|
|
|
- >
|
|
|
- <Text style={styles.item_text}>一年级</Text>
|
|
|
- </TouchableOpacity>
|
|
|
- <View style={styles.item}>
|
|
|
- <Text style={styles.item_text}>二年级</Text>
|
|
|
- </View>
|
|
|
- <View style={styles.item}>
|
|
|
- <Text style={styles.item_text}>三年级</Text>
|
|
|
- </View>
|
|
|
- </View>
|
|
|
- <View
|
|
|
- style={{
|
|
|
- flex: 1,
|
|
|
- justifyContent: "space-between",
|
|
|
- width: "90%",
|
|
|
- flexDirection: "row"
|
|
|
+ flexDirection: "row",
|
|
|
+ //换行显示
|
|
|
+ flexWrap: "wrap",
|
|
|
+ alignItems: "center"
|
|
|
}}
|
|
|
+ onLayout={event => this.onLayout(event)}
|
|
|
>
|
|
|
- <View style={styles.item}>
|
|
|
- <Text style={styles.item_text}>四年级</Text>
|
|
|
- </View>
|
|
|
- <View style={styles.item}>
|
|
|
- <Text style={styles.item_text}>五年级</Text>
|
|
|
- </View>
|
|
|
- <View style={styles.item}>
|
|
|
- <Text style={styles.item_text}>六年级</Text>
|
|
|
- </View>
|
|
|
+ {this.centerItem()}
|
|
|
</View>
|
|
|
- <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={{
|
|
|
- flex: 1,
|
|
|
- justifyContent: "space-between",
|
|
|
- width: "90%",
|
|
|
- flexDirection: "row"
|
|
|
+ margin: 1,
|
|
|
+ height: this.state.item_height,
|
|
|
+ alignItems: "center",
|
|
|
+ justifyContent: "center"
|
|
|
}}
|
|
|
+ onPress={() => this.clickGrade(index)}
|
|
|
>
|
|
|
- <View style={styles.item}>
|
|
|
- <Text style={styles.item_text}>七年级</Text>
|
|
|
- </View>
|
|
|
- <View style={styles.item}>
|
|
|
- <Text style={styles.item_text}>八年级</Text>
|
|
|
- </View>
|
|
|
- <View style={styles.item}>
|
|
|
- <Text style={styles.item_text}>九年级</Text>
|
|
|
+ <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>
|
|
|
- </View>
|
|
|
- </View>
|
|
|
- );
|
|
|
- }
|
|
|
+ </TouchableOpacity>
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
commit() {
|
|
|
- alert("确定");
|
|
|
+ this.props.commitGrade(
|
|
|
+ this.state.grade_data[this.state.click_index],
|
|
|
+ this.state.click_index
|
|
|
+ );
|
|
|
+ this.setModalVisible(false);
|
|
|
}
|
|
|
|
|
|
setModalVisible(visible) {
|
|
@@ -224,20 +234,18 @@ export default class GradeSelectionModal extends Component<Props> {
|
|
|
modalVisible: visible
|
|
|
});
|
|
|
}
|
|
|
- clickGrade() {}
|
|
|
+ clickGrade(index) {
|
|
|
+ this.setState({
|
|
|
+ click_index: index
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
const styles = StyleSheet.create({
|
|
|
- item: {
|
|
|
- width: 127,
|
|
|
- height: 53,
|
|
|
- backgroundColor: "rgba(61, 192, 252, 0.15)",
|
|
|
- borderRadius: 30
|
|
|
- },
|
|
|
item_text: {
|
|
|
flex: 1,
|
|
|
textAlign: "center",
|
|
|
textAlignVertical: "center",
|
|
|
color: "rgba(58, 58, 58, 1)",
|
|
|
- fontSize: 18
|
|
|
+ fontSize: 16
|
|
|
}
|
|
|
});
|