@draftbit/core 44.1.8 → 44.1.9-a8c6fb.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.
Files changed (65) hide show
  1. package/lib/commonjs/Provider.js.map +1 -1
  2. package/lib/commonjs/components/Picker/Picker.js +249 -27
  3. package/lib/commonjs/components/Picker/Picker.js.map +1 -1
  4. package/lib/commonjs/components/Touchable.web.js.map +1 -1
  5. package/lib/commonjs/mappings/AvatarEdit.js.map +1 -1
  6. package/lib/commonjs/mappings/CardContainer.js.map +1 -1
  7. package/lib/commonjs/mappings/Carousel.js.map +1 -1
  8. package/lib/commonjs/mappings/CustomCode.js.map +1 -1
  9. package/lib/commonjs/mappings/Image.js.map +1 -1
  10. package/lib/commonjs/mappings/Picker.js +3 -1
  11. package/lib/commonjs/mappings/Picker.js.map +1 -1
  12. package/lib/commonjs/mappings/RadioButtonGroup.js.map +1 -1
  13. package/lib/commonjs/mappings/RadioButtonRow.js.map +1 -1
  14. package/lib/commonjs/mappings/RowBodyIcon.js.map +1 -1
  15. package/lib/commonjs/mappings/ScrollView.js.map +1 -1
  16. package/lib/commonjs/mappings/Stepper.js.map +1 -1
  17. package/lib/commonjs/mappings/Swiper.js.map +1 -1
  18. package/lib/commonjs/styles/overlay.js.map +1 -1
  19. package/lib/commonjs/styles/shadow.js.map +1 -1
  20. package/lib/commonjs/utilities.js +19 -0
  21. package/lib/commonjs/utilities.js.map +1 -1
  22. package/lib/module/components/Picker/Picker.js +236 -29
  23. package/lib/module/components/Picker/Picker.js.map +1 -1
  24. package/lib/module/mappings/Picker.js +4 -2
  25. package/lib/module/mappings/Picker.js.map +1 -1
  26. package/lib/module/utilities.js +12 -1
  27. package/lib/module/utilities.js.map +1 -1
  28. package/lib/typescript/src/components/Picker/Picker.d.ts +28 -4
  29. package/lib/typescript/src/mappings/Picker.d.ts +21 -0
  30. package/lib/typescript/src/utilities.d.ts +7 -0
  31. package/package.json +2 -2
  32. package/src/components/Picker/Picker.js +184 -18
  33. package/src/components/Picker/Picker.tsx +362 -35
  34. package/src/mappings/Picker.js +3 -1
  35. package/src/mappings/Picker.ts +4 -0
  36. package/src/utilities.js +49 -1
  37. package/src/utilities.ts +65 -1
  38. package/lib/commonjs/components/Picker/PickerComponent.android.js +0 -135
  39. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +0 -1
  40. package/lib/commonjs/components/Picker/PickerComponent.ios.js +0 -161
  41. package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +0 -1
  42. package/lib/commonjs/components/Picker/PickerComponent.web.js +0 -136
  43. package/lib/commonjs/components/Picker/PickerComponent.web.js.map +0 -1
  44. package/lib/commonjs/components/Picker/PickerTypes.js +0 -6
  45. package/lib/commonjs/components/Picker/PickerTypes.js.map +0 -1
  46. package/lib/module/components/Picker/PickerComponent.android.js +0 -112
  47. package/lib/module/components/Picker/PickerComponent.android.js.map +0 -1
  48. package/lib/module/components/Picker/PickerComponent.ios.js +0 -135
  49. package/lib/module/components/Picker/PickerComponent.ios.js.map +0 -1
  50. package/lib/module/components/Picker/PickerComponent.web.js +0 -113
  51. package/lib/module/components/Picker/PickerComponent.web.js.map +0 -1
  52. package/lib/module/components/Picker/PickerTypes.js +0 -2
  53. package/lib/module/components/Picker/PickerTypes.js.map +0 -1
  54. package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +0 -6
  55. package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +0 -7
  56. package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +0 -6
  57. package/lib/typescript/src/components/Picker/PickerTypes.d.ts +0 -18
  58. package/src/components/Picker/PickerComponent.android.js +0 -68
  59. package/src/components/Picker/PickerComponent.android.tsx +0 -116
  60. package/src/components/Picker/PickerComponent.ios.js +0 -78
  61. package/src/components/Picker/PickerComponent.ios.tsx +0 -142
  62. package/src/components/Picker/PickerComponent.web.js +0 -69
  63. package/src/components/Picker/PickerComponent.web.tsx +0 -117
  64. package/src/components/Picker/PickerTypes.js +0 -1
  65. package/src/components/Picker/PickerTypes.ts +0 -18
@@ -1,31 +1,76 @@
1
1
  import * as React from "react";
2
+ import {
3
+ View,
4
+ StyleSheet,
5
+ Text,
6
+ Platform,
7
+ ViewStyle,
8
+ StyleProp,
9
+ } from "react-native";
10
+ import { omit, pickBy, identity, isObject } from "lodash";
11
+ import { SafeAreaView } from "react-native-safe-area-context";
12
+ import { Picker as NativePicker } from "@react-native-picker/picker";
13
+
2
14
  import { withTheme } from "../../theming";
3
- //@ts-ignore
4
- import PickerComponent from "./PickerComponent"; //unable to find file due to using .android/.web/.ios
5
- import { PickerComponentProps, PickerOption } from "./PickerTypes";
15
+ import Portal from "../Portal/Portal";
16
+ import Button from "../DeprecatedButton";
17
+ import Touchable from "../Touchable";
18
+ import type { Theme } from "../../styles/DefaultTheme";
19
+ import type { IconSlot } from "../../interfaces/Icon";
20
+ import {
21
+ extractStyles,
22
+ extractBorderAndMarginStyles,
23
+ borderStyleNames,
24
+ marginStyleNames,
25
+ } from "../../utilities";
26
+
27
+ export interface PickerOption {
28
+ value: string;
29
+ label: string;
30
+ }
6
31
 
7
- type Props = PickerComponentProps & {
32
+ export type PickerProps = {
33
+ error?: any;
8
34
  placeholder?: string;
35
+ disabled?: boolean;
36
+ style?: StyleProp<ViewStyle> & { height?: number };
9
37
  value?: string;
10
38
  options: PickerOption[] | string[];
39
+ onValueChange: (value: string, index: number) => void;
40
+ defaultValue?: string;
41
+ assistiveText?: string;
42
+ label?: string;
43
+ iconColor?: string;
44
+ iconSize?: number;
45
+ leftIconMode?: "inset" | "outset";
46
+ leftIconName?: string;
47
+ placeholderTextColor?: string;
48
+ rightIconName?: string;
49
+ type?: "solid" | "underline";
50
+ theme: Theme;
51
+ Icon: IconSlot["Icon"];
11
52
  };
12
53
 
13
- function normalizeOptions(options: Props["options"]): PickerOption[] {
54
+ function normalizeOptions(options: PickerProps["options"]): PickerOption[] {
14
55
  if (options.length === 0) {
15
56
  return [];
16
57
  }
17
58
 
18
- if (typeof options[0] === "string") {
59
+ if (typeof options[0] === ("string" || "number")) {
19
60
  return (options as string[]).map((option) => ({
20
- label: option,
61
+ label: String(option),
21
62
  value: String(option),
22
63
  }));
23
64
  }
24
65
 
25
- if (options[0].label && options[0].value) {
26
- return options.map((option) => {
66
+ if (
67
+ isObject(options[0]) &&
68
+ options[0].value !== null &&
69
+ options[0].label !== null
70
+ ) {
71
+ return (options as PickerOption[]).map((option) => {
27
72
  return {
28
- label: option.label,
73
+ label: String(option.label),
29
74
  value: String(option.value),
30
75
  };
31
76
  });
@@ -36,18 +81,40 @@ function normalizeOptions(options: Props["options"]): PickerOption[] {
36
81
  );
37
82
  }
38
83
 
39
- const Picker: React.FC<Props> = ({
84
+ const unstyledColor = "rgba(165, 173, 183, 1)";
85
+ const disabledColor = "rgb(240, 240, 240)";
86
+ const errorColor = "rgba(255, 69, 100, 1)";
87
+
88
+ const Picker: React.FC<PickerProps> = ({
89
+ error,
40
90
  options = [],
91
+ onValueChange,
92
+ defaultValue,
93
+ Icon,
94
+ style,
41
95
  placeholder,
42
- onValueChange: onValueChangeOverride,
43
96
  value,
44
- defaultValue,
45
- ...props
97
+ disabled = false,
98
+ theme,
99
+ assistiveText,
100
+ label,
101
+ iconColor = unstyledColor,
102
+ iconSize = 24,
103
+ leftIconMode = "inset",
104
+ leftIconName,
105
+ placeholderTextColor = unstyledColor,
106
+ rightIconName,
107
+ type = "solid",
46
108
  }) => {
47
109
  const [internalValue, setInternalValue] = React.useState<string | undefined>(
48
110
  value || defaultValue
49
111
  );
50
112
 
113
+ const [pickerVisible, togglePickerVisible] = React.useReducer(
114
+ (state) => !state,
115
+ false
116
+ );
117
+
51
118
  React.useEffect(() => {
52
119
  if (value != null) {
53
120
  setInternalValue(value);
@@ -60,39 +127,299 @@ const Picker: React.FC<Props> = ({
60
127
  }
61
128
  }, [defaultValue]);
62
129
 
63
- const onValueChange = React.useCallback(
64
- (itemValue: string, itemIndex: number) => {
65
- if (placeholder && itemIndex === 0) {
66
- return;
67
- }
68
- onValueChangeOverride &&
69
- onValueChangeOverride(String(itemValue), itemIndex);
70
- },
71
- [placeholder, onValueChangeOverride]
72
- );
73
-
74
130
  const normalizedOptions = normalizeOptions(options);
75
131
 
76
132
  const pickerOptions = placeholder
77
133
  ? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
78
134
  : normalizedOptions;
79
135
 
136
+ const { colors } = theme;
137
+
138
+ const { viewStyles, textStyles } = extractStyles(style);
139
+
140
+ const { marginStyles, borderStyles: extractedBorderStyles } =
141
+ extractBorderAndMarginStyles(viewStyles, ["backgroundColor"]);
142
+
143
+ const borderStyles = {
144
+ ...{
145
+ ...(type === "solid"
146
+ ? {
147
+ borderTopLeftRadius: 5,
148
+ borderTopRightRadius: 5,
149
+ borderBottomRightRadius: 5,
150
+ borderBottomLeftRadius: 5,
151
+ borderTopWidth: 1,
152
+ borderRightWidth: 1,
153
+ borderLeftWidth: 1,
154
+ }
155
+ : {}),
156
+ borderBottomWidth: 1,
157
+ borderColor: unstyledColor,
158
+ borderStyle: "solid",
159
+ },
160
+ ...extractedBorderStyles,
161
+ ...(error ? { borderColor: errorColor } : {}),
162
+ ...(disabled
163
+ ? { borderColor: "transparent", backgroundColor: disabledColor }
164
+ : {}),
165
+ };
166
+
167
+ const platform = Platform.OS;
168
+
169
+ const stylesWithoutBordersAndMargins = {
170
+ ...{
171
+ height: 60,
172
+ width: "100%",
173
+ flex: platform === "web" ? undefined : 1,
174
+ },
175
+ ...omit(viewStyles, [
176
+ ...borderStyleNames,
177
+ ...marginStyleNames,
178
+ "backgroundColor",
179
+ ]),
180
+ };
181
+
182
+ const selectedLabel =
183
+ internalValue &&
184
+ ((pickerOptions as unknown as PickerOption[]).find(
185
+ (option) => option.value === internalValue
186
+ )?.label ??
187
+ internalValue);
188
+
189
+ const labelText = label ? (
190
+ <Text
191
+ style={{
192
+ textAlign: textStyles.textAlign,
193
+ color: unstyledColor,
194
+ fontSize: 12,
195
+ paddingBottom: 4,
196
+ }}
197
+ >
198
+ {label}
199
+ </Text>
200
+ ) : null;
201
+
202
+ const leftIconOutset = leftIconMode === "outset";
203
+
204
+ const leftIcon = leftIconName ? (
205
+ <Icon
206
+ name={leftIconName}
207
+ color={disabled ? unstyledColor : iconColor}
208
+ size={iconSize}
209
+ style={{
210
+ marginRight: 4,
211
+ marginLeft: 4,
212
+ }}
213
+ />
214
+ ) : null;
215
+
216
+ const rightIcon = rightIconName ? (
217
+ <Icon
218
+ name={rightIconName}
219
+ color={disabled ? unstyledColor : iconColor}
220
+ size={iconSize}
221
+ style={{
222
+ marginRight: -10,
223
+ marginLeft: 8,
224
+ }}
225
+ />
226
+ ) : null;
227
+
228
+ const width = stylesWithoutBordersAndMargins?.width;
229
+
230
+ const textAlign = textStyles?.textAlign;
231
+
232
+ const paddingLeft =
233
+ leftIconOutset &&
234
+ (!textAlign || textAlign === "left" || textAlign === "justify")
235
+ ? iconSize + 4
236
+ : 0;
237
+
238
+ const assistiveTextLabel = assistiveText ? (
239
+ <Text
240
+ style={{
241
+ textAlign,
242
+ width,
243
+ paddingLeft,
244
+ color: unstyledColor,
245
+ fontSize: 12,
246
+ paddingTop: 4,
247
+ }}
248
+ >
249
+ {assistiveText}
250
+ </Text>
251
+ ) : null;
252
+
253
+ const primaryTextStyle = {
254
+ color: unstyledColor,
255
+ fontSize: 14,
256
+ ...pickBy(textStyles, identity),
257
+ ...(placeholder === internalValue ? { color: placeholderTextColor } : {}),
258
+ ...(disabled ? { color: unstyledColor } : {}),
259
+ };
260
+
80
261
  const handleValueChange = (newValue: string, itemIndex: number) => {
81
- setInternalValue(newValue);
82
- if (onValueChange) {
83
- onValueChange(newValue, itemIndex);
262
+ if (!placeholder || itemIndex > 0) {
263
+ onValueChange?.(newValue, itemIndex);
84
264
  }
265
+ setInternalValue(newValue);
85
266
  };
86
267
 
87
268
  return (
88
- <PickerComponent
89
- {...props}
90
- selectedValue={String(internalValue)}
91
- placeholder={placeholder}
92
- options={pickerOptions}
93
- onValueChange={handleValueChange}
94
- />
269
+ /* marginsContainer */
270
+ <View style={[styles.marginsContainer, marginStyles]}>
271
+ {/* touchableContainer */}
272
+ <Touchable
273
+ disabled={disabled}
274
+ onPress={togglePickerVisible}
275
+ style={styles.touchableContainer}
276
+ >
277
+ {/* outsetContainer */}
278
+ <View
279
+ pointerEvents="none"
280
+ style={[
281
+ styles.outsetContainer,
282
+ stylesWithoutBordersAndMargins,
283
+ !leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
284
+ ]}
285
+ >
286
+ {leftIcon}
287
+
288
+ {/* insetContainer */}
289
+ <View
290
+ style={[
291
+ styles.insetContainer,
292
+ leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
293
+ ]}
294
+ >
295
+ {/* primaryTextContainer */}
296
+ <View style={styles.primaryTextContainer}>
297
+ {labelText}
298
+
299
+ <Text style={primaryTextStyle}>
300
+ {String(selectedLabel ?? placeholder)}
301
+ </Text>
302
+ </View>
303
+
304
+ {rightIcon}
305
+ </View>
306
+ </View>
307
+ {assistiveTextLabel}
308
+ </Touchable>
309
+
310
+ {/* iosPicker */}
311
+ {platform === "ios" && pickerVisible ? (
312
+ <Portal>
313
+ <View
314
+ style={[
315
+ styles.iosPicker,
316
+ {
317
+ backgroundColor: colors.divider,
318
+ },
319
+ ]}
320
+ >
321
+ <SafeAreaView style={styles.iosSafeArea}>
322
+ <Button
323
+ Icon={Icon}
324
+ type="text"
325
+ onPress={togglePickerVisible}
326
+ style={styles.iosButton}
327
+ >
328
+ {"Close"}
329
+ </Button>
330
+
331
+ <NativePicker
332
+ style={styles.iosNativePicker}
333
+ selectedValue={internalValue}
334
+ onValueChange={handleValueChange}
335
+ >
336
+ {(pickerOptions as unknown as PickerOption[]).map((option) => (
337
+ <NativePicker.Item
338
+ label={option.label}
339
+ value={option.value}
340
+ key={option.value}
341
+ />
342
+ ))}
343
+ </NativePicker>
344
+ </SafeAreaView>
345
+ </View>
346
+ </Portal>
347
+ ) : null}
348
+
349
+ {/* nonIosPicker */}
350
+ {platform !== "ios" ? (
351
+ <NativePicker
352
+ enabled={!disabled}
353
+ selectedValue={internalValue}
354
+ onValueChange={handleValueChange}
355
+ style={styles.nonIosPicker}
356
+ >
357
+ {(pickerOptions as unknown as PickerOption[]).map((option) => (
358
+ <NativePicker.Item
359
+ label={option.label}
360
+ value={option.value}
361
+ key={option.value}
362
+ />
363
+ ))}
364
+ </NativePicker>
365
+ ) : null}
366
+ </View>
95
367
  );
96
368
  };
97
369
 
98
370
  export default withTheme(Picker);
371
+
372
+ const styles = StyleSheet.create({
373
+ marginsContainer: {
374
+ alignSelf: "stretch",
375
+ },
376
+ touchableContainer: {
377
+ alignSelf: "stretch",
378
+ alignItems: "center",
379
+ },
380
+ outsetContainer: {
381
+ flexDirection: "row",
382
+ alignItems: "center",
383
+ justifyContent: "space-between",
384
+ },
385
+ insetContainer: {
386
+ flex: 1,
387
+ height: "100%",
388
+ flexDirection: "row",
389
+ alignItems: "center",
390
+ justifyContent: "space-between",
391
+ paddingLeft: 12,
392
+ paddingRight: 12,
393
+ },
394
+ primaryTextContainer: {
395
+ flex: 1,
396
+ },
397
+ iosPicker: {
398
+ position: "absolute",
399
+ bottom: 0,
400
+ left: 0,
401
+ right: 0,
402
+ flexDirection: "row",
403
+ justifyContent: "center",
404
+ },
405
+ iosSafeArea: {
406
+ backgroundColor: "white",
407
+ flexDirection: "column",
408
+ width: "100%",
409
+ },
410
+ iosButton: {
411
+ alignSelf: "flex-end",
412
+ },
413
+ iosNativePicker: {
414
+ backgroundColor: "white",
415
+ },
416
+ nonIosPicker: {
417
+ opacity: 0,
418
+ position: "absolute",
419
+ top: 0,
420
+ left: 0,
421
+ right: 0,
422
+ bottom: 0,
423
+ width: "100%",
424
+ },
425
+ });
@@ -1,4 +1,4 @@
1
- import { COMPONENT_TYPES, Triggers, GROUPS, FORM_TYPES, PROP_TYPES, FIELD_NAME, } from "@draftbit/types";
1
+ import { COMPONENT_TYPES, Triggers, GROUPS, FORM_TYPES, PROP_TYPES, FIELD_NAME, createIconSizeProp, createColorProp, } from "@draftbit/types";
2
2
  const SEED_DATA_PROPS = {
3
3
  label: {
4
4
  group: GROUPS.data,
@@ -131,6 +131,8 @@ export const SEED_DATA = [
131
131
  required: true,
132
132
  group: GROUPS.basic,
133
133
  },
134
+ iconSize: createIconSizeProp(),
135
+ iconColor: createColorProp(),
134
136
  },
135
137
  layout: {},
136
138
  },
@@ -5,6 +5,8 @@ import {
5
5
  FORM_TYPES,
6
6
  PROP_TYPES,
7
7
  FIELD_NAME,
8
+ createIconSizeProp,
9
+ createColorProp,
8
10
  } from "@draftbit/types";
9
11
 
10
12
  const SEED_DATA_PROPS = {
@@ -143,6 +145,8 @@ export const SEED_DATA = [
143
145
  required: true,
144
146
  group: GROUPS.basic,
145
147
  },
148
+ iconSize: createIconSizeProp(),
149
+ iconColor: createColorProp(),
146
150
  },
147
151
  layout: {},
148
152
  },
package/src/utilities.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from "react-native";
2
- import { isString, isNumber } from "lodash";
2
+ import { isString, isNumber, pick, pickBy, identity } from "lodash";
3
3
  export function extractStyles(style) {
4
4
  const { color, fontFamily, fontWeight, fontSize, lineHeight, letterSpacing, textTransform, textAlign, textDecorationLine, textDecorationColor, textDecorationStyle, ...viewStyles } = StyleSheet.flatten(style || {});
5
5
  const textStyles = {
@@ -17,6 +17,54 @@ export function extractStyles(style) {
17
17
  };
18
18
  return { viewStyles, textStyles };
19
19
  }
20
+ export const borderStyleNames = [
21
+ "borderRadius",
22
+ "borderBottomColor",
23
+ "borderBottomEndRadius",
24
+ "borderBottomLeftRadius",
25
+ "borderBottomRightRadius",
26
+ "borderBottomStartRadius",
27
+ "borderBottomWidth",
28
+ "borderColor",
29
+ "borderEndColor",
30
+ "borderLeftColor",
31
+ "borderLeftWidth",
32
+ "borderRadius",
33
+ "borderRightColor",
34
+ "borderRightWidth",
35
+ "borderStartColor",
36
+ "borderStyle",
37
+ "borderTopColor",
38
+ "borderTopEndRadius",
39
+ "borderTopLeftRadius",
40
+ "borderTopRightRadius",
41
+ "borderTopStartRadius",
42
+ "borderTopWidth",
43
+ "borderWidth",
44
+ ];
45
+ export const marginStyleNames = [
46
+ "margin",
47
+ "marginBottom",
48
+ "marginEnd",
49
+ "marginHorizontal",
50
+ "marginLeft",
51
+ "marginRight",
52
+ "marginStart",
53
+ "marginTop",
54
+ "marginVertical",
55
+ ];
56
+ export function extractBorderAndMarginStyles(style, additionalBorderStyles, additionalMarginStyles) {
57
+ const flatStyle = StyleSheet.flatten(style || {});
58
+ const borderStyles = pickBy(pick(flatStyle, [
59
+ ...borderStyleNames,
60
+ ...(additionalBorderStyles ? additionalBorderStyles : []),
61
+ ]), identity);
62
+ const marginStyles = pickBy(pick(flatStyle, [
63
+ ...marginStyleNames,
64
+ ...(additionalMarginStyles ? additionalMarginStyles : []),
65
+ ]), identity);
66
+ return { borderStyles, marginStyles };
67
+ }
20
68
  /**
21
69
  * Merges a style object on top of another style object. In React Native,
22
70
  * keys with undefined values in a style object will still override styles
package/src/utilities.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet, StyleProp, TextStyle } from "react-native";
2
- import { isString, isNumber } from "lodash";
2
+ import { isString, isNumber, pick, pickBy, identity } from "lodash";
3
3
 
4
4
  export function extractStyles(style: StyleProp<any>) {
5
5
  const {
@@ -34,6 +34,70 @@ export function extractStyles(style: StyleProp<any>) {
34
34
  return { viewStyles, textStyles };
35
35
  }
36
36
 
37
+ export const borderStyleNames = [
38
+ "borderRadius",
39
+ "borderBottomColor",
40
+ "borderBottomEndRadius",
41
+ "borderBottomLeftRadius",
42
+ "borderBottomRightRadius",
43
+ "borderBottomStartRadius",
44
+ "borderBottomWidth",
45
+ "borderColor",
46
+ "borderEndColor",
47
+ "borderLeftColor",
48
+ "borderLeftWidth",
49
+ "borderRadius",
50
+ "borderRightColor",
51
+ "borderRightWidth",
52
+ "borderStartColor",
53
+ "borderStyle",
54
+ "borderTopColor",
55
+ "borderTopEndRadius",
56
+ "borderTopLeftRadius",
57
+ "borderTopRightRadius",
58
+ "borderTopStartRadius",
59
+ "borderTopWidth",
60
+ "borderWidth",
61
+ ];
62
+
63
+ export const marginStyleNames = [
64
+ "margin",
65
+ "marginBottom",
66
+ "marginEnd",
67
+ "marginHorizontal",
68
+ "marginLeft",
69
+ "marginRight",
70
+ "marginStart",
71
+ "marginTop",
72
+ "marginVertical",
73
+ ];
74
+
75
+ export function extractBorderAndMarginStyles(
76
+ style: StyleProp<any>,
77
+ additionalBorderStyles?: string[],
78
+ additionalMarginStyles?: string[]
79
+ ) {
80
+ const flatStyle = StyleSheet.flatten(style || {});
81
+
82
+ const borderStyles = pickBy(
83
+ pick(flatStyle, [
84
+ ...borderStyleNames,
85
+ ...(additionalBorderStyles ? additionalBorderStyles : []),
86
+ ]),
87
+ identity
88
+ );
89
+
90
+ const marginStyles = pickBy(
91
+ pick(flatStyle, [
92
+ ...marginStyleNames,
93
+ ...(additionalMarginStyles ? additionalMarginStyles : []),
94
+ ]),
95
+ identity
96
+ );
97
+
98
+ return { borderStyles, marginStyles };
99
+ }
100
+
37
101
  /**
38
102
  * Merges a style object on top of another style object. In React Native,
39
103
  * keys with undefined values in a style object will still override styles