ferns-ui 0.23.0 → 0.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FernsProvider.js +3 -1
- package/dist/FernsProvider.js.map +1 -1
- package/dist/PickerSelect.d.ts +28 -93
- package/dist/PickerSelect.js +104 -241
- package/dist/PickerSelect.js.map +1 -1
- package/dist/SelectList.js +1 -1
- package/dist/SelectList.js.map +1 -1
- package/dist/Toast.js +2 -0
- package/dist/Toast.js.map +1 -1
- package/package.json +1 -1
- package/src/FernsProvider.tsx +2 -1
- package/src/PickerSelect.tsx +187 -320
- package/src/SelectList.tsx +1 -1
- package/src/Toast.tsx +3 -0
package/src/PickerSelect.tsx
CHANGED
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
import {Picker} from "@react-native-picker/picker";
|
|
27
27
|
import isEqual from "lodash/isEqual";
|
|
28
|
-
import
|
|
29
|
-
import React, {PureComponent} from "react";
|
|
28
|
+
import React, {useCallback, useEffect, useMemo, useState} from "react";
|
|
30
29
|
import {
|
|
31
30
|
Keyboard,
|
|
32
31
|
Modal,
|
|
@@ -38,7 +37,7 @@ import {
|
|
|
38
37
|
View,
|
|
39
38
|
} from "react-native";
|
|
40
39
|
|
|
41
|
-
const defaultStyles = StyleSheet.create({
|
|
40
|
+
export const defaultStyles = StyleSheet.create({
|
|
42
41
|
viewContainer: {
|
|
43
42
|
alignSelf: "stretch",
|
|
44
43
|
},
|
|
@@ -108,221 +107,142 @@ const defaultStyles = StyleSheet.create({
|
|
|
108
107
|
},
|
|
109
108
|
});
|
|
110
109
|
|
|
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
|
-
// Picker props
|
|
152
|
-
pickerProps: PropTypes.shape({}),
|
|
153
|
-
|
|
154
|
-
// Touchable Done props (iOS only)
|
|
155
|
-
touchableDoneProps: PropTypes.shape({}),
|
|
156
|
-
|
|
157
|
-
// Touchable wrapper props
|
|
158
|
-
touchableWrapperProps: PropTypes.shape({}),
|
|
159
|
-
|
|
160
|
-
// Custom Icon
|
|
161
|
-
Icon: PropTypes.func,
|
|
162
|
-
InputAccessoryView: PropTypes.func,
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
static defaultProps = {
|
|
166
|
-
value: undefined,
|
|
167
|
-
placeholder: {
|
|
168
|
-
label: "Select an item...",
|
|
169
|
-
value: null,
|
|
170
|
-
color: "#9EA0A4",
|
|
171
|
-
},
|
|
172
|
-
disabled: false,
|
|
173
|
-
itemKey: null,
|
|
174
|
-
style: {},
|
|
175
|
-
children: null,
|
|
176
|
-
useNativeAndroidPickerStyle: true,
|
|
177
|
-
fixAndroidTouchableBug: false,
|
|
178
|
-
doneText: "Done",
|
|
179
|
-
onDonePress: null,
|
|
180
|
-
onUpArrow: null,
|
|
181
|
-
onDownArrow: null,
|
|
182
|
-
onOpen: null,
|
|
183
|
-
onClose: null,
|
|
184
|
-
modalProps: {},
|
|
185
|
-
textInputProps: {},
|
|
186
|
-
pickerProps: {},
|
|
187
|
-
touchableDoneProps: {},
|
|
188
|
-
touchableWrapperProps: {},
|
|
189
|
-
Icon: null,
|
|
190
|
-
InputAccessoryView: null,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
inputRef: any;
|
|
110
|
+
interface RNPickerSelectProps {
|
|
111
|
+
onValueChange: (value: any, index: any) => void;
|
|
112
|
+
items: any[];
|
|
113
|
+
value?: any;
|
|
114
|
+
placeholder?: any;
|
|
115
|
+
disabled?: boolean;
|
|
116
|
+
itemKey?: string | number;
|
|
117
|
+
style?: any;
|
|
118
|
+
children?: any;
|
|
119
|
+
onOpen?: () => void;
|
|
120
|
+
useNativeAndroidPickerStyle?: boolean;
|
|
121
|
+
fixAndroidTouchableBug?: boolean;
|
|
122
|
+
|
|
123
|
+
// Custom Modal props (iOS only)
|
|
124
|
+
doneText?: string;
|
|
125
|
+
onDonePress?: () => void;
|
|
126
|
+
onUpArrow?: () => void;
|
|
127
|
+
onDownArrow?: () => void;
|
|
128
|
+
onClose?: () => void;
|
|
129
|
+
|
|
130
|
+
// Modal props (iOS only)
|
|
131
|
+
modalProps?: any;
|
|
132
|
+
|
|
133
|
+
// TextInput props
|
|
134
|
+
textInputProps?: any;
|
|
135
|
+
|
|
136
|
+
// Picker props
|
|
137
|
+
pickerProps?: any;
|
|
138
|
+
|
|
139
|
+
// Touchable Done props (iOS only)
|
|
140
|
+
touchableDoneProps?: any;
|
|
141
|
+
|
|
142
|
+
// Touchable wrapper props
|
|
143
|
+
touchableWrapperProps?: any;
|
|
144
|
+
|
|
145
|
+
// Custom Icon
|
|
146
|
+
Icon?: any;
|
|
147
|
+
InputAccessoryView?: any;
|
|
148
|
+
}
|
|
194
149
|
|
|
195
|
-
|
|
150
|
+
export function RNPickerSelect({
|
|
151
|
+
onValueChange,
|
|
152
|
+
value,
|
|
153
|
+
items,
|
|
154
|
+
placeholder = {
|
|
155
|
+
label: "Select an item...",
|
|
156
|
+
value: null,
|
|
157
|
+
color: "#9EA0A4",
|
|
158
|
+
},
|
|
159
|
+
disabled = false,
|
|
160
|
+
itemKey,
|
|
161
|
+
style = defaultStyles,
|
|
162
|
+
children,
|
|
163
|
+
useNativeAndroidPickerStyle = true,
|
|
164
|
+
fixAndroidTouchableBug = false,
|
|
165
|
+
doneText = "Done",
|
|
166
|
+
onDonePress,
|
|
167
|
+
onUpArrow,
|
|
168
|
+
onDownArrow,
|
|
169
|
+
onOpen,
|
|
170
|
+
onClose,
|
|
171
|
+
modalProps,
|
|
172
|
+
textInputProps,
|
|
173
|
+
pickerProps,
|
|
174
|
+
touchableDoneProps,
|
|
175
|
+
touchableWrapperProps,
|
|
176
|
+
Icon,
|
|
177
|
+
InputAccessoryView,
|
|
178
|
+
}: RNPickerSelectProps) {
|
|
179
|
+
const [selectedItem, setSelectedItem] = useState<any>();
|
|
180
|
+
const [showPicker, setShowPicker] = useState<boolean>(false);
|
|
181
|
+
const [animationType, setAnimationType] = useState(undefined);
|
|
182
|
+
const [orientation, setOrientation] = useState<"portrait" | "landscape">("portrait");
|
|
183
|
+
const [doneDepressed, setDoneDepressed] = useState<boolean>(false);
|
|
184
|
+
|
|
185
|
+
const options = useMemo(() => {
|
|
196
186
|
if (isEqual(placeholder, {})) {
|
|
197
|
-
return [];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
static getSelectedItem({items, key, value}: any) {
|
|
203
|
-
let idx = items.findIndex((item: any) => {
|
|
204
|
-
if (item.key && key) {
|
|
205
|
-
return isEqual(item.key, key);
|
|
206
|
-
}
|
|
207
|
-
return isEqual(item.value, value);
|
|
208
|
-
});
|
|
209
|
-
if (idx === -1) {
|
|
210
|
-
idx = 0;
|
|
187
|
+
return [...items];
|
|
188
|
+
} else {
|
|
189
|
+
return [placeholder, ...items];
|
|
211
190
|
}
|
|
212
|
-
|
|
213
|
-
selectedItem: items[idx] || {},
|
|
214
|
-
idx,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
constructor(props: any) {
|
|
219
|
-
super(props);
|
|
220
|
-
|
|
221
|
-
const items = RNPickerSelect.handlePlaceholder({
|
|
222
|
-
placeholder: props.placeholder,
|
|
223
|
-
}).concat(props.items);
|
|
224
|
-
|
|
225
|
-
const {selectedItem} = RNPickerSelect.getSelectedItem({
|
|
226
|
-
items,
|
|
227
|
-
key: props.itemKey,
|
|
228
|
-
value: props.value,
|
|
229
|
-
});
|
|
191
|
+
}, [items, placeholder]);
|
|
230
192
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
this.onUpArrow = this.onUpArrow.bind(this);
|
|
241
|
-
this.onDownArrow = this.onDownArrow.bind(this);
|
|
242
|
-
this.onValueChange = this.onValueChange.bind(this);
|
|
243
|
-
this.onOrientationChange = this.onOrientationChange.bind(this);
|
|
244
|
-
this.setInputRef = this.setInputRef.bind(this);
|
|
245
|
-
this.togglePicker = this.togglePicker.bind(this);
|
|
246
|
-
this.renderInputAccessoryView = this.renderInputAccessoryView.bind(this);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
componentDidUpdate(prevProps: Readonly<any>, prevState: Readonly<any>) {
|
|
250
|
-
// update items if items or placeholder prop changes
|
|
251
|
-
const items = RNPickerSelect.handlePlaceholder({
|
|
252
|
-
placeholder: this.props.placeholder,
|
|
253
|
-
}).concat(this.props.items);
|
|
254
|
-
const itemsChanged = !isEqual(prevState.items, items);
|
|
255
|
-
|
|
256
|
-
// update selectedItem if value prop is defined and differs from currently selected item
|
|
257
|
-
const {selectedItem, idx} = RNPickerSelect.getSelectedItem({
|
|
258
|
-
items,
|
|
259
|
-
key: this.props.itemKey,
|
|
260
|
-
value: this.props.value,
|
|
261
|
-
});
|
|
262
|
-
const selectedItemChanged =
|
|
263
|
-
!isEqual(this.props.value, undefined) && !isEqual(prevState.selectedItem, selectedItem);
|
|
264
|
-
|
|
265
|
-
if (itemsChanged || selectedItemChanged) {
|
|
266
|
-
this.props.onValueChange(selectedItem.value, idx);
|
|
267
|
-
|
|
268
|
-
this.setState({
|
|
269
|
-
...(itemsChanged ? {items} : {}),
|
|
270
|
-
...(selectedItemChanged ? {selectedItem} : {}),
|
|
193
|
+
const getSelectedItem = useCallback(
|
|
194
|
+
(key, val) => {
|
|
195
|
+
let idx = options.findIndex((item: any) => {
|
|
196
|
+
if (item.key && key) {
|
|
197
|
+
return isEqual(item.key, key);
|
|
198
|
+
}
|
|
199
|
+
return isEqual(item.value, val);
|
|
271
200
|
});
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
onUpArrow() {
|
|
276
|
-
const {onUpArrow} = this.props;
|
|
277
|
-
|
|
278
|
-
this.togglePicker(false, onUpArrow);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
onDownArrow() {
|
|
282
|
-
const {onDownArrow} = this.props;
|
|
283
|
-
|
|
284
|
-
this.togglePicker(false, onDownArrow);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
onValueChange(value: any, index: any) {
|
|
288
|
-
const {onValueChange} = this.props;
|
|
289
|
-
|
|
290
|
-
onValueChange(value, index);
|
|
291
|
-
|
|
292
|
-
this.setState((prevState: any) => {
|
|
201
|
+
if (idx === -1) {
|
|
202
|
+
idx = 0;
|
|
203
|
+
}
|
|
293
204
|
return {
|
|
294
|
-
selectedItem:
|
|
205
|
+
selectedItem: options[idx] || {},
|
|
206
|
+
idx,
|
|
295
207
|
};
|
|
296
|
-
}
|
|
297
|
-
|
|
208
|
+
},
|
|
209
|
+
[options]
|
|
210
|
+
);
|
|
298
211
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
const item = getSelectedItem(itemKey, value);
|
|
214
|
+
setSelectedItem(item.selectedItem);
|
|
215
|
+
}, [getSelectedItem, itemKey, value]);
|
|
216
|
+
|
|
217
|
+
const onUpArrowEvent = () => {
|
|
218
|
+
togglePicker(false, onUpArrow);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const onDownArrowEvent = () => {
|
|
222
|
+
togglePicker(false, onDownArrow);
|
|
223
|
+
};
|
|
304
224
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
225
|
+
const onValueChangeEvent = (val: any, index: any) => {
|
|
226
|
+
const item = getSelectedItem(itemKey, val);
|
|
227
|
+
onValueChange(val, index);
|
|
228
|
+
setSelectedItem(item.selectedItem);
|
|
229
|
+
};
|
|
308
230
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
231
|
+
const onOrientationChange = ({nativeEvent}: any) => {
|
|
232
|
+
setOrientation(nativeEvent.orientation);
|
|
233
|
+
};
|
|
312
234
|
|
|
313
|
-
|
|
235
|
+
const getPlaceholderStyle = () => {
|
|
236
|
+
if (!isEqual(placeholder, {}) && selectedItem?.label === placeholder?.label) {
|
|
314
237
|
return {
|
|
315
238
|
...defaultStyles.placeholder,
|
|
316
|
-
...style
|
|
239
|
+
...style?.placeholder,
|
|
317
240
|
};
|
|
318
241
|
}
|
|
319
242
|
return {};
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
triggerOpenCloseCallbacks() {
|
|
323
|
-
const {onOpen, onClose} = this.props;
|
|
324
|
-
const {showPicker} = this.state;
|
|
243
|
+
};
|
|
325
244
|
|
|
245
|
+
const triggerOpenCloseCallbacks = () => {
|
|
326
246
|
if (!showPicker && onOpen) {
|
|
327
247
|
onOpen();
|
|
328
248
|
}
|
|
@@ -330,12 +250,9 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
330
250
|
if (showPicker && onClose) {
|
|
331
251
|
onClose();
|
|
332
252
|
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
togglePicker(animate = false, postToggleCallback?: any) {
|
|
336
|
-
const {modalProps, disabled} = this.props;
|
|
337
|
-
const {showPicker} = this.state;
|
|
253
|
+
};
|
|
338
254
|
|
|
255
|
+
const togglePicker = (animate = false, postToggleCallback?: any) => {
|
|
339
256
|
if (disabled) {
|
|
340
257
|
return;
|
|
341
258
|
}
|
|
@@ -344,30 +261,20 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
344
261
|
Keyboard.dismiss();
|
|
345
262
|
}
|
|
346
263
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
this.triggerOpenCloseCallbacks();
|
|
351
|
-
|
|
352
|
-
this.setState(
|
|
353
|
-
(prevState: any) => {
|
|
354
|
-
return {
|
|
355
|
-
animationType: animate ? animationType : undefined,
|
|
356
|
-
showPicker: !prevState.showPicker,
|
|
357
|
-
};
|
|
358
|
-
},
|
|
359
|
-
() => {
|
|
360
|
-
if (postToggleCallback) {
|
|
361
|
-
postToggleCallback();
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
);
|
|
365
|
-
}
|
|
264
|
+
setAnimationType(modalProps && modalProps?.animationType ? modalProps?.animationType : "slide");
|
|
265
|
+
|
|
266
|
+
triggerOpenCloseCallbacks();
|
|
366
267
|
|
|
367
|
-
|
|
368
|
-
|
|
268
|
+
setAnimationType(animate ? animationType : undefined);
|
|
269
|
+
setShowPicker(!showPicker);
|
|
270
|
+
|
|
271
|
+
if (postToggleCallback) {
|
|
272
|
+
postToggleCallback();
|
|
273
|
+
}
|
|
274
|
+
};
|
|
369
275
|
|
|
370
|
-
|
|
276
|
+
const renderPickerItems = () => {
|
|
277
|
+
return options?.map((item: any) => {
|
|
371
278
|
return (
|
|
372
279
|
<Picker.Item
|
|
373
280
|
key={item.key || item.label}
|
|
@@ -377,21 +284,9 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
377
284
|
/>
|
|
378
285
|
);
|
|
379
286
|
});
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
renderInputAccessoryView() {
|
|
383
|
-
const {
|
|
384
|
-
InputAccessoryView,
|
|
385
|
-
doneText,
|
|
386
|
-
onUpArrow,
|
|
387
|
-
onDownArrow,
|
|
388
|
-
onDonePress,
|
|
389
|
-
style,
|
|
390
|
-
touchableDoneProps,
|
|
391
|
-
} = this.props;
|
|
392
|
-
|
|
393
|
-
const {doneDepressed} = this.state;
|
|
287
|
+
};
|
|
394
288
|
|
|
289
|
+
const renderInputAccessoryView = () => {
|
|
395
290
|
if (InputAccessoryView) {
|
|
396
291
|
return <InputAccessoryView testID="custom_input_accessory_view" />;
|
|
397
292
|
}
|
|
@@ -404,7 +299,7 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
404
299
|
<View style={[defaultStyles.chevronContainer, style.chevronContainer]}>
|
|
405
300
|
<TouchableOpacity
|
|
406
301
|
activeOpacity={onUpArrow ? 0.5 : 1}
|
|
407
|
-
onPress={onUpArrow ?
|
|
302
|
+
onPress={onUpArrow ? onUpArrowEvent : undefined}
|
|
408
303
|
>
|
|
409
304
|
<View
|
|
410
305
|
style={[
|
|
@@ -418,7 +313,7 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
418
313
|
</TouchableOpacity>
|
|
419
314
|
<TouchableOpacity
|
|
420
315
|
activeOpacity={onDownArrow ? 0.5 : 1}
|
|
421
|
-
onPress={onDownArrow ?
|
|
316
|
+
onPress={onDownArrow ? onDownArrowEvent : undefined}
|
|
422
317
|
>
|
|
423
318
|
<View
|
|
424
319
|
style={[
|
|
@@ -435,13 +330,13 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
435
330
|
hitSlop={{top: 4, right: 4, bottom: 4, left: 4}}
|
|
436
331
|
testID="done_button"
|
|
437
332
|
onPress={() => {
|
|
438
|
-
|
|
333
|
+
togglePicker(true, onDonePress);
|
|
439
334
|
}}
|
|
440
335
|
onPressIn={() => {
|
|
441
|
-
|
|
336
|
+
setDoneDepressed(true);
|
|
442
337
|
}}
|
|
443
338
|
onPressOut={() => {
|
|
444
|
-
|
|
339
|
+
setDoneDepressed(false);
|
|
445
340
|
}}
|
|
446
341
|
{...touchableDoneProps}
|
|
447
342
|
>
|
|
@@ -461,11 +356,9 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
461
356
|
</TouchableOpacity>
|
|
462
357
|
</View>
|
|
463
358
|
);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
renderIcon() {
|
|
467
|
-
const {style, Icon} = this.props;
|
|
359
|
+
};
|
|
468
360
|
|
|
361
|
+
const renderIcon = () => {
|
|
469
362
|
if (!Icon) {
|
|
470
363
|
return null;
|
|
471
364
|
}
|
|
@@ -475,12 +368,9 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
475
368
|
<Icon testID="icon" />
|
|
476
369
|
</View>
|
|
477
370
|
);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
renderTextInputOrChildren() {
|
|
481
|
-
const {children, style, textInputProps} = this.props;
|
|
482
|
-
const {selectedItem} = this.state;
|
|
371
|
+
};
|
|
483
372
|
|
|
373
|
+
const renderTextInputOrChildren = () => {
|
|
484
374
|
const containerStyle =
|
|
485
375
|
Platform.OS === "ios" ? style.inputIOSContainer : style.inputAndroidContainer;
|
|
486
376
|
|
|
@@ -495,25 +385,21 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
495
385
|
return (
|
|
496
386
|
<View pointerEvents="box-only" style={containerStyle}>
|
|
497
387
|
<TextInput
|
|
498
|
-
ref={this.setInputRef}
|
|
499
388
|
editable={false}
|
|
500
389
|
style={[
|
|
501
390
|
Platform.OS === "ios" ? style.inputIOS : style.inputAndroid,
|
|
502
|
-
|
|
391
|
+
getPlaceholderStyle(),
|
|
503
392
|
]}
|
|
504
393
|
testID="text_input"
|
|
505
|
-
value={selectedItem
|
|
394
|
+
value={selectedItem?.inputLabel ? selectedItem?.inputLabel : selectedItem?.label}
|
|
506
395
|
{...textInputProps}
|
|
507
396
|
/>
|
|
508
|
-
{
|
|
397
|
+
{renderIcon()}
|
|
509
398
|
</View>
|
|
510
399
|
);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
renderIOS() {
|
|
514
|
-
const {style, modalProps, pickerProps, touchableWrapperProps} = this.props;
|
|
515
|
-
const {animationType, orientation, selectedItem, showPicker} = this.state;
|
|
400
|
+
};
|
|
516
401
|
|
|
402
|
+
const renderIOS = () => {
|
|
517
403
|
return (
|
|
518
404
|
<View style={[defaultStyles.viewContainer, style.viewContainer]}>
|
|
519
405
|
<TouchableOpacity
|
|
@@ -527,11 +413,11 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
527
413
|
}}
|
|
528
414
|
testID="ios_touchable_wrapper"
|
|
529
415
|
onPress={() => {
|
|
530
|
-
|
|
416
|
+
togglePicker(true);
|
|
531
417
|
}}
|
|
532
418
|
{...touchableWrapperProps}
|
|
533
419
|
>
|
|
534
|
-
{
|
|
420
|
+
{renderTextInputOrChildren()}
|
|
535
421
|
</TouchableOpacity>
|
|
536
422
|
<Modal
|
|
537
423
|
animationType={animationType}
|
|
@@ -539,17 +425,17 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
539
425
|
testID="ios_modal"
|
|
540
426
|
transparent
|
|
541
427
|
visible={showPicker}
|
|
542
|
-
onOrientationChange={
|
|
428
|
+
onOrientationChange={onOrientationChange}
|
|
543
429
|
{...modalProps}
|
|
544
430
|
>
|
|
545
431
|
<TouchableOpacity
|
|
546
432
|
style={[defaultStyles.modalViewTop, style.modalViewTop]}
|
|
547
433
|
testID="ios_modal_top"
|
|
548
434
|
onPress={() => {
|
|
549
|
-
|
|
435
|
+
togglePicker(true);
|
|
550
436
|
}}
|
|
551
437
|
/>
|
|
552
|
-
{
|
|
438
|
+
{renderInputAccessoryView()}
|
|
553
439
|
<View
|
|
554
440
|
style={[
|
|
555
441
|
defaultStyles.modalViewBottom,
|
|
@@ -558,31 +444,20 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
558
444
|
]}
|
|
559
445
|
>
|
|
560
446
|
<Picker
|
|
561
|
-
selectedValue={selectedItem
|
|
447
|
+
selectedValue={selectedItem?.value}
|
|
562
448
|
testID="ios_picker"
|
|
563
|
-
onValueChange={
|
|
449
|
+
onValueChange={onValueChangeEvent}
|
|
564
450
|
{...pickerProps}
|
|
565
451
|
>
|
|
566
|
-
{
|
|
452
|
+
{renderPickerItems()}
|
|
567
453
|
</Picker>
|
|
568
454
|
</View>
|
|
569
455
|
</Modal>
|
|
570
456
|
</View>
|
|
571
457
|
);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
renderAndroidHeadless() {
|
|
575
|
-
const {
|
|
576
|
-
disabled,
|
|
577
|
-
Icon,
|
|
578
|
-
style,
|
|
579
|
-
pickerProps,
|
|
580
|
-
onOpen,
|
|
581
|
-
touchableWrapperProps,
|
|
582
|
-
fixAndroidTouchableBug,
|
|
583
|
-
} = this.props;
|
|
584
|
-
const {selectedItem} = this.state;
|
|
458
|
+
};
|
|
585
459
|
|
|
460
|
+
const renderAndroidHeadless = () => {
|
|
586
461
|
const Component: any = fixAndroidTouchableBug ? View : TouchableOpacity;
|
|
587
462
|
return (
|
|
588
463
|
<Component
|
|
@@ -592,90 +467,82 @@ export default class RNPickerSelect extends PureComponent<any, any> {
|
|
|
592
467
|
{...touchableWrapperProps}
|
|
593
468
|
>
|
|
594
469
|
<View style={style.headlessAndroidContainer}>
|
|
595
|
-
{
|
|
470
|
+
{renderTextInputOrChildren()}
|
|
596
471
|
<Picker
|
|
597
472
|
enabled={!disabled}
|
|
598
|
-
selectedValue={selectedItem
|
|
473
|
+
selectedValue={selectedItem?.value}
|
|
599
474
|
style={[
|
|
600
475
|
Icon ? {backgroundColor: "transparent"} : {}, // to hide native icon
|
|
601
476
|
defaultStyles.headlessAndroidPicker,
|
|
602
477
|
style.headlessAndroidPicker,
|
|
603
478
|
]}
|
|
604
479
|
testID="android_picker_headless"
|
|
605
|
-
onValueChange={
|
|
480
|
+
onValueChange={onValueChangeEvent}
|
|
606
481
|
{...pickerProps}
|
|
607
482
|
>
|
|
608
|
-
{
|
|
483
|
+
{renderPickerItems()}
|
|
609
484
|
</Picker>
|
|
610
485
|
</View>
|
|
611
486
|
</Component>
|
|
612
487
|
);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
renderAndroidNativePickerStyle() {
|
|
616
|
-
const {disabled, Icon, style, pickerProps} = this.props;
|
|
617
|
-
const {selectedItem} = this.state;
|
|
488
|
+
};
|
|
618
489
|
|
|
490
|
+
const renderAndroidNativePickerStyle = () => {
|
|
619
491
|
return (
|
|
620
492
|
<View style={[defaultStyles.viewContainer, style.viewContainer]}>
|
|
621
493
|
<Picker
|
|
622
494
|
enabled={!disabled}
|
|
623
|
-
selectedValue={selectedItem
|
|
495
|
+
selectedValue={selectedItem?.value}
|
|
624
496
|
style={[
|
|
625
497
|
Icon ? {backgroundColor: "transparent"} : {}, // to hide native icon
|
|
626
498
|
style.inputAndroid,
|
|
627
499
|
{width: "100%"},
|
|
628
|
-
|
|
500
|
+
getPlaceholderStyle(),
|
|
629
501
|
]}
|
|
630
502
|
testID="android_picker"
|
|
631
|
-
onValueChange={
|
|
503
|
+
onValueChange={onValueChangeEvent}
|
|
632
504
|
{...pickerProps}
|
|
633
505
|
>
|
|
634
|
-
{
|
|
506
|
+
{renderPickerItems()}
|
|
635
507
|
</Picker>
|
|
636
|
-
{
|
|
508
|
+
{renderIcon()}
|
|
637
509
|
</View>
|
|
638
510
|
);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
renderWeb() {
|
|
642
|
-
const {disabled, style, pickerProps} = this.props;
|
|
643
|
-
const {selectedItem} = this.state;
|
|
511
|
+
};
|
|
644
512
|
|
|
513
|
+
const renderWeb = () => {
|
|
645
514
|
return (
|
|
646
515
|
<View style={[defaultStyles.viewContainer, style.viewContainer]}>
|
|
647
516
|
<Picker
|
|
648
517
|
enabled={!disabled}
|
|
649
|
-
selectedValue={selectedItem
|
|
518
|
+
selectedValue={selectedItem?.value}
|
|
650
519
|
style={[{width: "100%", height: "100%", border: "none"}, style.inputWeb]}
|
|
651
520
|
testID="web_picker"
|
|
652
|
-
onValueChange={
|
|
521
|
+
onValueChange={onValueChangeEvent}
|
|
653
522
|
{...pickerProps}
|
|
654
523
|
>
|
|
655
|
-
{
|
|
524
|
+
{renderPickerItems()}
|
|
656
525
|
</Picker>
|
|
657
|
-
{
|
|
526
|
+
{renderIcon()}
|
|
658
527
|
</View>
|
|
659
528
|
);
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
render() {
|
|
663
|
-
const {children, useNativeAndroidPickerStyle} = this.props;
|
|
529
|
+
};
|
|
664
530
|
|
|
531
|
+
const render = () => {
|
|
665
532
|
if (Platform.OS === "ios") {
|
|
666
|
-
return
|
|
533
|
+
return renderIOS();
|
|
667
534
|
}
|
|
668
535
|
|
|
669
536
|
if (Platform.OS === "web") {
|
|
670
|
-
return
|
|
537
|
+
return renderWeb();
|
|
671
538
|
}
|
|
672
539
|
|
|
673
540
|
if (children || !useNativeAndroidPickerStyle) {
|
|
674
|
-
return
|
|
541
|
+
return renderAndroidHeadless();
|
|
675
542
|
}
|
|
676
543
|
|
|
677
|
-
return
|
|
678
|
-
}
|
|
679
|
-
}
|
|
544
|
+
return renderAndroidNativePickerStyle();
|
|
545
|
+
};
|
|
680
546
|
|
|
681
|
-
|
|
547
|
+
return render();
|
|
548
|
+
}
|