@@ -12,8 +12,8 @@ import {
12
12
Pressable ,
13
13
Keyboard
14
14
} from 'react-native' ;
15
+ import { MultipleSelectListProps } from ".." ;
15
16
16
- import { MultipleSelectListProps } from '..' ;
17
17
18
18
type L1Keys = { key ?: any ; value ?: any ; disabled ?: boolean | undefined }
19
19
@@ -28,6 +28,7 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
28
28
dropdownTextStyles,
29
29
maxHeight,
30
30
data,
31
+ defaultOptions,
31
32
searchicon = false ,
32
33
arrowicon = false ,
33
34
closeicon = false ,
@@ -58,21 +59,21 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
58
59
59
60
const slidedown = ( ) => {
60
61
setDropdown ( true )
61
-
62
+
62
63
Animated . timing ( animatedvalue , {
63
64
toValue :height ,
64
65
duration :500 ,
65
66
useNativeDriver :false ,
66
-
67
+
67
68
} ) . start ( )
68
69
}
69
70
const slideup = ( ) => {
70
-
71
+
71
72
Animated . timing ( animatedvalue , {
72
73
toValue :0 ,
73
74
duration :500 ,
74
75
useNativeDriver :false ,
75
-
76
+
76
77
} ) . start ( ( ) => setDropdown ( false ) )
77
78
}
78
79
@@ -81,7 +82,7 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
81
82
setHeight ( maxHeight )
82
83
} , [ maxHeight ] )
83
84
84
-
85
+
85
86
React . useEffect ( ( ) => {
86
87
setFilteredData ( data ) ;
87
88
} , [ data ] )
@@ -93,18 +94,25 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
93
94
return ;
94
95
}
95
96
onSelect ( )
96
-
97
+
97
98
} , [ selectedval ] )
98
99
100
+ React . useEffect ( ( ) => {
101
+ if ( defaultOptions && _firstRender ) {
102
+ setSelected ( defaultOptions ) ;
103
+ setSelectedVal ( defaultOptions ) ;
104
+ }
105
+ } )
106
+
99
107
React . useEffect ( ( ) => {
100
108
if ( ! _firstRender ) {
101
109
if ( dropdownShown )
102
110
slidedown ( ) ;
103
111
else
104
112
slideup ( ) ;
105
-
113
+
106
114
}
107
-
115
+
108
116
} , [ dropdownShown ] )
109
117
110
118
@@ -118,20 +126,20 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
118
126
( dropdown && search )
119
127
?
120
128
< View style = { [ styles . wrapper , boxStyles ] } >
121
- < View style = { { flexDirection :'row' , alignItems :'center' , flex :1 } } >
129
+ < View style = { { flexDirection :'row' , alignItems :'center' , flex :1 } } >
122
130
{
123
131
( ! searchicon )
124
132
?
125
- < Image
133
+ < Image
126
134
source = { require ( '../assets/images/search.png' ) }
127
135
resizeMode = 'contain'
128
136
style = { { width :20 , height :20 , marginRight :7 } }
129
137
/>
130
138
:
131
139
searchicon
132
140
}
133
-
134
- < TextInput
141
+
142
+ < TextInput
135
143
placeholder = { searchPlaceholder }
136
144
onChangeText = { ( val ) => {
137
145
let result = data . filter ( ( item : L1Keys ) => {
@@ -150,7 +158,7 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
150
158
{
151
159
( ! closeicon )
152
160
?
153
- < Image
161
+ < Image
154
162
source = { require ( '../assets/images/close.png' ) }
155
163
resizeMode = 'contain'
156
164
style = { { width :17 , height :17 } }
@@ -159,10 +167,10 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
159
167
closeicon
160
168
}
161
169
</ TouchableOpacity >
162
-
163
-
170
+
171
+
164
172
</ View >
165
-
173
+
166
174
</ View >
167
175
:
168
176
@@ -191,18 +199,18 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
191
199
{
192
200
( ! arrowicon )
193
201
?
194
- < Image
202
+ < Image
195
203
source = { require ( '../assets/images/chevron.png' ) }
196
204
resizeMode = 'contain'
197
205
style = { { width :20 , height :20 } }
198
206
/>
199
207
:
200
208
arrowicon
201
209
}
202
-
210
+
203
211
</ TouchableOpacity >
204
212
}
205
-
213
+
206
214
{
207
215
( dropdown )
208
216
?
@@ -221,18 +229,18 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
221
229
return (
222
230
< TouchableOpacity style = { [ styles . disabledoption , disabledItemStyles ] } key = { index } >
223
231
< View style = { [ { width :15 , height :15 , marginRight :10 , borderRadius :3 , justifyContent :'center' , alignItems :'center' , backgroundColor :'#c4c5c6' } , disabledCheckBoxStyles ] } >
224
-
232
+
225
233
{
226
234
( selectedval ?. includes ( value ) )
227
235
?
228
-
229
- < Image
236
+
237
+ < Image
230
238
key = { index }
231
239
source = { require ( '../assets/images/check.png' ) }
232
240
resizeMode = 'contain'
233
241
style = { [ { width :8 , height :8 , paddingLeft :7 } ] }
234
242
/>
235
-
243
+
236
244
:
237
245
null
238
246
@@ -245,7 +253,7 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
245
253
return (
246
254
< TouchableOpacity style = { [ styles . option , dropdownItemStyles ] } key = { index } onPress = { ( ) => {
247
255
248
-
256
+
249
257
let existing = selectedval ?. indexOf ( value )
250
258
251
259
@@ -254,16 +262,16 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
254
262
if ( existing != - 1 && existing != undefined ) {
255
263
256
264
let sv = [ ...selectedval ] ;
257
- sv . splice ( existing , 1 )
265
+ sv . splice ( existing , 1 )
258
266
setSelectedVal ( sv ) ;
259
267
260
268
261
269
setSelected ( ( val : any ) => {
262
270
let temp = [ ...val ] ;
263
- temp . splice ( existing , 1 )
271
+ temp . splice ( existing , 1 )
264
272
return temp ;
265
273
} ) ;
266
-
274
+
267
275
// onSelect()
268
276
} else {
269
277
if ( save === 'value' ) {
@@ -277,62 +285,62 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
277
285
return temp ;
278
286
} )
279
287
}
280
-
288
+
281
289
setSelectedVal ( ( val : any ) => {
282
290
let temp = [ ...new Set ( [ ...val , value ] ) ] ;
283
291
return temp ;
284
292
} )
285
-
286
-
293
+
294
+
287
295
// onSelect()
288
296
}
289
-
290
-
291
-
297
+
298
+
299
+
292
300
} } >
293
301
< View style = { [ { width :15 , height :15 , borderWidth :1 , marginRight :10 , borderColor :'gray' , borderRadius :3 , justifyContent :'center' , alignItems :'center' } , checkBoxStyles ] } >
294
-
302
+
295
303
{
296
304
( selectedval ?. includes ( value ) )
297
305
?
298
-
299
- < Image
306
+
307
+ < Image
300
308
key = { index }
301
309
source = { require ( '../assets/images/check.png' ) }
302
310
resizeMode = 'contain'
303
311
style = { { width :8 , height :8 , paddingLeft :7 } }
304
312
/>
305
-
313
+
306
314
:
307
315
null
308
316
309
317
}
310
-
311
318
312
-
313
-
319
+
320
+
321
+
314
322
</ View >
315
323
< Text style = { [ { fontFamily} , dropdownTextStyles ] } > { value } </ Text >
316
324
</ TouchableOpacity >
317
325
)
318
326
}
319
-
327
+
320
328
} )
321
329
:
322
330
< TouchableOpacity style = { [ styles . option , dropdownItemStyles ] } onPress = { ( ) => {
323
331
setSelected ( undefined )
324
332
setSelectedVal ( "" )
325
333
slideup ( )
326
- setTimeout ( ( ) => setFilteredData ( data ) , 800 )
334
+ setTimeout ( ( ) => setFilteredData ( data ) , 800 )
327
335
} } >
328
336
< Text style = { dropdownTextStyles } > { notFoundText } </ Text >
329
337
</ TouchableOpacity >
330
338
}
331
-
332
-
333
-
339
+
340
+
341
+
334
342
</ ScrollView >
335
-
343
+
336
344
{
337
345
( selectedval ?. length > 0 )
338
346
?
@@ -342,7 +350,7 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
342
350
< View style = { { height : 1 , flex : 1 , backgroundColor : 'gray' } } />
343
351
</ View >
344
352
< View style = { { flexDirection :'row' , paddingHorizontal :20 , marginBottom :20 , flexWrap :'wrap' } } >
345
-
353
+
346
354
{
347
355
selectedval ?. map ( ( item , index ) => {
348
356
return (
@@ -358,17 +366,17 @@ const MultipleSelectList: React.FC<MultipleSelectListProps> = ({
358
366
:
359
367
null
360
368
}
361
-
362
-
363
-
369
+
370
+
371
+
364
372
</ View >
365
-
373
+
366
374
</ Animated . View >
367
375
:
368
376
null
369
377
}
370
-
371
-
378
+
379
+
372
380
</ View >
373
381
)
374
382
}
0 commit comments