-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.ios.js
153 lines (149 loc) · 3.84 KB
/
index.ios.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Created by TinySymphony on 2017-01-03.
*/
import React, {Component} from 'react';
import {
View,
Text,
Button,
StyleSheet,
AppRegistry
} from 'react-native';
import LabelSelect from './LabelSelect';
export default class checkbox extends Component {
constructor(props) {
super(props);
this.state = {
arr: [{
name: 'Aspirin',
isSelected: false,
value: 1
}, {
name: 'MarginTop',
isSelected: true,
value: 2
}, {
name: 'Dooper',
isSelected: true,
value: 3
}, {
name: 'Young Skywalker',
isSelected: false,
value: 4
}, {
name: 'Jedi Master',
isSelected: true,
value: 5
}, {
name: 'Anakin',
isSelected: false,
value: 6
}, {
name: 'ナウシカ',
isSelected: false,
value: 7
}, {
name: '你好',
isSelected: false,
value: 8
}]
};
this.selectConfirm = this.selectConfirm.bind(this);
this.deleteItem = this.deleteItem.bind(this);
}
selectConfirm(list) {
let {arr} = this.state;
for (let item of list) {
let index = arr.findIndex(ele => ele === item);
if (~index) arr[index].isSelected = true;
else continue;
}
this.setState({arr: arr});
}
deleteItem(item) {
let {arr} = this.state;
let index = arr.findIndex(a => a === item);
arr[index].isSelected = false;
this.setState({arr: arr});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.text}>Normal LabelSelect</Text>
<LabelSelect
title="Checkbox"
ref="select"
style={styles.labelSelect}
onConfirm={this.selectConfirm}
>
{this.state.arr.filter(item => item.isSelected).map((item, index) =>
<LabelSelect.Label
key={'label-' + index}
data={item}
onCancel={() => {this.deleteItem(item);}}
>{item.name}</LabelSelect.Label>
)}
{this.state.arr.filter(item => !item.isSelected).map((item, index) =>
<LabelSelect.ModalItem
key={'modal-item-' + index}
data={item}
>{item.name}</LabelSelect.ModalItem>
)}
</LabelSelect>
<Text style={styles.text}>ReadOnly LabelSelect</Text>
<LabelSelect
style={styles.labelSelect}
title="Checkbox"
readOnly={true}
onConfirm={this.selectConfirm}
>
{this.state.arr.filter(item => item.isSelected).map((item, index) =>
<LabelSelect.Label
key={'label-' + index}
data={item}
onCancel={() => {this.deleteItem(item);}}
>{item.name}</LabelSelect.Label>
)}
</LabelSelect>
<Text style={styles.text}>Disabled LabelSelect</Text>
<LabelSelect
style={styles.labelSelect}
title="Checkbox"
enable={false}
onConfirm={this.selectConfirm}
>
{this.state.arr.filter(item => item.isSelected).map((item, index) =>
<LabelSelect.Label
key={'label-' + index}
data={item}
onCancel={() => {this.deleteItem(item);}}
>{item.name}</LabelSelect.Label>
)}
</LabelSelect>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 10,
justifyContent: 'center',
alignItems: 'flex-start',
backgroundColor: '#e3eeee'
},
labelSelect: {
marginTop: 5,
marginBottom: 20,
padding: 5,
borderWidth: 1,
borderRadius: 6,
borderStyle: 'dashed',
borderColor: '#6dc2a2'
},
text: {
fontSize: 16,
color: 'rgb(13, 131, 144)'
}
});
AppRegistry.registerComponent('checkbox', () => checkbox);