-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorPicker.js
More file actions
62 lines (59 loc) · 1.51 KB
/
ColorPicker.js
File metadata and controls
62 lines (59 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { Component } from "react";
import { StyleSheet, Text, View } from "react-native";
const COLORS = ["W", "U", "B", "R", "G"];
export default class ColorPicker extends Component {
constructor(props) {
super(props);
this.state = {
callback: props.callback,
colors: [true, true, true, true, true]
};
}
render() {
return (
<View style={styles.colorPickerContainer}>
{COLORS.map((item, index) => (
<Text
onPress={() => {
let newcolors = this.state.colors;
newcolors[index] = !newcolors[index];
this.forceUpdate();
this.state.callback(newcolors);
this.setState({ colors: newcolors });
}}
key={index}
style={
this.state.colors[index]
? [styles.colorPickerButton, styles.colorPickerButtonActive]
: [styles.colorPickerButton, styles.colorPickerButtonInactive]
}
>
{item}
</Text>
))}
</View>
);
}
}
const styles = StyleSheet.create({
colorPickerContainer: {
flex: 1,
flexDirection: "row",
alignItems: "center",
justifyContent: "center"
},
colorPickerButton: {
width: 35,
backgroundColor: "#AAAAAA",
borderRadius: 3,
fontSize: 20,
textAlign: "center",
marginHorizontal: 5
},
colorPickerButtonActive: {
backgroundColor: "#AAFFAA"
},
colorPickerButtonInactive: {
backgroundColor: "#FFAAAA"
}
});