/
App.js
131 lines (120 loc) · 3.19 KB
/
App.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React, { Fragment } from "react";
import {
StyleSheet,
View,
Image,
Text,
TouchableOpacity,
findNodeHandle,
InteractionManager
} from "react-native";
import ValPicker from "react-native-tydligval";
const fontColor = "#000";
const createItems = many => {
const items = [];
let i = 0;
while (i < many + 1) {
items.push({
id: `${i}item`,
value: `${i}Value`,
label: `Value ${i}`
});
i++;
}
return items;
};
const items = createItems(100);
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
selectionOne: items[0].value,
selectionTwo: items[0].value
};
}
onSelect = selected => {
this.setState({
selectionOne: selected.value
});
};
onSelectOther = selected => {
this.setState({
selectionTwo: selected.value
});
};
render() {
return (
<View style={styles.container}>
<Image
style={styles.absolute}
source={require("./assets/desert.jpg")}
/>
<Fragment>
{/* DEFAULT */}
<Fragment>
<Text style={{ color: fontColor }}>Default selector</Text>
<Text style={{ color: fontColor }}>
Selected value: {this.state.selectionOne}
</Text>
<ValPicker
source={require("./assets/desert.jpg")}
key="picker-one"
onSelect={selected => this.onSelect(selected)}
items={items}
color={fontColor}
/>
</Fragment>
{/* CUSTOM */}
<Fragment>
<Text style={{ color: fontColor }}>Customized selector</Text>
<Text style={{ color: fontColor }}>
Selected value: {this.state.selectionTwo}
</Text>
<ValPicker
source={require("./assets/desert.jpg")}
key="picker-two"
onSelect={selected => this.onSelectOther(selected)}
items={items}
triggerButton={(items, onPress, selected) => (
<TouchableOpacity onPress={onPress}>
<Text style={{ color: fontColor, fontWeight: "bold" }}>
{selected ? selected.label : "Select a value -- click here"}
</Text>
</TouchableOpacity>
)}
selectButton={(item, onSelect) => (
<TouchableOpacity key={item.id} onPress={() => onSelect(item)}>
<Text style={{ color: fontColor }}>{item.label}</Text>
</TouchableOpacity>
)}
closeButton={onClose => (
<TouchableOpacity onPress={() => onClose()}>
<Text style={{ color: fontColor, paddingBottom: 55 }}>
Close ME
</Text>
</TouchableOpacity>
)}
/>
</Fragment>
</Fragment>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
zIndex: -1
},
absolute: {
flex: 1,
position: "absolute",
top: 0,
left: 0,
bottom: 0,
right: 0
}
});
export default App;