@draftbit/core 48.4.8-41fa1b.2 → 48.4.8-618b68.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/lib/commonjs/components/Picker/Picker.js +1 -1
- package/lib/commonjs/components/PinInput/PinInput.js +1 -1
- package/lib/commonjs/components/SectionList/SectionList.js +1 -1
- package/lib/commonjs/components/TextField.js +1 -1
- package/lib/typescript/src/components/Picker/Picker.d.ts +4 -10
- package/lib/typescript/src/components/Picker/Picker.js +84 -243
- package/lib/typescript/src/components/Picker/Picker.js.map +1 -1
- package/lib/typescript/src/components/PinInput/PinInput.d.ts +6 -2
- package/lib/typescript/src/components/PinInput/PinInput.js +15 -16
- package/lib/typescript/src/components/PinInput/PinInput.js.map +1 -1
- package/lib/typescript/src/components/SectionList/SectionList.d.ts +2 -1
- package/lib/typescript/src/components/SectionList/SectionList.js +13 -3
- package/lib/typescript/src/components/SectionList/SectionList.js.map +1 -1
- package/lib/typescript/src/components/TextField.d.ts +3 -3
- package/lib/typescript/src/components/TextField.js +9 -6
- package/lib/typescript/src/components/TextField.js.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/Picker/Picker.js +84 -243
- package/src/components/Picker/Picker.js.map +1 -1
- package/src/components/Picker/Picker.tsx +134 -401
- package/src/components/PinInput/PinInput.js +15 -16
- package/src/components/PinInput/PinInput.js.map +1 -1
- package/src/components/PinInput/PinInput.tsx +26 -20
- package/src/components/SectionList/SectionList.js +13 -3
- package/src/components/SectionList/SectionList.js.map +1 -1
- package/src/components/SectionList/SectionList.tsx +15 -0
- package/src/components/TextField.js +9 -6
- package/src/components/TextField.js.map +1 -1
- package/src/components/TextField.tsx +14 -8
- package/lib/commonjs/components/Picker/PickerComponent.android.js +0 -1
- package/lib/commonjs/components/Picker/PickerComponent.ios.js +0 -1
- package/lib/commonjs/components/Picker/PickerComponent.web.js +0 -1
- package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +0 -6
- package/lib/typescript/src/components/Picker/PickerComponent.android.js +0 -70
- package/lib/typescript/src/components/Picker/PickerComponent.android.js.map +0 -1
- package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +0 -7
- package/lib/typescript/src/components/Picker/PickerComponent.ios.js +0 -80
- package/lib/typescript/src/components/Picker/PickerComponent.ios.js.map +0 -1
- package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +0 -6
- package/lib/typescript/src/components/Picker/PickerComponent.web.js +0 -71
- package/lib/typescript/src/components/Picker/PickerComponent.web.js.map +0 -1
- package/src/components/Picker/PickerComponent.android.js +0 -70
- package/src/components/Picker/PickerComponent.android.js.map +0 -1
- package/src/components/Picker/PickerComponent.android.tsx +0 -116
- package/src/components/Picker/PickerComponent.ios.js +0 -80
- package/src/components/Picker/PickerComponent.ios.js.map +0 -1
- package/src/components/Picker/PickerComponent.ios.tsx +0 -142
- package/src/components/Picker/PickerComponent.web.js +0 -71
- package/src/components/Picker/PickerComponent.web.js.map +0 -1
- package/src/components/Picker/PickerComponent.web.tsx +0 -117
|
@@ -2,29 +2,26 @@ import * as React from "react";
|
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
StyleSheet,
|
|
5
|
-
Text,
|
|
6
5
|
Platform,
|
|
7
6
|
ViewStyle,
|
|
8
7
|
StyleProp,
|
|
9
|
-
Dimensions,
|
|
10
8
|
Keyboard,
|
|
11
9
|
} from "react-native";
|
|
12
|
-
import {
|
|
10
|
+
import { isObject } from "lodash";
|
|
13
11
|
import { SafeAreaView } from "react-native-safe-area-context";
|
|
14
12
|
import { Picker as NativePicker } from "@react-native-picker/picker";
|
|
15
|
-
|
|
16
|
-
import { withTheme } from "../../theming";
|
|
17
13
|
import Portal from "../Portal/Portal";
|
|
18
|
-
import Button from "
|
|
14
|
+
import { Button } from "../Button";
|
|
19
15
|
import Touchable from "../Touchable";
|
|
20
|
-
import type { Theme } from "../../styles/DefaultTheme";
|
|
21
16
|
import type { IconSlot } from "../../interfaces/Icon";
|
|
22
17
|
import {
|
|
23
|
-
extractStyles,
|
|
24
18
|
extractBorderAndMarginStyles,
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
extractSizeStyles,
|
|
20
|
+
extractFlexItemStyles,
|
|
21
|
+
extractPositionStyles,
|
|
27
22
|
} from "../../utilities";
|
|
23
|
+
import TextField from "../TextField";
|
|
24
|
+
import omit from "lodash.omit";
|
|
28
25
|
|
|
29
26
|
export interface PickerOption {
|
|
30
27
|
value: string;
|
|
@@ -38,8 +35,7 @@ export type PickerProps = {
|
|
|
38
35
|
style?: StyleProp<ViewStyle> & { height?: number };
|
|
39
36
|
value?: string;
|
|
40
37
|
options: PickerOption[] | string[];
|
|
41
|
-
onValueChange: (value: string
|
|
42
|
-
defaultValue?: string;
|
|
38
|
+
onValueChange: (value: string) => void;
|
|
43
39
|
assistiveText?: string;
|
|
44
40
|
label?: string;
|
|
45
41
|
iconColor?: string;
|
|
@@ -50,427 +46,145 @@ export type PickerProps = {
|
|
|
50
46
|
rightIconName?: string;
|
|
51
47
|
type?: "solid" | "underline";
|
|
52
48
|
autoDismissKeyboard?: boolean;
|
|
53
|
-
|
|
54
|
-
Icon: IconSlot["Icon"];
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
function normalizeOptions(options: PickerProps["options"]): PickerOption[] {
|
|
58
|
-
if (options.length === 0) {
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (typeof options[0] === ("string" || "number")) {
|
|
63
|
-
return (options as string[]).map((option) => ({
|
|
64
|
-
label: String(option),
|
|
65
|
-
value: String(option),
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
isObject(options[0]) &&
|
|
71
|
-
options[0].value !== null &&
|
|
72
|
-
options[0].label !== null
|
|
73
|
-
) {
|
|
74
|
-
return (options as PickerOption[]).map((option) => {
|
|
75
|
-
return {
|
|
76
|
-
label: String(option.label),
|
|
77
|
-
value: String(option.value),
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
}
|
|
49
|
+
} & IconSlot;
|
|
81
50
|
|
|
82
|
-
throw new Error(
|
|
83
|
-
'Picker options must be either an array of strings or array of { "label": string; "value": string; } objects.'
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const { width: deviceWidth, height: deviceHeight } = Dimensions.get("screen");
|
|
88
51
|
const isIos = Platform.OS === "ios";
|
|
89
52
|
const isWeb = Platform.OS === "web";
|
|
90
53
|
|
|
91
|
-
const unstyledColor = "rgba(165, 173, 183, 1)";
|
|
92
|
-
const disabledColor = "rgb(240, 240, 240)";
|
|
93
|
-
const errorColor = "rgba(255, 69, 100, 1)";
|
|
94
|
-
|
|
95
|
-
//Empty string for 'value' is treated as a non-value
|
|
96
|
-
//reason: Draftbit uses empty string as initial value for string state*/
|
|
97
54
|
const Picker: React.FC<PickerProps> = ({
|
|
98
|
-
|
|
99
|
-
options = [],
|
|
55
|
+
options: optionsProp = [],
|
|
100
56
|
onValueChange,
|
|
101
|
-
defaultValue,
|
|
102
57
|
Icon,
|
|
103
58
|
style,
|
|
104
59
|
placeholder,
|
|
105
60
|
value,
|
|
106
61
|
disabled = false,
|
|
107
|
-
assistiveText,
|
|
108
|
-
label,
|
|
109
|
-
iconColor = unstyledColor,
|
|
110
|
-
iconSize = 24,
|
|
111
|
-
leftIconMode = "inset",
|
|
112
|
-
leftIconName,
|
|
113
|
-
placeholderTextColor = unstyledColor,
|
|
114
|
-
rightIconName,
|
|
115
|
-
type = "solid",
|
|
116
62
|
autoDismissKeyboard = true,
|
|
63
|
+
...rest
|
|
117
64
|
}) => {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const [internalValue, setInternalValue] = React.useState<string | undefined>(
|
|
121
|
-
value || defaultValue
|
|
122
|
-
);
|
|
65
|
+
const pickerRef = React.useRef<NativePicker<string>>(null);
|
|
123
66
|
|
|
124
67
|
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
125
68
|
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
React.useEffect(() => {
|
|
131
|
-
if (value != null && value !== "") {
|
|
132
|
-
setInternalValue(value);
|
|
133
|
-
} else if (value === "") {
|
|
134
|
-
setInternalValue(undefined);
|
|
135
|
-
}
|
|
136
|
-
}, [value]);
|
|
69
|
+
const options = React.useMemo(() => {
|
|
70
|
+
const normalizedOptions = normalizeToPickerOptions(optionsProp);
|
|
137
71
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
72
|
+
// Underlying Picker component defaults selection to first element when value is not provided (or undefined)
|
|
73
|
+
// Placholder must be the 1st option in order to allow selection of the 'actual' 1st option
|
|
74
|
+
if (placeholder) {
|
|
75
|
+
return [{ label: placeholder, value: placeholder }, ...normalizedOptions];
|
|
76
|
+
} else {
|
|
77
|
+
return normalizedOptions;
|
|
141
78
|
}
|
|
142
|
-
}, [
|
|
79
|
+
}, [placeholder, optionsProp]);
|
|
143
80
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
}, [pickerVisible, androidPickerRef]);
|
|
149
|
-
|
|
150
|
-
React.useEffect(() => {
|
|
151
|
-
if (pickerVisible && autoDismissKeyboard) {
|
|
152
|
-
Keyboard.dismiss();
|
|
153
|
-
}
|
|
154
|
-
}, [pickerVisible, autoDismissKeyboard]);
|
|
155
|
-
|
|
156
|
-
const normalizedOptions = React.useMemo(
|
|
157
|
-
() => normalizeOptions(options),
|
|
158
|
-
[options]
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
//Underlying Picker component defaults selection to first element when value is not provided (or undefined)
|
|
162
|
-
//Placholder must be the 1st option in order to allow selection of the 'actual' 1st option
|
|
163
|
-
const pickerOptions = React.useMemo(
|
|
164
|
-
() =>
|
|
165
|
-
placeholder
|
|
166
|
-
? [{ label: placeholder, value: placeholder }, ...normalizedOptions]
|
|
167
|
-
: normalizedOptions,
|
|
168
|
-
[placeholder, normalizedOptions]
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
//When no placeholder is provided then first item should be marked selected to reflect underlying Picker internal state
|
|
172
|
-
if (
|
|
173
|
-
!placeholder &&
|
|
174
|
-
pickerOptions.length &&
|
|
175
|
-
!internalValue &&
|
|
176
|
-
internalValue !== pickerOptions[0].value //Prevent infinite state changes incase first value is falsy
|
|
177
|
-
) {
|
|
178
|
-
onValueChange?.(pickerOptions[0].value, 0);
|
|
179
|
-
setInternalValue(pickerOptions[0].value);
|
|
81
|
+
// When no placeholder is provided then first item should be marked selected to reflect underlying Picker internal state
|
|
82
|
+
if (!placeholder && options.length && !value && value !== options[0].value) {
|
|
83
|
+
onValueChange?.(options[0].value);
|
|
180
84
|
}
|
|
181
85
|
|
|
182
|
-
const { viewStyles, textStyles } = extractStyles(style);
|
|
183
|
-
|
|
184
|
-
const additionalBorderStyles = ["backgroundColor"];
|
|
185
|
-
|
|
186
|
-
const additionalMarginStyles = [
|
|
187
|
-
"bottom",
|
|
188
|
-
"height",
|
|
189
|
-
"left",
|
|
190
|
-
"maxHeight",
|
|
191
|
-
"maxWidth",
|
|
192
|
-
"minHeight",
|
|
193
|
-
"minWidth",
|
|
194
|
-
"overflow",
|
|
195
|
-
"position",
|
|
196
|
-
"right",
|
|
197
|
-
"top",
|
|
198
|
-
"width",
|
|
199
|
-
"zIndex",
|
|
200
|
-
];
|
|
201
|
-
|
|
202
|
-
const {
|
|
203
|
-
borderStyles: extractedBorderStyles,
|
|
204
|
-
marginStyles: extractedMarginStyles,
|
|
205
|
-
} = extractBorderAndMarginStyles(
|
|
206
|
-
viewStyles,
|
|
207
|
-
additionalBorderStyles,
|
|
208
|
-
additionalMarginStyles
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
const borderStyles = {
|
|
212
|
-
...{
|
|
213
|
-
...(type === "solid"
|
|
214
|
-
? {
|
|
215
|
-
borderTopLeftRadius: 5,
|
|
216
|
-
borderTopRightRadius: 5,
|
|
217
|
-
borderBottomRightRadius: 5,
|
|
218
|
-
borderBottomLeftRadius: 5,
|
|
219
|
-
borderTopWidth: 1,
|
|
220
|
-
borderRightWidth: 1,
|
|
221
|
-
borderLeftWidth: 1,
|
|
222
|
-
}
|
|
223
|
-
: {}),
|
|
224
|
-
borderBottomWidth: 1,
|
|
225
|
-
borderColor: unstyledColor,
|
|
226
|
-
borderStyle: "solid",
|
|
227
|
-
},
|
|
228
|
-
...extractedBorderStyles,
|
|
229
|
-
...(error ? { borderColor: errorColor } : {}),
|
|
230
|
-
...(disabled
|
|
231
|
-
? { borderColor: "transparent", backgroundColor: disabledColor }
|
|
232
|
-
: {}),
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const marginStyles = {
|
|
236
|
-
height: 60,
|
|
237
|
-
...extractedMarginStyles,
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
const stylesWithoutBordersAndMargins = omit(viewStyles, [
|
|
241
|
-
...borderStyleNames,
|
|
242
|
-
...marginStyleNames,
|
|
243
|
-
...additionalBorderStyles,
|
|
244
|
-
...additionalMarginStyles,
|
|
245
|
-
]);
|
|
246
|
-
|
|
247
86
|
const selectedLabel =
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
{
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
<Icon
|
|
271
|
-
name={leftIconName}
|
|
272
|
-
color={disabled ? unstyledColor : iconColor}
|
|
273
|
-
size={iconSize}
|
|
274
|
-
style={{
|
|
275
|
-
marginRight: 4,
|
|
276
|
-
marginLeft: 4,
|
|
277
|
-
}}
|
|
278
|
-
/>
|
|
279
|
-
) : null;
|
|
280
|
-
|
|
281
|
-
const rightIcon = rightIconName ? (
|
|
282
|
-
<Icon
|
|
283
|
-
name={rightIconName}
|
|
284
|
-
color={disabled ? unstyledColor : iconColor}
|
|
285
|
-
size={iconSize}
|
|
286
|
-
style={{
|
|
287
|
-
marginRight: -10,
|
|
288
|
-
marginLeft: 8,
|
|
289
|
-
}}
|
|
290
|
-
/>
|
|
291
|
-
) : null;
|
|
292
|
-
|
|
293
|
-
const textAlign = textStyles?.textAlign;
|
|
294
|
-
|
|
295
|
-
const calculateLeftPadding = () => {
|
|
296
|
-
if (leftIconOutset) {
|
|
297
|
-
if (textAlign === "center") {
|
|
298
|
-
return iconSize - Math.abs(8 - iconSize);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return iconSize + 8;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return 0;
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const assistiveTextLabel = assistiveText ? (
|
|
308
|
-
<Text
|
|
309
|
-
style={{
|
|
310
|
-
textAlign,
|
|
311
|
-
width: "100%",
|
|
312
|
-
paddingLeft: calculateLeftPadding(),
|
|
313
|
-
color: unstyledColor,
|
|
314
|
-
fontSize: 12,
|
|
315
|
-
paddingTop: 4,
|
|
87
|
+
options.find((option) => option.value === String(value))?.label ||
|
|
88
|
+
value ||
|
|
89
|
+
placeholder;
|
|
90
|
+
|
|
91
|
+
const containerStyle = StyleSheet.flatten([
|
|
92
|
+
extractSizeStyles(style),
|
|
93
|
+
extractPositionStyles(style),
|
|
94
|
+
extractFlexItemStyles(style),
|
|
95
|
+
extractBorderAndMarginStyles(style).marginStyles,
|
|
96
|
+
]);
|
|
97
|
+
const textFieldStyle = omit(style, Object.keys(containerStyle));
|
|
98
|
+
|
|
99
|
+
const renderNativePicker = () => (
|
|
100
|
+
<NativePicker
|
|
101
|
+
ref={pickerRef}
|
|
102
|
+
selectedValue={value}
|
|
103
|
+
onValueChange={(newValue) => {
|
|
104
|
+
if (newValue !== placeholder) {
|
|
105
|
+
onValueChange?.(newValue);
|
|
106
|
+
} else if (newValue === placeholder) {
|
|
107
|
+
onValueChange?.("");
|
|
108
|
+
}
|
|
316
109
|
}}
|
|
110
|
+
style={[
|
|
111
|
+
styles.nativePicker,
|
|
112
|
+
isIos ? styles.iosNativePicker : styles.nonIosPicker,
|
|
113
|
+
]}
|
|
114
|
+
onBlur={() => setPickerVisible(false)}
|
|
317
115
|
>
|
|
318
|
-
{
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
...(disabled ? { color: unstyledColor } : {}),
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
const handleValueChange = (newValue: string, itemIndex: number) => {
|
|
331
|
-
if (newValue !== "" && newValue !== placeholder) {
|
|
332
|
-
onValueChange?.(newValue, itemIndex);
|
|
333
|
-
setInternalValue(newValue);
|
|
334
|
-
} else if (newValue === placeholder) {
|
|
335
|
-
onValueChange?.("", 0);
|
|
336
|
-
setInternalValue(undefined);
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
return (
|
|
341
|
-
/* marginsContainer */
|
|
342
|
-
<View style={[styles.marginsContainer, marginStyles]}>
|
|
343
|
-
{/* touchableContainer */}
|
|
344
|
-
<Touchable
|
|
345
|
-
disabled={disabled}
|
|
346
|
-
onPress={togglePickerVisible}
|
|
347
|
-
style={styles.touchableContainer}
|
|
348
|
-
>
|
|
349
|
-
{/* outsetContainer */}
|
|
350
|
-
<View
|
|
351
|
-
pointerEvents="none"
|
|
352
|
-
style={[
|
|
353
|
-
styles.outsetContainer,
|
|
354
|
-
stylesWithoutBordersAndMargins,
|
|
355
|
-
!leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
|
|
356
|
-
]}
|
|
357
|
-
>
|
|
358
|
-
{leftIcon}
|
|
359
|
-
|
|
360
|
-
{/* insetContainer */}
|
|
361
|
-
<View
|
|
362
|
-
style={[
|
|
363
|
-
styles.insetContainer,
|
|
364
|
-
leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
|
|
365
|
-
]}
|
|
366
|
-
>
|
|
367
|
-
{/* primaryTextContainer */}
|
|
368
|
-
<View style={styles.primaryTextContainer}>
|
|
369
|
-
{labelText}
|
|
370
|
-
|
|
371
|
-
<Text style={primaryTextStyle}>
|
|
372
|
-
{String(selectedLabel ?? placeholder)}
|
|
373
|
-
</Text>
|
|
374
|
-
</View>
|
|
375
|
-
|
|
376
|
-
{rightIcon}
|
|
377
|
-
</View>
|
|
378
|
-
</View>
|
|
379
|
-
{assistiveTextLabel}
|
|
380
|
-
</Touchable>
|
|
116
|
+
{(options as unknown as PickerOption[]).map((option) => (
|
|
117
|
+
<NativePicker.Item
|
|
118
|
+
label={option.label}
|
|
119
|
+
value={option.value}
|
|
120
|
+
key={option.value}
|
|
121
|
+
/>
|
|
122
|
+
))}
|
|
123
|
+
</NativePicker>
|
|
124
|
+
);
|
|
381
125
|
|
|
382
|
-
|
|
383
|
-
|
|
126
|
+
const renderPicker = () => {
|
|
127
|
+
if (isIos) {
|
|
128
|
+
return (
|
|
384
129
|
<Portal>
|
|
385
|
-
<SafeAreaView style={styles.
|
|
130
|
+
<SafeAreaView style={styles.nativePicker}>
|
|
386
131
|
<View style={styles.iosPickerContent}>
|
|
387
132
|
<Button
|
|
388
133
|
Icon={Icon}
|
|
389
134
|
type="text"
|
|
390
|
-
onPress={
|
|
135
|
+
onPress={() => setPickerVisible(!pickerVisible)}
|
|
391
136
|
style={styles.iosButton}
|
|
392
137
|
>
|
|
393
138
|
{"Close"}
|
|
394
139
|
</Button>
|
|
395
|
-
|
|
396
|
-
<NativePicker
|
|
397
|
-
style={styles.iosNativePicker}
|
|
398
|
-
selectedValue={internalValue}
|
|
399
|
-
onValueChange={handleValueChange}
|
|
400
|
-
>
|
|
401
|
-
{(pickerOptions as unknown as PickerOption[]).map((option) => (
|
|
402
|
-
<NativePicker.Item
|
|
403
|
-
label={option.label}
|
|
404
|
-
value={option.value}
|
|
405
|
-
key={option.value}
|
|
406
|
-
/>
|
|
407
|
-
))}
|
|
408
|
-
</NativePicker>
|
|
140
|
+
{renderNativePicker()}
|
|
409
141
|
</View>
|
|
410
142
|
</SafeAreaView>
|
|
411
143
|
</Portal>
|
|
412
|
-
)
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
return renderNativePicker();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
React.useEffect(() => {
|
|
151
|
+
if (pickerVisible && pickerRef.current) {
|
|
152
|
+
pickerRef?.current?.focus();
|
|
153
|
+
}
|
|
154
|
+
}, [pickerVisible, pickerRef]);
|
|
155
|
+
|
|
156
|
+
React.useEffect(() => {
|
|
157
|
+
if (pickerVisible && autoDismissKeyboard) {
|
|
158
|
+
Keyboard.dismiss();
|
|
159
|
+
}
|
|
160
|
+
}, [pickerVisible, autoDismissKeyboard]);
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<View style={containerStyle}>
|
|
164
|
+
<Touchable
|
|
165
|
+
disabled={disabled}
|
|
166
|
+
onPress={() => setPickerVisible(!pickerVisible)}
|
|
167
|
+
>
|
|
168
|
+
<TextField
|
|
169
|
+
Icon={Icon}
|
|
170
|
+
numberOfLines={1}
|
|
171
|
+
onChangeText={() => {}}
|
|
172
|
+
value={String(selectedLabel ?? placeholder)}
|
|
173
|
+
editable={false}
|
|
174
|
+
disabled={disabled}
|
|
175
|
+
style={textFieldStyle}
|
|
176
|
+
{...rest}
|
|
177
|
+
/>
|
|
178
|
+
</Touchable>
|
|
413
179
|
|
|
414
|
-
{/* nonIosPicker */}
|
|
415
180
|
{/* Web version is collapsed by default, always show to allow direct expand */}
|
|
416
|
-
{
|
|
417
|
-
<NativePicker
|
|
418
|
-
enabled={!disabled}
|
|
419
|
-
selectedValue={internalValue}
|
|
420
|
-
onValueChange={handleValueChange}
|
|
421
|
-
style={styles.nonIosPicker}
|
|
422
|
-
ref={androidPickerRef}
|
|
423
|
-
onBlur={() => setPickerVisible(false)}
|
|
424
|
-
>
|
|
425
|
-
{(pickerOptions as unknown as PickerOption[]).map((option) => (
|
|
426
|
-
<NativePicker.Item
|
|
427
|
-
label={option.label}
|
|
428
|
-
value={option.value}
|
|
429
|
-
key={option.value}
|
|
430
|
-
/>
|
|
431
|
-
))}
|
|
432
|
-
</NativePicker>
|
|
433
|
-
) : null}
|
|
181
|
+
{(pickerVisible || isWeb) && renderPicker()}
|
|
434
182
|
</View>
|
|
435
183
|
);
|
|
436
184
|
};
|
|
437
185
|
|
|
438
186
|
const styles = StyleSheet.create({
|
|
439
|
-
|
|
440
|
-
alignSelf: "stretch",
|
|
441
|
-
alignItems: "center",
|
|
442
|
-
width: "100%",
|
|
443
|
-
maxWidth: deviceWidth,
|
|
444
|
-
},
|
|
445
|
-
touchableContainer: {
|
|
446
|
-
flex: 1,
|
|
447
|
-
height: "100%",
|
|
448
|
-
width: "100%",
|
|
449
|
-
alignSelf: "stretch",
|
|
450
|
-
alignItems: "center",
|
|
451
|
-
},
|
|
452
|
-
outsetContainer: {
|
|
453
|
-
flex: 1,
|
|
454
|
-
height: "100%",
|
|
455
|
-
width: "100%",
|
|
456
|
-
flexDirection: "row",
|
|
457
|
-
alignItems: "center",
|
|
458
|
-
justifyContent: "space-between",
|
|
459
|
-
},
|
|
460
|
-
insetContainer: {
|
|
461
|
-
flex: 1,
|
|
462
|
-
height: "100%",
|
|
463
|
-
width: "100%",
|
|
464
|
-
flexDirection: "row",
|
|
465
|
-
alignItems: "center",
|
|
466
|
-
justifyContent: "space-between",
|
|
467
|
-
paddingLeft: 12,
|
|
468
|
-
paddingRight: 12,
|
|
469
|
-
},
|
|
470
|
-
primaryTextContainer: {
|
|
471
|
-
flex: 1,
|
|
472
|
-
},
|
|
473
|
-
iosPicker: {
|
|
187
|
+
nativePicker: {
|
|
474
188
|
position: "absolute",
|
|
475
189
|
bottom: 0,
|
|
476
190
|
left: 0,
|
|
@@ -478,14 +192,11 @@ const styles = StyleSheet.create({
|
|
|
478
192
|
flexDirection: "row",
|
|
479
193
|
justifyContent: "center",
|
|
480
194
|
width: "100%",
|
|
481
|
-
maxWidth: deviceWidth,
|
|
482
|
-
maxHeight: deviceHeight,
|
|
483
195
|
backgroundColor: "white",
|
|
484
196
|
},
|
|
485
197
|
iosPickerContent: {
|
|
486
198
|
flexDirection: "column",
|
|
487
199
|
width: "100%",
|
|
488
|
-
maxWidth: deviceWidth,
|
|
489
200
|
},
|
|
490
201
|
iosButton: {
|
|
491
202
|
alignSelf: "flex-end",
|
|
@@ -495,15 +206,37 @@ const styles = StyleSheet.create({
|
|
|
495
206
|
},
|
|
496
207
|
nonIosPicker: {
|
|
497
208
|
opacity: 0,
|
|
498
|
-
position: "absolute",
|
|
499
|
-
top: 0,
|
|
500
|
-
left: 0,
|
|
501
|
-
right: 0,
|
|
502
|
-
bottom: 0,
|
|
503
|
-
width: "100%",
|
|
504
|
-
maxWidth: deviceWidth,
|
|
505
|
-
maxHeight: deviceHeight,
|
|
506
209
|
},
|
|
507
210
|
});
|
|
508
211
|
|
|
509
|
-
|
|
212
|
+
function normalizeToPickerOptions(
|
|
213
|
+
options: PickerOption[] | string[] | number[]
|
|
214
|
+
): PickerOption[] {
|
|
215
|
+
if (options.length === 0) {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const firstOption = options[0];
|
|
220
|
+
|
|
221
|
+
if (typeof firstOption === ("string" || "number")) {
|
|
222
|
+
return options.map((option) => ({
|
|
223
|
+
label: String(option),
|
|
224
|
+
value: String(option),
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (isObject(firstOption) && firstOption.value && firstOption.label) {
|
|
229
|
+
return (options as PickerOption[]).map((option) => {
|
|
230
|
+
return {
|
|
231
|
+
label: String(option.label),
|
|
232
|
+
value: String(option.value),
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
throw new Error(
|
|
238
|
+
'Picker options must be either an array of strings or array of { "label": string; "value": string; } objects.'
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export default Picker;
|
|
@@ -5,7 +5,7 @@ import { CodeField, useClearByFocusCell, } from "react-native-confirmation-code-
|
|
|
5
5
|
import { withTheme } from "../../theming";
|
|
6
6
|
import PinInputText from "./PinInputText";
|
|
7
7
|
import { extractStyles } from "../../utilities";
|
|
8
|
-
const PinInput = React.forwardRef(({ theme, onInputFull, cellCount = 4, clearOnCellFocus = true, blurOnFull = true, renderItem, value, onChangeText, focusedBorderColor, focusedBackgroundColor, focusedBorderWidth, focusedTextColor, style, ...rest }, ref) => {
|
|
8
|
+
const PinInput = React.forwardRef(({ theme, onInputFull, cellCount = 4, clearOnCellFocus = true, blurOnFull = true, renderItem, value, onChangeText, focusedBorderColor = theme.colors.primary, unFocusedBorderColor = theme.colors.disabled, focusedBackgroundColor, unFocusedBackgroundColor, focusedBorderWidth = 2, unFocusedBorderWidth = 1, focusedTextColor = theme.colors.strong, unFocusedTextColor = focusedTextColor, style, ...rest }, ref) => {
|
|
9
9
|
const newPinInputRef = React.useRef(null);
|
|
10
10
|
// Use the provided ref or default to new ref when not provided
|
|
11
11
|
const pinInputRef = ref
|
|
@@ -29,25 +29,25 @@ const PinInput = React.forwardRef(({ theme, onInputFull, cellCount = 4, clearOnC
|
|
|
29
29
|
}, [value, cellCount, blurOnFull, pinInputRef]);
|
|
30
30
|
return (React.createElement(CodeField, { ref: pinInputRef, ...(clearOnCellFocus ? codeFieldProps : {}), value: value, onChangeText: onChangeText, textInputStyle: { height: "100%" }, InputComponent: TextInput, cellCount: cellCount, renderCell: ({ symbol: cellValue, index, isFocused }) => (React.createElement(View, { key: index, onLayout: clearOnCellFocus ? getCellOnLayout(index) : undefined, style: { flex: 1 } }, (renderItem === null || renderItem === void 0 ? void 0 : renderItem({ cellValue, index, isFocused })) || (React.createElement(View, { testID: "default-code-input-cell", style: [
|
|
31
31
|
styles.cell,
|
|
32
|
-
{
|
|
32
|
+
{
|
|
33
|
+
borderWidth: isFocused
|
|
34
|
+
? focusedBorderWidth
|
|
35
|
+
: unFocusedBorderWidth,
|
|
36
|
+
borderColor: isFocused
|
|
37
|
+
? focusedBorderColor
|
|
38
|
+
: unFocusedBorderColor,
|
|
39
|
+
backgroundColor: isFocused
|
|
40
|
+
? focusedBackgroundColor
|
|
41
|
+
: unFocusedBackgroundColor,
|
|
42
|
+
},
|
|
33
43
|
viewStyles,
|
|
34
|
-
isFocused && focusedBorderWidth
|
|
35
|
-
? { borderWidth: focusedBorderWidth }
|
|
36
|
-
: undefined,
|
|
37
|
-
isFocused && focusedBorderColor
|
|
38
|
-
? { borderColor: focusedBorderColor }
|
|
39
|
-
: undefined,
|
|
40
|
-
isFocused && focusedBackgroundColor
|
|
41
|
-
? { backgroundColor: focusedBackgroundColor }
|
|
42
|
-
: undefined,
|
|
43
44
|
] },
|
|
44
45
|
React.createElement(PinInputText, { style: [
|
|
45
46
|
styles.cellText,
|
|
46
|
-
{
|
|
47
|
+
{
|
|
48
|
+
color: isFocused ? focusedTextColor : unFocusedTextColor,
|
|
49
|
+
},
|
|
47
50
|
textStyles,
|
|
48
|
-
isFocused && focusedTextColor
|
|
49
|
-
? { color: focusedTextColor }
|
|
50
|
-
: undefined,
|
|
51
51
|
], isFocused: isFocused }, cellValue))))), ...rest }));
|
|
52
52
|
});
|
|
53
53
|
const styles = StyleSheet.create({
|
|
@@ -61,7 +61,6 @@ const styles = StyleSheet.create({
|
|
|
61
61
|
aspectRatio: 1,
|
|
62
62
|
maxWidth: 70,
|
|
63
63
|
maxHeight: 70,
|
|
64
|
-
borderWidth: 1,
|
|
65
64
|
},
|
|
66
65
|
cellText: {
|
|
67
66
|
fontSize: 25,
|