@draftbit/core 47.0.1-54c307.2 → 47.0.1-cc5ccc.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 (79) hide show
  1. package/lib/commonjs/components/Button.js +27 -15
  2. package/lib/commonjs/components/Checkbox/Checkbox.js +1 -3
  3. package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
  4. package/lib/commonjs/components/DeprecatedCardWrapper.js +2 -2
  5. package/lib/commonjs/components/DeprecatedFAB.js +1 -2
  6. package/lib/commonjs/components/Picker/Picker.js +3 -4
  7. package/lib/commonjs/components/Picker/PickerComponent.ios.js +2 -2
  8. package/lib/commonjs/components/Pressable.js +48 -0
  9. package/lib/commonjs/components/Touchable.js +27 -11
  10. package/lib/commonjs/mappings/Button.js +13 -10
  11. package/lib/commonjs/mappings/Pressable.js +52 -0
  12. package/lib/module/components/Button.js +21 -9
  13. package/lib/module/components/Checkbox/Checkbox.js +2 -3
  14. package/lib/module/components/DatePicker/DatePicker.js +1 -1
  15. package/lib/module/components/DeprecatedCardWrapper.js +2 -2
  16. package/lib/module/components/DeprecatedFAB.js +2 -3
  17. package/lib/module/components/Picker/Picker.js +3 -4
  18. package/lib/module/components/Picker/PickerComponent.ios.js +1 -1
  19. package/lib/module/components/Pressable.js +40 -0
  20. package/lib/module/components/Touchable.js +25 -10
  21. package/lib/module/mappings/Button.js +14 -11
  22. package/lib/module/mappings/Pressable.js +45 -0
  23. package/lib/typescript/src/components/Button.d.ts +2 -0
  24. package/lib/typescript/src/components/Button.d.ts.map +1 -1
  25. package/lib/typescript/src/components/Checkbox/Checkbox.d.ts +2 -2
  26. package/lib/typescript/src/components/Checkbox/Checkbox.d.ts.map +1 -1
  27. package/lib/typescript/src/components/DeprecatedCardWrapper.d.ts.map +1 -1
  28. package/lib/typescript/src/components/DeprecatedFAB.d.ts +2 -2
  29. package/lib/typescript/src/components/DeprecatedFAB.d.ts.map +1 -1
  30. package/lib/typescript/src/components/Picker/Picker.d.ts.map +1 -1
  31. package/lib/typescript/src/components/Pressable.d.ts +18 -0
  32. package/lib/typescript/src/components/Pressable.d.ts.map +1 -0
  33. package/lib/typescript/src/components/Touchable.d.ts +9 -2
  34. package/lib/typescript/src/components/Touchable.d.ts.map +1 -1
  35. package/lib/typescript/src/mappings/Button.d.ts +113 -4
  36. package/lib/typescript/src/mappings/Button.d.ts.map +1 -1
  37. package/lib/typescript/src/mappings/Pressable.d.ts +76 -0
  38. package/lib/typescript/src/mappings/Pressable.d.ts.map +1 -0
  39. package/package.json +3 -3
  40. package/src/components/Button.js +18 -11
  41. package/src/components/Button.tsx +45 -11
  42. package/src/components/Checkbox/Checkbox.js +2 -3
  43. package/src/components/Checkbox/Checkbox.tsx +5 -7
  44. package/src/components/DatePicker/DatePicker.js +1 -1
  45. package/src/components/DatePicker/DatePicker.tsx +1 -1
  46. package/src/components/DeprecatedCardWrapper.js +2 -2
  47. package/src/components/DeprecatedCardWrapper.tsx +3 -4
  48. package/src/components/DeprecatedFAB.js +2 -3
  49. package/src/components/DeprecatedFAB.tsx +5 -5
  50. package/src/components/Picker/Picker.js +3 -4
  51. package/src/components/Picker/Picker.tsx +4 -4
  52. package/src/components/Picker/PickerComponent.ios.js +1 -1
  53. package/src/components/Picker/PickerComponent.ios.tsx +1 -1
  54. package/src/components/Pressable.js +17 -0
  55. package/src/components/Pressable.tsx +67 -0
  56. package/src/components/Touchable.js +16 -11
  57. package/src/components/Touchable.tsx +42 -11
  58. package/src/mappings/Button.js +13 -10
  59. package/src/mappings/Button.ts +13 -10
  60. package/src/mappings/Pressable.js +52 -0
  61. package/src/mappings/Pressable.ts +63 -0
  62. package/lib/commonjs/components/DeprecatedButton.js +0 -151
  63. package/lib/commonjs/components/Touchable.web.js +0 -9
  64. package/lib/commonjs/mappings/Touchable.js +0 -20
  65. package/lib/module/components/DeprecatedButton.js +0 -141
  66. package/lib/module/components/Touchable.web.js +0 -2
  67. package/lib/module/mappings/Touchable.js +0 -13
  68. package/lib/typescript/src/components/DeprecatedButton.d.ts +0 -54
  69. package/lib/typescript/src/components/DeprecatedButton.d.ts.map +0 -1
  70. package/lib/typescript/src/components/Touchable.web.d.ts +0 -3
  71. package/lib/typescript/src/components/Touchable.web.d.ts.map +0 -1
  72. package/lib/typescript/src/mappings/Touchable.d.ts +0 -22
  73. package/lib/typescript/src/mappings/Touchable.d.ts.map +0 -1
  74. package/src/components/DeprecatedButton.js +0 -95
  75. package/src/components/DeprecatedButton.tsx +0 -214
  76. package/src/components/Touchable.web.js +0 -2
  77. package/src/components/Touchable.web.tsx +0 -3
  78. package/src/mappings/Touchable.js +0 -17
  79. package/src/mappings/Touchable.ts +0 -23
@@ -1,11 +1,14 @@
1
- import * as React from "react";
1
+ import React, { useCallback } from "react";
2
2
  import {
3
3
  Text,
4
4
  Pressable,
5
+ PressableProps,
6
+ PressableStateCallbackType,
5
7
  Platform,
6
8
  StyleSheet,
9
+ StyleProp,
7
10
  TextStyle,
8
- PressableProps,
11
+ ViewStyle,
9
12
  ActivityIndicator,
10
13
  } from "react-native";
11
14
 
@@ -27,6 +30,12 @@ type BaseProps = {
27
30
  loading: boolean;
28
31
  style?: TextStyle;
29
32
  onPress: () => void;
33
+ onLongPress?: () => void;
34
+ activeOpacity?: number;
35
+ disabledOpacity?: number;
36
+ delayLongPress?: number;
37
+ hitSlop?: number;
38
+ pressRetentionOffset?: number;
30
39
  icon?: string;
31
40
  } & PressableProps &
32
41
  IconSlot;
@@ -37,16 +46,29 @@ type Props = {
37
46
  loading: boolean;
38
47
  style?: TextStyle;
39
48
  onPress: () => void;
49
+ onLongPress?: () => void;
50
+ activeOpacity?: number;
51
+ disabledOpacity?: number;
52
+ delayLongPress?: number;
53
+ hitSlop?: number;
54
+ pressRetentionOffset?: number;
40
55
  icon?: string;
41
56
  theme: Theme;
42
57
  } & PressableProps &
43
58
  IconSlot;
44
59
 
60
+ export type StyleType = (
61
+ state: PressableStateCallbackType
62
+ ) => StyleProp<ViewStyle>;
63
+
45
64
  function Base({
46
65
  Icon,
47
66
  icon,
48
67
  title,
49
68
  onPress,
69
+ onLongPress,
70
+ activeOpacity,
71
+ disabledOpacity,
50
72
  loading,
51
73
  disabled,
52
74
  style,
@@ -89,19 +111,31 @@ function Base({
89
111
  buttonStyles.justifyContent = "flex-end";
90
112
  }
91
113
 
114
+ const getOpacity = useCallback(
115
+ (pressed: boolean) => {
116
+ if (disabled) {
117
+ return disabledOpacity;
118
+ } else {
119
+ if (pressed) return activeOpacity;
120
+ else return 1;
121
+ }
122
+ },
123
+ [activeOpacity, disabled, disabledOpacity]
124
+ );
125
+ const _style = useCallback<StyleType>(
126
+ ({ pressed }) => [
127
+ buttonStyles as ViewStyle,
128
+ { opacity: getOpacity(pressed) },
129
+ ],
130
+ [getOpacity, buttonStyles]
131
+ );
132
+
92
133
  return (
93
134
  <Pressable
94
135
  onPress={onPress}
136
+ onLongPress={onLongPress}
95
137
  disabled={disabled || loading}
96
- style={({ pressed }) => {
97
- return [
98
- styles.base,
99
- {
100
- opacity: pressed || disabled ? 0.75 : 1,
101
- },
102
- buttonStyles,
103
- ];
104
- }}
138
+ style={(styles.base, _style)}
105
139
  {...props}
106
140
  >
107
141
  {loading ? (
@@ -1,7 +1,6 @@
1
1
  import * as React from "react";
2
- import { View, StyleSheet, } from "react-native";
2
+ import { View, StyleSheet, Pressable, } from "react-native";
3
3
  import { useTheme } from "../../theming";
4
- import Touchable from "../Touchable";
5
4
  import { usePrevious } from "../../hooks";
6
5
  const Checkbox = ({ Icon, status, disabled = false, onPress, onCheck, onUncheck, color, uncheckedColor, defaultValue, checkedIcon = "MaterialCommunityIcons/checkbox-marked", uncheckedIcon = "MaterialCommunityIcons/checkbox-blank-outline", size = 24, style, ...rest }) => {
7
6
  const [internalValue, setInternalValue] = React.useState(status || defaultValue || false);
@@ -33,7 +32,7 @@ const Checkbox = ({ Icon, status, disabled = false, onPress, onCheck, onUncheck,
33
32
  onUncheck === null || onUncheck === void 0 ? void 0 : onUncheck();
34
33
  }
35
34
  };
36
- return (React.createElement(Touchable, { ...rest, onPress: handlePress, disabled: disabled, accessibilityState: { disabled }, accessibilityRole: "button", accessibilityLiveRegion: "polite", style: [styles.container, style, { width: size, height: size }] },
35
+ return (React.createElement(Pressable, { ...rest, onPress: handlePress, disabled: disabled, accessibilityState: { disabled }, accessibilityRole: "button", accessibilityLiveRegion: "polite", style: [styles.container, style, { width: size, height: size }] },
37
36
  React.createElement(Icon, { style: styles.icon, name: internalValue ? checkedIcon : uncheckedIcon, size: size, color: checkboxColor }),
38
37
  React.createElement(View, { style: [StyleSheet.absoluteFill, styles.fillContainer] },
39
38
  React.createElement(View, { style: [
@@ -2,14 +2,14 @@ import * as React from "react";
2
2
  import {
3
3
  View,
4
4
  StyleSheet,
5
- TouchableHighlightProps,
6
5
  StyleProp,
7
6
  ViewStyle,
7
+ Pressable,
8
+ PressableProps,
8
9
  } from "react-native";
9
10
  import { useTheme } from "../../theming";
10
11
  import type { IconSlot } from "../../interfaces/Icon";
11
12
 
12
- import Touchable from "../Touchable";
13
13
  import { usePrevious } from "../../hooks";
14
14
 
15
15
  export interface CheckboxProps {
@@ -27,9 +27,7 @@ export interface CheckboxProps {
27
27
  style?: StyleProp<ViewStyle>;
28
28
  }
29
29
 
30
- const Checkbox: React.FC<
31
- CheckboxProps & TouchableHighlightProps & IconSlot
32
- > = ({
30
+ const Checkbox: React.FC<CheckboxProps & PressableProps & IconSlot> = ({
33
31
  Icon,
34
32
  status,
35
33
  disabled = false,
@@ -87,7 +85,7 @@ const Checkbox: React.FC<
87
85
  };
88
86
 
89
87
  return (
90
- <Touchable
88
+ <Pressable
91
89
  {...rest}
92
90
  onPress={handlePress}
93
91
  disabled={disabled}
@@ -111,7 +109,7 @@ const Checkbox: React.FC<
111
109
  ]}
112
110
  />
113
111
  </View>
114
- </Touchable>
112
+ </Pressable>
115
113
  );
116
114
  };
117
115
 
@@ -311,7 +311,7 @@ const DatePicker = ({ Icon, style, theme: { colors, typography, roundness, disab
311
311
  ...leftIconStyle,
312
312
  marginLeft: type === "solid" ? 16 : 0,
313
313
  } })) : null,
314
- React.createElement(NativeTextInput, { value: formatDate(), placeholder: label ? placeholder1 : placeholder, editable: !disabled, placeholderTextColor: placeholderColor, selectionColor: activeColor, onFocus: _handleFocus, onBlur: _handleBlur, underlineColorAndroid: "transparent", style: [inputStyles, textStyles, viewStyles], ...props })),
314
+ React.createElement(NativeTextInput, { value: formatDate(), placeholder: label ? placeholder1 : placeholder, editable: !disabled, placeholderTextColor: placeholderColor, selectionColor: activeColor, onFocus: _handleFocus, onBlur: _handleBlur, underlineColorAndroid: "transparent", style: [inputStyles, textStyles], ...props })),
315
315
  rightIconName ? (React.createElement(Icon, { name: rightIconName, size: ICON_SIZE, color: colors.light, style: {
316
316
  position: "absolute",
317
317
  right: 16,
@@ -471,7 +471,7 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
471
471
  onFocus={_handleFocus}
472
472
  onBlur={_handleBlur}
473
473
  underlineColorAndroid={"transparent"}
474
- style={[inputStyles, textStyles, viewStyles]}
474
+ style={[inputStyles, textStyles]}
475
475
  {...props}
476
476
  />
477
477
  </View>
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { withTheme } from "../theming";
3
- import Touchable from "./Touchable";
3
+ import { Pressable } from "react-native";
4
4
  const getWidth = (numColumns) => {
5
5
  switch (numColumns) {
6
6
  case 1:
@@ -13,6 +13,6 @@ const getWidth = (numColumns) => {
13
13
  };
14
14
  const Card = ({ numColumns = 3, children, onPress, style, ...rest }) => {
15
15
  const width = getWidth(numColumns);
16
- return (React.createElement(Touchable, { disabled: !onPress, onPress: onPress, style: [style, { width }], ...rest }, children));
16
+ return (React.createElement(Pressable, { disabled: !onPress, onPress: onPress, style: [style, { width }], ...rest }, children));
17
17
  };
18
18
  export default withTheme(Card);
@@ -1,7 +1,6 @@
1
1
  import React from "react";
2
2
  import { withTheme } from "../theming";
3
- import Touchable from "./Touchable";
4
- import { StyleProp, ViewStyle } from "react-native";
3
+ import { StyleProp, ViewStyle, Pressable } from "react-native";
5
4
  import theme from "../styles/DefaultTheme";
6
5
 
7
6
  type Props = {
@@ -32,14 +31,14 @@ const Card: React.FC<React.PropsWithChildren<Props>> = ({
32
31
  }) => {
33
32
  const width = getWidth(numColumns);
34
33
  return (
35
- <Touchable
34
+ <Pressable
36
35
  disabled={!onPress}
37
36
  onPress={onPress}
38
37
  style={[style, { width }]}
39
38
  {...rest}
40
39
  >
41
40
  {children}
42
- </Touchable>
41
+ </Pressable>
43
42
  );
44
43
  };
45
44
 
@@ -1,9 +1,8 @@
1
1
  import * as React from "react";
2
- import { ActivityIndicator, View, StyleSheet, } from "react-native";
2
+ import { ActivityIndicator, View, StyleSheet, Pressable, } from "react-native";
3
3
  import color from "color";
4
4
  import Config from "./Config";
5
5
  import Text from "./Text";
6
- import Touchable from "./Touchable";
7
6
  import Elevation from "./Elevation";
8
7
  import { withTheme } from "../theming";
9
8
  const FAB = ({ Icon, icon, disabled = false, type = "solid", loading = false, color: colorOverride, label, onPress, elevation = 0, style, theme: { colors, disabledOpacity, roundness, typography }, ...rest }) => {
@@ -83,7 +82,7 @@ const FAB = ({ Icon, icon, disabled = false, type = "solid", loading = false, co
83
82
  });
84
83
  }
85
84
  return (React.createElement(Elevation, { style: [{ elevation }, style] },
86
- React.createElement(Touchable, { ...rest, onPress: onPress, accessibilityState: { disabled }, accessibilityRole: "button", disabled: disabled || loading, style: buttonStyles },
85
+ React.createElement(Pressable, { ...rest, onPress: onPress, accessibilityState: { disabled }, accessibilityRole: "button", disabled: disabled || loading, style: buttonStyles },
87
86
  React.createElement(View, { style: styles.content },
88
87
  icon && loading !== true ? (React.createElement(View, { style: iconStyle },
89
88
  React.createElement(Icon, { name: icon, size: Config.buttonIconSize, color: textColor }))) : null,
@@ -3,15 +3,15 @@ import {
3
3
  ActivityIndicator,
4
4
  View,
5
5
  StyleSheet,
6
- TouchableHighlightProps,
7
6
  StyleProp,
8
7
  ViewStyle,
9
8
  TextStyle,
9
+ Pressable,
10
+ PressableProps,
10
11
  } from "react-native";
11
12
  import color from "color";
12
13
  import Config from "./Config";
13
14
  import Text from "./Text";
14
- import Touchable from "./Touchable";
15
15
  import Elevation from "./Elevation";
16
16
  import { withTheme } from "../theming";
17
17
 
@@ -65,7 +65,7 @@ type Props = {
65
65
  elevation?: number;
66
66
  theme: Theme;
67
67
  style?: StyleProp<ViewStyle>;
68
- } & TouchableHighlightProps &
68
+ } & PressableProps &
69
69
  IconSlot;
70
70
 
71
71
  const FAB: React.FC<React.PropsWithChildren<Props>> = ({
@@ -169,7 +169,7 @@ const FAB: React.FC<React.PropsWithChildren<Props>> = ({
169
169
 
170
170
  return (
171
171
  <Elevation style={[{ elevation }, style]}>
172
- <Touchable
172
+ <Pressable
173
173
  {...rest}
174
174
  onPress={onPress}
175
175
  accessibilityState={{ disabled }}
@@ -200,7 +200,7 @@ const FAB: React.FC<React.PropsWithChildren<Props>> = ({
200
200
  </Text>
201
201
  ) : null}
202
202
  </View>
203
- </Touchable>
203
+ </Pressable>
204
204
  </Elevation>
205
205
  );
206
206
  };
@@ -1,12 +1,11 @@
1
1
  import * as React from "react";
2
- import { View, StyleSheet, Text, Platform, Dimensions, } from "react-native";
2
+ import { View, StyleSheet, Text, Platform, Dimensions, Pressable, } from "react-native";
3
3
  import { omit, pickBy, identity, isObject } from "lodash";
4
4
  import { SafeAreaView } from "react-native-safe-area-context";
5
5
  import { Picker as NativePicker } from "@react-native-picker/picker";
6
6
  import { withTheme } from "../../theming";
7
7
  import Portal from "../Portal/Portal";
8
- import Button from "../DeprecatedButton";
9
- import Touchable from "../Touchable";
8
+ import { Button } from "../Button";
10
9
  import { extractStyles, extractBorderAndMarginStyles, borderStyleNames, marginStyleNames, } from "../../utilities";
11
10
  function normalizeOptions(options) {
12
11
  if (options.length === 0) {
@@ -166,7 +165,7 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
166
165
  return (
167
166
  /* marginsContainer */
168
167
  React.createElement(View, { style: [styles.marginsContainer, marginStyles] },
169
- React.createElement(Touchable, { disabled: disabled, onPress: togglePickerVisible, style: styles.touchableContainer },
168
+ React.createElement(Pressable, { disabled: disabled, onPress: togglePickerVisible, style: styles.touchableContainer },
170
169
  React.createElement(View, { pointerEvents: "none", style: [
171
170
  styles.outsetContainer,
172
171
  stylesWithoutBordersAndMargins,
@@ -7,6 +7,7 @@ import {
7
7
  ViewStyle,
8
8
  StyleProp,
9
9
  Dimensions,
10
+ Pressable,
10
11
  } from "react-native";
11
12
  import { omit, pickBy, identity, isObject } from "lodash";
12
13
  import { SafeAreaView } from "react-native-safe-area-context";
@@ -14,8 +15,7 @@ import { Picker as NativePicker } from "@react-native-picker/picker";
14
15
 
15
16
  import { withTheme } from "../../theming";
16
17
  import Portal from "../Portal/Portal";
17
- import Button from "../DeprecatedButton";
18
- import Touchable from "../Touchable";
18
+ import { Button } from "../Button";
19
19
  import type { Theme } from "../../styles/DefaultTheme";
20
20
  import type { IconSlot } from "../../interfaces/Icon";
21
21
  import {
@@ -306,7 +306,7 @@ const Picker: React.FC<PickerProps> = ({
306
306
  /* marginsContainer */
307
307
  <View style={[styles.marginsContainer, marginStyles]}>
308
308
  {/* touchableContainer */}
309
- <Touchable
309
+ <Pressable
310
310
  disabled={disabled}
311
311
  onPress={togglePickerVisible}
312
312
  style={styles.touchableContainer}
@@ -342,7 +342,7 @@ const Picker: React.FC<PickerProps> = ({
342
342
  </View>
343
343
  </View>
344
344
  {assistiveTextLabel}
345
- </Touchable>
345
+ </Pressable>
346
346
 
347
347
  {/* iosPicker */}
348
348
  {isIos && pickerVisible ? (
@@ -5,7 +5,7 @@ import omit from "lodash.omit";
5
5
  import { Picker as NativePicker } from "@react-native-picker/picker";
6
6
  import { withTheme } from "../../theming";
7
7
  import Portal from "../Portal/Portal";
8
- import Button from "../DeprecatedButton";
8
+ import { Button } from "../Button";
9
9
  import TextField from "../TextField";
10
10
  import Touchable from "../Touchable";
11
11
  import { extractStyles } from "../../utilities";
@@ -8,7 +8,7 @@ import { Picker as NativePicker } from "@react-native-picker/picker";
8
8
  import { withTheme } from "../../theming";
9
9
 
10
10
  import Portal from "../Portal/Portal";
11
- import Button from "../DeprecatedButton";
11
+ import { Button } from "../Button";
12
12
  import TextField from "../TextField";
13
13
  import Touchable from "../Touchable";
14
14
  import { PickerComponentProps } from "./PickerTypes";
@@ -0,0 +1,17 @@
1
+ import React, { useCallback } from "react";
2
+ import { Pressable as NativePressable, } from "react-native";
3
+ export default function Pressable({ children, disabled, onPress, onLongPress, hitSlop, delayLongPress, activeOpacity, disabledOpacity, style, ...props }) {
4
+ const getOpacity = useCallback((pressed) => {
5
+ if (disabled) {
6
+ return disabledOpacity;
7
+ }
8
+ else {
9
+ if (pressed)
10
+ return activeOpacity;
11
+ else
12
+ return 1;
13
+ }
14
+ }, [activeOpacity, disabled, disabledOpacity]);
15
+ const _style = useCallback(({ pressed }) => [style, { opacity: getOpacity(pressed) }], [getOpacity, style]);
16
+ return (React.createElement(NativePressable, { onPress: onPress, onLongPress: onLongPress, disabled: disabled, delayLongPress: delayLongPress ? delayLongPress : 500, hitSlop: hitSlop ? hitSlop : 8, style: _style, ...props }, children));
17
+ }
@@ -0,0 +1,67 @@
1
+ import React, { useCallback } from "react";
2
+ import {
3
+ Pressable as NativePressable,
4
+ PressableProps,
5
+ PressableStateCallbackType,
6
+ StyleProp,
7
+ ViewStyle,
8
+ } from "react-native";
9
+
10
+ type Props = {
11
+ disabled?: boolean;
12
+ children: React.ReactNode;
13
+ style?: ViewStyle;
14
+ onPress?: () => void;
15
+ onLongPress?: () => void;
16
+ delayLongPress?: number;
17
+ hitSlop?: number;
18
+ pressRetentionOffset?: number;
19
+ activeOpacity?: number;
20
+ disabledOpacity?: number;
21
+ } & PressableProps;
22
+
23
+ export type StyleType = (
24
+ state: PressableStateCallbackType
25
+ ) => StyleProp<ViewStyle>;
26
+
27
+ export default function Pressable({
28
+ children,
29
+ disabled,
30
+ onPress,
31
+ onLongPress,
32
+ hitSlop,
33
+ delayLongPress,
34
+ activeOpacity,
35
+ disabledOpacity,
36
+ style,
37
+ ...props
38
+ }: Props) {
39
+ const getOpacity = useCallback(
40
+ (pressed: boolean) => {
41
+ if (disabled) {
42
+ return disabledOpacity;
43
+ } else {
44
+ if (pressed) return activeOpacity;
45
+ else return 1;
46
+ }
47
+ },
48
+ [activeOpacity, disabled, disabledOpacity]
49
+ );
50
+ const _style = useCallback<StyleType>(
51
+ ({ pressed }) => [style as ViewStyle, { opacity: getOpacity(pressed) }],
52
+ [getOpacity, style]
53
+ );
54
+ return (
55
+ <NativePressable
56
+ onPress={onPress}
57
+ onLongPress={onLongPress}
58
+ disabled={disabled}
59
+ delayLongPress={delayLongPress ? delayLongPress : 500}
60
+ hitSlop={hitSlop ? hitSlop : 8}
61
+ style={_style}
62
+ {...props}
63
+ >
64
+ {children}
65
+ </NativePressable>
66
+ );
67
+ }
@@ -1,12 +1,17 @@
1
- import React from "react";
2
- import { Pressable } from "react-native";
3
- export default function Touchable({ children, disabled, onPress, style, ...props }) {
4
- return (React.createElement(Pressable, { onPress: onPress, disabled: disabled, hitSlop: 8, style: ({ pressed }) => {
5
- return [
6
- {
7
- opacity: pressed || disabled ? 0.75 : 1,
8
- },
9
- style,
10
- ];
11
- }, ...props }, children));
1
+ import React, { useCallback } from "react";
2
+ import { Pressable, } from "react-native";
3
+ export default function Touchable({ children, disabled, onPress, onLongPress, hitSlop, delayLongPress, activeOpacity, disabledOpacity, style, ...props }) {
4
+ const getOpacity = useCallback((pressed) => {
5
+ if (disabled) {
6
+ return disabledOpacity;
7
+ }
8
+ else {
9
+ if (pressed)
10
+ return activeOpacity;
11
+ else
12
+ return 1;
13
+ }
14
+ }, [activeOpacity, disabled, disabledOpacity]);
15
+ const _style = useCallback(({ pressed }) => [style, { opacity: getOpacity(pressed) }], [getOpacity, style]);
16
+ return (React.createElement(Pressable, { onPress: onPress, onLongPress: onLongPress, disabled: disabled, delayLongPress: delayLongPress ? delayLongPress : 500, hitSlop: hitSlop ? hitSlop : 8, style: _style, ...props }, children));
12
17
  }
@@ -1,33 +1,64 @@
1
- import React from "react";
2
- import { Pressable, ViewStyle, PressableProps } from "react-native";
1
+ import React, { useCallback } from "react";
2
+ import {
3
+ Pressable,
4
+ PressableProps,
5
+ PressableStateCallbackType,
6
+ StyleProp,
7
+ ViewStyle,
8
+ } from "react-native";
3
9
 
4
10
  type Props = {
5
11
  disabled?: boolean;
6
12
  children: React.ReactNode;
7
13
  style?: ViewStyle;
8
14
  onPress?: () => void;
15
+ onLongPress?: () => void;
16
+ delayLongPress?: number;
17
+ hitSlop?: number;
18
+ pressRetentionOffset?: number;
19
+ activeOpacity?: number;
20
+ disabledOpacity?: number;
9
21
  } & PressableProps;
10
22
 
23
+ export type StyleType = (
24
+ state: PressableStateCallbackType
25
+ ) => StyleProp<ViewStyle>;
26
+
11
27
  export default function Touchable({
12
28
  children,
13
29
  disabled,
14
30
  onPress,
31
+ onLongPress,
32
+ hitSlop,
33
+ delayLongPress,
34
+ activeOpacity,
35
+ disabledOpacity,
15
36
  style,
16
37
  ...props
17
38
  }: Props) {
39
+ const getOpacity = useCallback(
40
+ (pressed: boolean) => {
41
+ if (disabled) {
42
+ return disabledOpacity;
43
+ } else {
44
+ if (pressed) return activeOpacity;
45
+ else return 1;
46
+ }
47
+ },
48
+ [activeOpacity, disabled, disabledOpacity]
49
+ );
50
+ const _style = useCallback<StyleType>(
51
+ ({ pressed }) => [style as ViewStyle, { opacity: getOpacity(pressed) }],
52
+ [getOpacity, style]
53
+ );
18
54
  return (
19
55
  <Pressable
20
56
  onPress={onPress}
57
+ onLongPress={onLongPress}
21
58
  disabled={disabled}
22
- hitSlop={8}
23
- style={({ pressed }) => {
24
- return [
25
- {
26
- opacity: pressed || disabled ? 0.75 : 1,
27
- },
28
- style,
29
- ];
30
- }}
59
+ delayLongPress={delayLongPress ? delayLongPress : 500}
60
+ hitSlop={hitSlop ? hitSlop : 8}
61
+ style={_style}
31
62
  {...props}
32
63
  >
33
64
  {children}
@@ -1,7 +1,8 @@
1
- import { COMPONENT_TYPES, createIconProp, createTextProp, createDisabledProp, createLoadingProp, createActionProp, Triggers, StylesPanelSections, } from "@draftbit/types";
2
- const SEED_DATA_TRIGGERS = [Triggers.OnPress];
1
+ import { COMPONENT_TYPES, createIconProp, createTextProp, createDisabledProp, createLoadingProp, createActionProp, Triggers, StylesPanelSections, createNumberProp, } from "@draftbit/types";
2
+ const SEED_DATA_TRIGGERS = [Triggers.OnPress, Triggers.OnLongPress];
3
3
  const SEED_DATA_PROPS = {
4
4
  onPress: createActionProp(),
5
+ onLongPress: createActionProp(),
5
6
  icon: createIconProp({
6
7
  defaultValue: null,
7
8
  required: false,
@@ -13,11 +14,10 @@ const SEED_DATA_PROPS = {
13
14
  }),
14
15
  disabled: createDisabledProp(),
15
16
  loading: createLoadingProp(),
16
- };
17
- const LAYOUT = {
18
- backgroundColor: "transparent",
19
- borderRadius: 8,
20
- fontFamily: "system-700",
17
+ activeOpacity: createNumberProp(),
18
+ disabledOpacity: createNumberProp(),
19
+ delayLongPress: createNumberProp(),
20
+ hitSlop: createNumberProp(),
21
21
  };
22
22
  export const SEED_DATA = [
23
23
  {
@@ -34,8 +34,9 @@ export const SEED_DATA = [
34
34
  StylesPanelSections.Effects,
35
35
  ],
36
36
  layout: {
37
- ...LAYOUT,
38
37
  backgroundColor: "transparent",
38
+ borderRadius: 8,
39
+ fontFamily: "system-700",
39
40
  borderWidth: 1,
40
41
  textAlign: "center",
41
42
  },
@@ -56,7 +57,8 @@ export const SEED_DATA = [
56
57
  StylesPanelSections.Effects,
57
58
  ],
58
59
  layout: {
59
- ...LAYOUT,
60
+ borderRadius: 8,
61
+ fontFamily: "system-700",
60
62
  backgroundColor: "primary",
61
63
  textAlign: "center",
62
64
  },
@@ -77,7 +79,8 @@ export const SEED_DATA = [
77
79
  StylesPanelSections.Effects,
78
80
  ],
79
81
  layout: {
80
- ...LAYOUT,
82
+ borderRadius: 8,
83
+ fontFamily: "system-700",
81
84
  backgroundColor: "primary",
82
85
  textAlign: "center",
83
86
  },