@draftbit/core 46.12.1-07ad46.2 → 46.12.1-2b2e2a.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 (199) hide show
  1. package/lib/commonjs/components/ActionSheet/index.js.map +1 -1
  2. package/lib/commonjs/components/AspectRatio.js +2 -16
  3. package/lib/commonjs/components/AspectRatio.js.map +1 -1
  4. package/lib/commonjs/components/AvatarEdit.js +4 -15
  5. package/lib/commonjs/components/AvatarEdit.js.map +1 -1
  6. package/lib/commonjs/components/Banner.js +4 -23
  7. package/lib/commonjs/components/Banner.js.map +1 -1
  8. package/lib/commonjs/components/BottomSheet/BottomSheet.js +18 -3
  9. package/lib/commonjs/components/BottomSheet/BottomSheet.js.map +1 -1
  10. package/lib/commonjs/components/BottomSheet/BottomSheetComponent.js +73 -120
  11. package/lib/commonjs/components/BottomSheet/BottomSheetComponent.js.map +1 -1
  12. package/lib/commonjs/components/Button.js +10 -32
  13. package/lib/commonjs/components/Button.js.map +1 -1
  14. package/lib/commonjs/components/Card.js.map +1 -1
  15. package/lib/commonjs/components/Checkbox/CheckboxGroupRow.js +22 -5
  16. package/lib/commonjs/components/Checkbox/CheckboxGroupRow.js.map +1 -1
  17. package/lib/commonjs/components/Checkbox/CheckboxRow.js +6 -23
  18. package/lib/commonjs/components/Checkbox/CheckboxRow.js.map +1 -1
  19. package/lib/commonjs/components/Checkbox/index.js.map +1 -1
  20. package/lib/commonjs/components/Container.js +4 -15
  21. package/lib/commonjs/components/Container.js.map +1 -1
  22. package/lib/commonjs/components/DatePicker/DatePickerComponent.web.js.map +1 -1
  23. package/lib/commonjs/components/DatePicker/DatePickerComponentType.js.map +1 -1
  24. package/lib/commonjs/components/DeckSwiper/DeckSwiperCard.js.map +1 -1
  25. package/lib/commonjs/components/DeckSwiper/index.js.map +1 -1
  26. package/lib/commonjs/components/Divider.js +1 -12
  27. package/lib/commonjs/components/Divider.js.map +1 -1
  28. package/lib/commonjs/components/Elevation.js +2 -13
  29. package/lib/commonjs/components/Elevation.js.map +1 -1
  30. package/lib/commonjs/components/FAB.js +4 -19
  31. package/lib/commonjs/components/FAB.js.map +1 -1
  32. package/lib/commonjs/components/FieldSearchBarFull.js +2 -1
  33. package/lib/commonjs/components/FieldSearchBarFull.js.map +1 -1
  34. package/lib/commonjs/components/FormRow.js +3 -17
  35. package/lib/commonjs/components/FormRow.js.map +1 -1
  36. package/lib/commonjs/components/Image.js +2 -16
  37. package/lib/commonjs/components/Image.js.map +1 -1
  38. package/lib/commonjs/components/Justification.js +1 -2
  39. package/lib/commonjs/components/Justification.js.map +1 -1
  40. package/lib/commonjs/components/Layout.js +19 -39
  41. package/lib/commonjs/components/Layout.js.map +1 -1
  42. package/lib/commonjs/components/Markdown.js.map +1 -1
  43. package/lib/commonjs/components/NumberInput.js +3 -11
  44. package/lib/commonjs/components/NumberInput.js.map +1 -1
  45. package/lib/commonjs/components/Picker/PickerTypes.js.map +1 -1
  46. package/lib/commonjs/components/Portal/PortalConsumer.js +2 -1
  47. package/lib/commonjs/components/Portal/PortalConsumer.js.map +1 -1
  48. package/lib/commonjs/components/Portal/PortalHost.js +14 -43
  49. package/lib/commonjs/components/Portal/PortalHost.js.map +1 -1
  50. package/lib/commonjs/components/Portal/PortalManager.js +8 -34
  51. package/lib/commonjs/components/Portal/PortalManager.js.map +1 -1
  52. package/lib/commonjs/components/Pressable.js +2 -15
  53. package/lib/commonjs/components/Pressable.js.map +1 -1
  54. package/lib/commonjs/components/ProgressBar.js +7 -36
  55. package/lib/commonjs/components/ProgressBar.js.map +1 -1
  56. package/lib/commonjs/components/ProgressIndicator.js.map +1 -1
  57. package/lib/commonjs/components/RadioButton/RadioButton.js +2 -14
  58. package/lib/commonjs/components/RadioButton/RadioButton.js.map +1 -1
  59. package/lib/commonjs/components/RadioButton/RadioButtonFieldGroup.js +1 -10
  60. package/lib/commonjs/components/RadioButton/RadioButtonFieldGroup.js.map +1 -1
  61. package/lib/commonjs/components/RadioButton/RadioButtonGroup.js +4 -16
  62. package/lib/commonjs/components/RadioButton/RadioButtonGroup.js.map +1 -1
  63. package/lib/commonjs/components/RadioButton/RadioButtonRow.js +5 -23
  64. package/lib/commonjs/components/RadioButton/RadioButtonRow.js.map +1 -1
  65. package/lib/commonjs/components/ResizeMode.js +1 -2
  66. package/lib/commonjs/components/ResizeMode.js.map +1 -1
  67. package/lib/commonjs/components/Row.js.map +1 -1
  68. package/lib/commonjs/components/RowBodyIcon.js.map +1 -1
  69. package/lib/commonjs/components/RowHeadlineImageIcon.js.map +1 -1
  70. package/lib/commonjs/components/SVG.js.map +1 -1
  71. package/lib/commonjs/components/ScreenContainer.js +6 -23
  72. package/lib/commonjs/components/ScreenContainer.js.map +1 -1
  73. package/lib/commonjs/components/Slider.js +4 -21
  74. package/lib/commonjs/components/Slider.js.map +1 -1
  75. package/lib/commonjs/components/StarRating.js +4 -22
  76. package/lib/commonjs/components/StarRating.js.map +1 -1
  77. package/lib/commonjs/components/StepIndicator.js +18 -57
  78. package/lib/commonjs/components/StepIndicator.js.map +1 -1
  79. package/lib/commonjs/components/SwipeableView/SwipeableView.js +157 -0
  80. package/lib/commonjs/components/SwipeableView/SwipeableView.js.map +1 -0
  81. package/lib/commonjs/components/SwipeableView/SwipeableViewButton.js +13 -0
  82. package/lib/commonjs/components/SwipeableView/SwipeableViewButton.js.map +1 -0
  83. package/lib/commonjs/components/SwipeableView/SwipeableViewSwipeHandler.js +13 -0
  84. package/lib/commonjs/components/SwipeableView/SwipeableViewSwipeHandler.js.map +1 -0
  85. package/lib/commonjs/components/SwipeableView/index.js +28 -0
  86. package/lib/commonjs/components/SwipeableView/index.js.map +1 -0
  87. package/lib/commonjs/components/Swiper/Swiper.js.map +1 -1
  88. package/lib/commonjs/components/Swiper/SwiperItem.js.map +1 -1
  89. package/lib/commonjs/components/Switch.js +10 -19
  90. package/lib/commonjs/components/Switch.js.map +1 -1
  91. package/lib/commonjs/components/TabView/TabView.js +7 -14
  92. package/lib/commonjs/components/TabView/TabView.js.map +1 -1
  93. package/lib/commonjs/components/TabView/TabViewItem.js.map +1 -1
  94. package/lib/commonjs/components/Table/Table.js +5 -6
  95. package/lib/commonjs/components/Table/Table.js.map +1 -1
  96. package/lib/commonjs/components/Table/TableCommon.js.map +1 -1
  97. package/lib/commonjs/components/Table/TableRow.js +2 -1
  98. package/lib/commonjs/components/Table/TableRow.js.map +1 -1
  99. package/lib/commonjs/components/Text.js +4 -50
  100. package/lib/commonjs/components/Text.js.map +1 -1
  101. package/lib/commonjs/components/TextField.js +28 -76
  102. package/lib/commonjs/components/TextField.js.map +1 -1
  103. package/lib/commonjs/components/ToggleButton.js +2 -14
  104. package/lib/commonjs/components/ToggleButton.js.map +1 -1
  105. package/lib/commonjs/components/Touchable.js +2 -15
  106. package/lib/commonjs/components/Touchable.js.map +1 -1
  107. package/lib/commonjs/components/Touchable.web.js.map +1 -1
  108. package/lib/commonjs/components/Typography.js.map +1 -1
  109. package/lib/commonjs/components/YoutubePlayer/YoutubePlayer.native.js.map +1 -1
  110. package/lib/commonjs/components/YoutubePlayer/YoutubePlayerProps.js.map +1 -1
  111. package/lib/commonjs/components/useAuthState.js.map +1 -1
  112. package/lib/commonjs/index.js +19 -0
  113. package/lib/commonjs/index.js.map +1 -1
  114. package/lib/commonjs/mappings/BottomSheet.js +37 -9
  115. package/lib/commonjs/mappings/BottomSheet.js.map +1 -1
  116. package/lib/commonjs/mappings/FlatList.js +0 -3
  117. package/lib/commonjs/mappings/FlatList.js.map +1 -1
  118. package/lib/commonjs/mappings/MapMarker.js +15 -0
  119. package/lib/commonjs/mappings/MapMarker.js.map +1 -1
  120. package/lib/commonjs/mappings/MapView.js +5 -0
  121. package/lib/commonjs/mappings/MapView.js.map +1 -1
  122. package/lib/commonjs/mappings/SwipeableView.js +183 -0
  123. package/lib/commonjs/mappings/SwipeableView.js.map +1 -0
  124. package/lib/commonjs/utilities.js +28 -3
  125. package/lib/commonjs/utilities.js.map +1 -1
  126. package/lib/module/components/BottomSheet/BottomSheet.js +18 -3
  127. package/lib/module/components/BottomSheet/BottomSheet.js.map +1 -1
  128. package/lib/module/components/Button.js +32 -10
  129. package/lib/module/components/SwipeableView/SwipeableView.js +149 -0
  130. package/lib/module/components/SwipeableView/SwipeableView.js.map +1 -0
  131. package/lib/module/components/SwipeableView/SwipeableViewButton.js +6 -0
  132. package/lib/module/components/SwipeableView/SwipeableViewButton.js.map +1 -0
  133. package/lib/module/components/SwipeableView/SwipeableViewSwipeHandler.js +6 -0
  134. package/lib/module/components/SwipeableView/SwipeableViewSwipeHandler.js.map +1 -0
  135. package/lib/module/components/SwipeableView/index.js +4 -0
  136. package/lib/module/components/SwipeableView/index.js.map +1 -0
  137. package/lib/module/index.js +1 -0
  138. package/lib/module/index.js.map +1 -1
  139. package/lib/module/mappings/BottomSheet.js +38 -10
  140. package/lib/module/mappings/BottomSheet.js.map +1 -1
  141. package/lib/module/mappings/FlatList.js +0 -3
  142. package/lib/module/mappings/FlatList.js.map +1 -1
  143. package/lib/module/mappings/MapMarker.js +16 -1
  144. package/lib/module/mappings/MapMarker.js.map +1 -1
  145. package/lib/module/mappings/MapView.js +6 -1
  146. package/lib/module/mappings/MapView.js.map +1 -1
  147. package/lib/module/mappings/SwipeableView.js +175 -0
  148. package/lib/module/mappings/SwipeableView.js.map +1 -0
  149. package/lib/module/utilities.js +19 -1
  150. package/lib/module/utilities.js.map +1 -1
  151. package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts +6 -1
  152. package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts.map +1 -1
  153. package/lib/typescript/src/components/SwipeableView/SwipeableView.d.ts +29 -0
  154. package/lib/typescript/src/components/SwipeableView/SwipeableView.d.ts.map +1 -0
  155. package/lib/typescript/src/components/SwipeableView/SwipeableViewButton.d.ts +13 -0
  156. package/lib/typescript/src/components/SwipeableView/SwipeableViewButton.d.ts.map +1 -0
  157. package/lib/typescript/src/components/SwipeableView/SwipeableViewSwipeHandler.d.ts +13 -0
  158. package/lib/typescript/src/components/SwipeableView/SwipeableViewSwipeHandler.d.ts.map +1 -0
  159. package/lib/typescript/src/components/SwipeableView/index.d.ts +4 -0
  160. package/lib/typescript/src/components/SwipeableView/index.d.ts.map +1 -0
  161. package/lib/typescript/src/index.d.ts +1 -0
  162. package/lib/typescript/src/index.d.ts.map +1 -1
  163. package/lib/typescript/src/mappings/BottomSheet.d.ts +48 -4
  164. package/lib/typescript/src/mappings/BottomSheet.d.ts.map +1 -1
  165. package/lib/typescript/src/mappings/FlatList.d.ts +0 -3
  166. package/lib/typescript/src/mappings/FlatList.d.ts.map +1 -1
  167. package/lib/typescript/src/mappings/MapMarker.d.ts +32 -0
  168. package/lib/typescript/src/mappings/MapMarker.d.ts.map +1 -1
  169. package/lib/typescript/src/mappings/MapView.d.ts +11 -0
  170. package/lib/typescript/src/mappings/MapView.d.ts.map +1 -1
  171. package/lib/typescript/src/mappings/SwipeableView.d.ts +426 -0
  172. package/lib/typescript/src/mappings/SwipeableView.d.ts.map +1 -0
  173. package/lib/typescript/src/utilities.d.ts +6 -0
  174. package/lib/typescript/src/utilities.d.ts.map +1 -1
  175. package/package.json +4 -3
  176. package/src/components/BottomSheet/BottomSheet.js +17 -2
  177. package/src/components/BottomSheet/BottomSheet.tsx +32 -4
  178. package/src/components/SwipeableView/SwipeableView.js +121 -0
  179. package/src/components/SwipeableView/SwipeableView.tsx +304 -0
  180. package/src/components/SwipeableView/SwipeableViewButton.js +5 -0
  181. package/src/components/SwipeableView/SwipeableViewButton.tsx +18 -0
  182. package/src/components/SwipeableView/SwipeableViewSwipeHandler.js +5 -0
  183. package/src/components/SwipeableView/SwipeableViewSwipeHandler.tsx +20 -0
  184. package/src/components/SwipeableView/index.js +3 -0
  185. package/src/components/SwipeableView/index.tsx +3 -0
  186. package/src/index.js +1 -0
  187. package/src/index.tsx +6 -0
  188. package/src/mappings/BottomSheet.js +37 -9
  189. package/src/mappings/BottomSheet.ts +43 -8
  190. package/src/mappings/FlatList.js +0 -3
  191. package/src/mappings/FlatList.ts +0 -3
  192. package/src/mappings/MapMarker.js +16 -1
  193. package/src/mappings/MapMarker.ts +20 -0
  194. package/src/mappings/MapView.js +6 -1
  195. package/src/mappings/MapView.ts +8 -0
  196. package/src/mappings/SwipeableView.js +181 -0
  197. package/src/mappings/SwipeableView.ts +210 -0
  198. package/src/utilities.js +42 -1
  199. package/src/utilities.ts +72 -1
@@ -2,10 +2,25 @@ import React from "react";
2
2
  import { StyleSheet, View, } from "react-native";
3
3
  import BottomSheetComponent from "./BottomSheetComponent";
4
4
  import { withTheme } from "../../theming";
5
- const BottomSheet = ({ theme, snapPoints = ["10%", "50%", "80%"], initialSnapIndex = 0, showHandle = true, handleColor = theme.colors.divider, topBorderRadius = 20, borderWidth = 1, borderColor = theme.colors.divider, onSettle, style, children, ...rest }) => {
5
+ const BottomSheet = ({ theme, snapPoints: snapPointsProp, topSnapPosition = "10%", middleSnapPosition = "50%", bottomSnapPosition = "80%", initialSnapIndex, initialSnapPosition = "bottom", showHandle = true, handleColor = theme.colors.divider, topBorderRadius = 20, borderWidth = 1, borderColor = theme.colors.divider, onSettle, style, children, ...rest }) => {
6
6
  const backgroundColor = (style === null || style === void 0 ? void 0 : style.backgroundColor) || theme.colors.background;
7
+ const snapPoints = snapPointsProp || [
8
+ topSnapPosition,
9
+ middleSnapPosition,
10
+ bottomSnapPosition,
11
+ ];
12
+ const getSnapIndexFromPosition = (position) => {
13
+ switch (position) {
14
+ case "top":
15
+ return 0;
16
+ case "middle":
17
+ return 1;
18
+ case "bottom":
19
+ return 2;
20
+ }
21
+ };
7
22
  return (React.createElement(View, { style: styles.parentContainer, pointerEvents: "box-none" },
8
- React.createElement(BottomSheetComponent, { componentType: "ScrollView", snapPoints: snapPoints, initialSnapIndex: initialSnapIndex, renderHandle: () => (React.createElement(React.Fragment, null, showHandle && (React.createElement(View, { style: [
23
+ React.createElement(BottomSheetComponent, { componentType: "ScrollView", snapPoints: snapPoints, initialSnapIndex: initialSnapIndex !== null && initialSnapIndex !== void 0 ? initialSnapIndex : getSnapIndexFromPosition(initialSnapPosition), renderHandle: () => (React.createElement(React.Fragment, null, showHandle && (React.createElement(View, { style: [
9
24
  styles.handleContainer,
10
25
  {
11
26
  backgroundColor,
@@ -11,9 +11,14 @@ import BottomSheetComponent from "./BottomSheetComponent";
11
11
  import type { Theme } from "../../styles/DefaultTheme";
12
12
  import { withTheme } from "../../theming";
13
13
 
14
+ type SnapPosition = "top" | "middle" | "bottom";
14
15
  export interface BottomSheetProps extends ScrollViewProps {
15
- snapPoints?: (string | number)[];
16
+ topSnapPosition?: string | number;
17
+ middleSnapPosition?: string | number;
18
+ bottomSnapPosition?: string | number;
19
+ snapPoints: (string | number)[];
16
20
  initialSnapIndex?: number;
21
+ initialSnapPosition: SnapPosition;
17
22
  showHandle?: boolean;
18
23
  handleColor?: string;
19
24
  topBorderRadius?: number;
@@ -26,8 +31,12 @@ export interface BottomSheetProps extends ScrollViewProps {
26
31
 
27
32
  const BottomSheet: React.FC<React.PropsWithChildren<BottomSheetProps>> = ({
28
33
  theme,
29
- snapPoints = ["10%", "50%", "80%"],
30
- initialSnapIndex = 0,
34
+ snapPoints: snapPointsProp,
35
+ topSnapPosition = "10%",
36
+ middleSnapPosition = "50%",
37
+ bottomSnapPosition = "80%",
38
+ initialSnapIndex,
39
+ initialSnapPosition = "bottom",
31
40
  showHandle = true,
32
41
  handleColor = theme.colors.divider,
33
42
  topBorderRadius = 20,
@@ -41,12 +50,31 @@ const BottomSheet: React.FC<React.PropsWithChildren<BottomSheetProps>> = ({
41
50
  const backgroundColor =
42
51
  (style as ViewStyle)?.backgroundColor || theme.colors.background;
43
52
 
53
+ const snapPoints = snapPointsProp || [
54
+ topSnapPosition,
55
+ middleSnapPosition,
56
+ bottomSnapPosition,
57
+ ];
58
+
59
+ const getSnapIndexFromPosition = (position: SnapPosition) => {
60
+ switch (position) {
61
+ case "top":
62
+ return 0;
63
+ case "middle":
64
+ return 1;
65
+ case "bottom":
66
+ return 2;
67
+ }
68
+ };
69
+
44
70
  return (
45
71
  <View style={styles.parentContainer} pointerEvents="box-none">
46
72
  <BottomSheetComponent
47
73
  componentType="ScrollView"
48
74
  snapPoints={snapPoints}
49
- initialSnapIndex={initialSnapIndex}
75
+ initialSnapIndex={
76
+ initialSnapIndex ?? getSnapIndexFromPosition(initialSnapPosition)
77
+ }
50
78
  renderHandle={() => (
51
79
  <>
52
80
  {showHandle && (
@@ -0,0 +1,121 @@
1
+ import React from "react";
2
+ import { View, StyleSheet, Text, } from "react-native";
3
+ import Pressable from "../Pressable";
4
+ import { extractBorderAndMarginStyles, extractEffectStyles, extractFlexItemStyles, extractPositionStyles, extractSizeStyles, extractStyles, } from "../../utilities";
5
+ import { SwipeRow } from "react-native-swipe-list-view";
6
+ import { withTheme } from "../../theming";
7
+ const SwipeableView = ({ theme, style, children, Icon, closeOnPress, leftOpenValue, rightOpenValue, leftActivationValue, rightActivationValue, swipeActivationPercentage = 80, stopLeftSwipe, stopRightSwipe, friction = 20, ...rest }) => {
8
+ const instanceOfSwipeableViewButtonProps = (object) => {
9
+ return "title" in object && "side" in object && "onPress" in object;
10
+ };
11
+ const instanceOfSwipeableViewSwipeHandlerProps = (object) => {
12
+ return "title" in object && "side" in object && "onSwipe" in object;
13
+ };
14
+ const { viewStyles, textStyles } = extractStyles(style);
15
+ const { borderStyles, marginStyles } = extractBorderAndMarginStyles(viewStyles);
16
+ const sizeStyles = extractSizeStyles(viewStyles);
17
+ const parentContainerStyles = StyleSheet.flatten([
18
+ borderStyles,
19
+ marginStyles,
20
+ extractFlexItemStyles(viewStyles),
21
+ extractPositionStyles(viewStyles),
22
+ extractEffectStyles(viewStyles),
23
+ sizeStyles,
24
+ ]);
25
+ //Remove styles already consumed from viewStyles
26
+ Object.keys(parentContainerStyles).forEach((key) => delete viewStyles[key]);
27
+ const surfaceContainerStyles = StyleSheet.flatten([
28
+ viewStyles,
29
+ sizeStyles /* Size styles needs to be readded to surface container due to inconsistencies on web */,
30
+ ]);
31
+ const [componentWidth, setComponentWidth] = React.useState(null);
32
+ const leftButtons = React.useMemo(() => React.Children.toArray(children).filter((child) => React.isValidElement(child) &&
33
+ instanceOfSwipeableViewButtonProps(child.props) &&
34
+ child.props.side === "left"), [children]);
35
+ const rightButtons = React.useMemo(() => React.Children.toArray(children).filter((child) => React.isValidElement(child) &&
36
+ instanceOfSwipeableViewButtonProps(child.props) &&
37
+ child.props.side === "right"), [children]);
38
+ const leftSwipeHandlers = React.useMemo(() => React.Children.toArray(children).filter((child) => React.isValidElement(child) &&
39
+ instanceOfSwipeableViewSwipeHandlerProps(child.props) &&
40
+ child.props.side === "left"), [children]);
41
+ const rightSwipeHandlers = React.useMemo(() => React.Children.toArray(children).filter((child) => React.isValidElement(child) &&
42
+ instanceOfSwipeableViewSwipeHandlerProps(child.props) &&
43
+ child.props.side === "right"), [children]);
44
+ const remainingChildren = React.useMemo(() => React.Children.toArray(children).filter((child) => React.isValidElement(child) &&
45
+ !instanceOfSwipeableViewSwipeHandlerProps(child.props) &&
46
+ !instanceOfSwipeableViewButtonProps(child.props)), [children]);
47
+ if (leftButtons.length > 2 || rightButtons.length > 2) {
48
+ throw Error("Cannot have more than 2 buttons per side");
49
+ }
50
+ if (leftSwipeHandlers.length > 1 || rightSwipeHandlers.length > 1) {
51
+ throw Error("Cannot have more than 1 swiper handler per side");
52
+ }
53
+ if ((leftButtons.length && leftSwipeHandlers.length) ||
54
+ (rightButtons.length && rightSwipeHandlers.length)) {
55
+ throw Error("Cannot combine swiper handler and buttons on the same side");
56
+ }
57
+ //Renders a single button/item. Used for both buttons and swipe handler
58
+ const renderBehindItem = (props, index) => (React.createElement(Pressable, { key: index.toString(), onPress: props.onPress, style: [
59
+ styles.buttonContainer,
60
+ { backgroundColor: props.backgroundColor || theme.colors.primary },
61
+ ] },
62
+ props.icon && (React.createElement(Icon, { name: props.icon, size: props.iconSize || 25, color: props.color || theme.colors.surface })),
63
+ React.createElement(Text, { style: [textStyles, { color: props.color || theme.colors.surface }] }, props.title)));
64
+ const isLeftSwipeHandler = !!leftSwipeHandlers.length;
65
+ const isRightSwipeHandler = !!rightSwipeHandlers.length;
66
+ const defaultLeftOpenValue = componentWidth ? componentWidth / 2 : 0;
67
+ const defaultRightOpenValue = componentWidth ? -componentWidth / 2 : 0;
68
+ return (React.createElement(View, { onLayout: (event) => {
69
+ setComponentWidth(event.nativeEvent.layout.width);
70
+ }, style: [styles.parentContainer, parentContainerStyles] },
71
+ React.createElement(SwipeRow, { leftOpenValue: isLeftSwipeHandler ? 0 : leftOpenValue || defaultLeftOpenValue //If in swiping mode, don't keep open
72
+ , rightOpenValue: isRightSwipeHandler ? 0 : rightOpenValue || defaultRightOpenValue, leftActivationValue: leftActivationValue || isLeftSwipeHandler
73
+ ? defaultLeftOpenValue * (swipeActivationPercentage / 100) //When swipe passes activation percentage then it should be considered activated (call onSwipe)
74
+ : defaultLeftOpenValue, rightActivationValue: rightActivationValue || isRightSwipeHandler
75
+ ? defaultRightOpenValue * (swipeActivationPercentage / 100)
76
+ : defaultRightOpenValue, stopLeftSwipe: stopLeftSwipe || defaultLeftOpenValue, stopRightSwipe: stopRightSwipe || defaultRightOpenValue, onLeftAction: isLeftSwipeHandler
77
+ ? () => { var _a, _b; return (_b = (_a = leftSwipeHandlers[0].props).onSwipe) === null || _b === void 0 ? void 0 : _b.call(_a); }
78
+ : undefined, onRightAction: isRightSwipeHandler
79
+ ? () => { var _a, _b; return (_b = (_a = rightSwipeHandlers[0].props).onSwipe) === null || _b === void 0 ? void 0 : _b.call(_a); }
80
+ : undefined, closeOnRowPress: closeOnPress, friction: friction, ...rest },
81
+ React.createElement(View, { style: styles.behindContainer },
82
+ React.createElement(View, { style: styles.behindContainerItem }, (isLeftSwipeHandler ? leftSwipeHandlers : leftButtons).map((item, index) => renderBehindItem(item.props, index))),
83
+ React.createElement(View, { style: styles.behindContainerItem }, (isRightSwipeHandler ? rightSwipeHandlers : rightButtons).map((item, index) => renderBehindItem(item.props, index)))),
84
+ React.createElement(View, { style: [
85
+ styles.surfaceContainer,
86
+ {
87
+ backgroundColor: theme.colors.background,
88
+ },
89
+ surfaceContainerStyles,
90
+ ] }, remainingChildren))));
91
+ };
92
+ const styles = StyleSheet.create({
93
+ parentContainer: {
94
+ overflow: "hidden",
95
+ minHeight: 50,
96
+ },
97
+ behindContainer: {
98
+ flex: 1,
99
+ width: "100%",
100
+ height: "100%",
101
+ flexDirection: "row",
102
+ },
103
+ behindContainerItem: {
104
+ flex: 1,
105
+ flexDirection: "row",
106
+ },
107
+ buttonContainer: {
108
+ flex: 1,
109
+ alignItems: "center",
110
+ justifyContent: "center",
111
+ },
112
+ surfaceContainer: {
113
+ flexDirection: "row",
114
+ width: "100%",
115
+ minHeight: 50,
116
+ padding: 10,
117
+ alignItems: "center",
118
+ overflow: "hidden",
119
+ },
120
+ });
121
+ export default withTheme(SwipeableView);
@@ -0,0 +1,304 @@
1
+ import React from "react";
2
+ import {
3
+ View,
4
+ StyleProp,
5
+ ViewStyle,
6
+ TextStyle,
7
+ StyleSheet,
8
+ Text,
9
+ } from "react-native";
10
+ import Pressable from "../Pressable";
11
+ import {
12
+ extractBorderAndMarginStyles,
13
+ extractEffectStyles,
14
+ extractFlexItemStyles,
15
+ extractPositionStyles,
16
+ extractSizeStyles,
17
+ extractStyles,
18
+ } from "../../utilities";
19
+ import { SwipeRow } from "react-native-swipe-list-view";
20
+ import { IconSlot } from "../../interfaces/Icon";
21
+ import type { Theme } from "../../styles/DefaultTheme";
22
+ import { withTheme } from "../../theming";
23
+ import { SwipeableViewButtonProps } from "./SwipeableViewButton";
24
+ import { SwipeableViewSwipeHandlerProps } from "./SwipeableViewSwipeHandler";
25
+
26
+ export interface SwipeableViewProps extends IconSlot {
27
+ closeOnPress?: boolean;
28
+ leftOpenValue?: number;
29
+ rightOpenValue?: number;
30
+ leftActivationValue?: number;
31
+ rightActivationValue?: number;
32
+ swipeActivationPercentage?: number;
33
+ stopLeftSwipe?: number;
34
+ stopRightSwipe?: number;
35
+ directionalDistanceChangeThreshold?: number;
36
+ friction?: number;
37
+ tension?: number;
38
+ disableLeftSwipe?: boolean;
39
+ disableRightSwipe?: boolean;
40
+ swipeToOpenVelocityContribution?: number;
41
+ swipeToOpenPercent?: number;
42
+ swipeToClosePercent?: number;
43
+ style?: StyleProp<ViewStyle | TextStyle>;
44
+ theme: Theme;
45
+ }
46
+
47
+ const SwipeableView: React.FC<React.PropsWithChildren<SwipeableViewProps>> = ({
48
+ theme,
49
+ style,
50
+ children,
51
+ Icon,
52
+ closeOnPress,
53
+ leftOpenValue,
54
+ rightOpenValue,
55
+ leftActivationValue,
56
+ rightActivationValue,
57
+ swipeActivationPercentage = 80,
58
+ stopLeftSwipe,
59
+ stopRightSwipe,
60
+ friction = 20,
61
+ ...rest
62
+ }) => {
63
+ const instanceOfSwipeableViewButtonProps = (
64
+ object: any
65
+ ): object is SwipeableViewButtonProps => {
66
+ return "title" in object && "side" in object && "onPress" in object;
67
+ };
68
+
69
+ const instanceOfSwipeableViewSwipeHandlerProps = (
70
+ object: any
71
+ ): object is SwipeableViewSwipeHandlerProps => {
72
+ return "title" in object && "side" in object && "onSwipe" in object;
73
+ };
74
+
75
+ const { viewStyles, textStyles } = extractStyles(style);
76
+
77
+ const { borderStyles, marginStyles } =
78
+ extractBorderAndMarginStyles(viewStyles);
79
+
80
+ const sizeStyles = extractSizeStyles(viewStyles);
81
+
82
+ const parentContainerStyles = StyleSheet.flatten([
83
+ borderStyles,
84
+ marginStyles,
85
+ extractFlexItemStyles(viewStyles),
86
+ extractPositionStyles(viewStyles),
87
+ extractEffectStyles(viewStyles),
88
+ sizeStyles,
89
+ ]);
90
+
91
+ //Remove styles already consumed from viewStyles
92
+ Object.keys(parentContainerStyles).forEach((key) => delete viewStyles[key]);
93
+ const surfaceContainerStyles = StyleSheet.flatten([
94
+ viewStyles,
95
+ sizeStyles /* Size styles needs to be readded to surface container due to inconsistencies on web */,
96
+ ]);
97
+
98
+ const [componentWidth, setComponentWidth] = React.useState<number | null>(
99
+ null
100
+ );
101
+ const leftButtons = React.useMemo(
102
+ () =>
103
+ React.Children.toArray(children).filter(
104
+ (child) =>
105
+ React.isValidElement(child) &&
106
+ instanceOfSwipeableViewButtonProps(child.props) &&
107
+ child.props.side === "left"
108
+ ) as React.ReactElement<SwipeableViewButtonProps>[],
109
+ [children]
110
+ );
111
+
112
+ const rightButtons = React.useMemo(
113
+ () =>
114
+ React.Children.toArray(children).filter(
115
+ (child) =>
116
+ React.isValidElement(child) &&
117
+ instanceOfSwipeableViewButtonProps(child.props) &&
118
+ child.props.side === "right"
119
+ ) as React.ReactElement<SwipeableViewButtonProps>[],
120
+ [children]
121
+ );
122
+
123
+ const leftSwipeHandlers = React.useMemo(
124
+ () =>
125
+ React.Children.toArray(children).filter(
126
+ (child) =>
127
+ React.isValidElement(child) &&
128
+ instanceOfSwipeableViewSwipeHandlerProps(child.props) &&
129
+ child.props.side === "left"
130
+ ) as React.ReactElement<SwipeableViewSwipeHandlerProps>[],
131
+ [children]
132
+ );
133
+
134
+ const rightSwipeHandlers = React.useMemo(
135
+ () =>
136
+ React.Children.toArray(children).filter(
137
+ (child) =>
138
+ React.isValidElement(child) &&
139
+ instanceOfSwipeableViewSwipeHandlerProps(child.props) &&
140
+ child.props.side === "right"
141
+ ) as React.ReactElement<SwipeableViewSwipeHandlerProps>[],
142
+ [children]
143
+ );
144
+
145
+ const remainingChildren = React.useMemo(
146
+ () =>
147
+ React.Children.toArray(children).filter(
148
+ (child) =>
149
+ React.isValidElement(child) &&
150
+ !instanceOfSwipeableViewSwipeHandlerProps(child.props) &&
151
+ !instanceOfSwipeableViewButtonProps(child.props)
152
+ ),
153
+ [children]
154
+ );
155
+
156
+ if (leftButtons.length > 2 || rightButtons.length > 2) {
157
+ throw Error("Cannot have more than 2 buttons per side");
158
+ }
159
+
160
+ if (leftSwipeHandlers.length > 1 || rightSwipeHandlers.length > 1) {
161
+ throw Error("Cannot have more than 1 swiper handler per side");
162
+ }
163
+
164
+ if (
165
+ (leftButtons.length && leftSwipeHandlers.length) ||
166
+ (rightButtons.length && rightSwipeHandlers.length)
167
+ ) {
168
+ throw Error("Cannot combine swiper handler and buttons on the same side");
169
+ }
170
+
171
+ //Renders a single button/item. Used for both buttons and swipe handler
172
+ const renderBehindItem = (
173
+ props: SwipeableViewSwipeHandlerProps | SwipeableViewButtonProps,
174
+ index: number
175
+ ) => (
176
+ <Pressable
177
+ key={index.toString()}
178
+ onPress={(props as any).onPress}
179
+ style={[
180
+ styles.buttonContainer,
181
+ { backgroundColor: props.backgroundColor || theme.colors.primary },
182
+ ]}
183
+ >
184
+ {props.icon && (
185
+ <Icon
186
+ name={props.icon}
187
+ size={props.iconSize || 25}
188
+ color={props.color || theme.colors.surface}
189
+ />
190
+ )}
191
+ <Text
192
+ style={[textStyles, { color: props.color || theme.colors.surface }]}
193
+ >
194
+ {props.title}
195
+ </Text>
196
+ </Pressable>
197
+ );
198
+
199
+ const isLeftSwipeHandler = !!leftSwipeHandlers.length;
200
+ const isRightSwipeHandler = !!rightSwipeHandlers.length;
201
+
202
+ const defaultLeftOpenValue = componentWidth ? componentWidth / 2 : 0;
203
+ const defaultRightOpenValue = componentWidth ? -componentWidth / 2 : 0;
204
+
205
+ return (
206
+ <View
207
+ onLayout={(event) => {
208
+ setComponentWidth(event.nativeEvent.layout.width);
209
+ }}
210
+ style={[styles.parentContainer, parentContainerStyles]}
211
+ >
212
+ {/*@ts-ignore*/}
213
+ <SwipeRow
214
+ leftOpenValue={
215
+ isLeftSwipeHandler ? 0 : leftOpenValue || defaultLeftOpenValue //If in swiping mode, don't keep open
216
+ }
217
+ rightOpenValue={
218
+ isRightSwipeHandler ? 0 : rightOpenValue || defaultRightOpenValue
219
+ }
220
+ leftActivationValue={
221
+ leftActivationValue || isLeftSwipeHandler
222
+ ? defaultLeftOpenValue * (swipeActivationPercentage / 100) //When swipe passes activation percentage then it should be considered activated (call onSwipe)
223
+ : defaultLeftOpenValue
224
+ }
225
+ rightActivationValue={
226
+ rightActivationValue || isRightSwipeHandler
227
+ ? defaultRightOpenValue * (swipeActivationPercentage / 100)
228
+ : defaultRightOpenValue
229
+ }
230
+ stopLeftSwipe={stopLeftSwipe || defaultLeftOpenValue}
231
+ stopRightSwipe={stopRightSwipe || defaultRightOpenValue}
232
+ onLeftAction={
233
+ isLeftSwipeHandler
234
+ ? () => leftSwipeHandlers[0].props.onSwipe?.()
235
+ : undefined
236
+ }
237
+ onRightAction={
238
+ isRightSwipeHandler
239
+ ? () => rightSwipeHandlers[0].props.onSwipe?.()
240
+ : undefined
241
+ }
242
+ closeOnRowPress={closeOnPress}
243
+ friction={friction}
244
+ {...rest}
245
+ >
246
+ <View style={styles.behindContainer}>
247
+ <View style={styles.behindContainerItem}>
248
+ {(isLeftSwipeHandler ? leftSwipeHandlers : leftButtons).map(
249
+ (item, index) => renderBehindItem(item.props, index)
250
+ )}
251
+ </View>
252
+ <View style={styles.behindContainerItem}>
253
+ {(isRightSwipeHandler ? rightSwipeHandlers : rightButtons).map(
254
+ (item, index) => renderBehindItem(item.props, index)
255
+ )}
256
+ </View>
257
+ </View>
258
+ <View
259
+ style={[
260
+ styles.surfaceContainer,
261
+ {
262
+ backgroundColor: theme.colors.background,
263
+ },
264
+ surfaceContainerStyles,
265
+ ]}
266
+ >
267
+ {remainingChildren}
268
+ </View>
269
+ </SwipeRow>
270
+ </View>
271
+ );
272
+ };
273
+
274
+ const styles = StyleSheet.create({
275
+ parentContainer: {
276
+ overflow: "hidden",
277
+ minHeight: 50,
278
+ },
279
+ behindContainer: {
280
+ flex: 1,
281
+ width: "100%",
282
+ height: "100%",
283
+ flexDirection: "row",
284
+ },
285
+ behindContainerItem: {
286
+ flex: 1,
287
+ flexDirection: "row",
288
+ },
289
+ buttonContainer: {
290
+ flex: 1,
291
+ alignItems: "center",
292
+ justifyContent: "center",
293
+ },
294
+ surfaceContainer: {
295
+ flexDirection: "row",
296
+ width: "100%",
297
+ minHeight: 50,
298
+ padding: 10,
299
+ alignItems: "center",
300
+ overflow: "hidden",
301
+ },
302
+ });
303
+
304
+ export default withTheme(SwipeableView);
@@ -0,0 +1,5 @@
1
+ //Renders nothing, acts as a wrapper be used by SwipeableView
2
+ const SwipeableViewButton = () => {
3
+ return null;
4
+ };
5
+ export default SwipeableViewButton;
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+
3
+ export interface SwipeableViewButtonProps {
4
+ title: string;
5
+ side: "left" | "right";
6
+ onPress?: () => void;
7
+ icon?: string;
8
+ iconSize?: number;
9
+ backgroundColor?: string;
10
+ color?: string;
11
+ }
12
+
13
+ //Renders nothing, acts as a wrapper be used by SwipeableView
14
+ const SwipeableViewButton: React.FC<SwipeableViewButtonProps> = () => {
15
+ return null;
16
+ };
17
+
18
+ export default SwipeableViewButton;
@@ -0,0 +1,5 @@
1
+ //Renders nothing, acts as a wrapper to be used by SwipeableView
2
+ const SwipeableViewSwipeHandler = () => {
3
+ return null;
4
+ };
5
+ export default SwipeableViewSwipeHandler;
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+
3
+ export interface SwipeableViewSwipeHandlerProps {
4
+ title: string;
5
+ side: "left" | "right";
6
+ onSwipe?: () => void;
7
+ icon?: string;
8
+ iconSize?: number;
9
+ backgroundColor?: string;
10
+ color?: string;
11
+ }
12
+
13
+ //Renders nothing, acts as a wrapper to be used by SwipeableView
14
+ const SwipeableViewSwipeHandler: React.FC<
15
+ SwipeableViewSwipeHandlerProps
16
+ > = () => {
17
+ return null;
18
+ };
19
+
20
+ export default SwipeableViewSwipeHandler;
@@ -0,0 +1,3 @@
1
+ export { default as SwipeableView } from "./SwipeableView";
2
+ export { default as SwipeableViewButton } from "./SwipeableViewButton";
3
+ export { default as SwipeableViewSwipeHandler } from "./SwipeableViewSwipeHandler";
@@ -0,0 +1,3 @@
1
+ export { default as SwipeableView } from "./SwipeableView";
2
+ export { default as SwipeableViewButton } from "./SwipeableViewButton";
3
+ export { default as SwipeableViewSwipeHandler } from "./SwipeableViewSwipeHandler";
package/src/index.js CHANGED
@@ -38,6 +38,7 @@ export { default as Markdown } from "./components/Markdown";
38
38
  export { BottomSheet } from "./components/BottomSheet";
39
39
  export { YoutubePlayer } from "./components/YoutubePlayer";
40
40
  export { Table, TableRow, TableCell } from "./components/Table";
41
+ export { SwipeableView, SwipeableViewButton, SwipeableViewSwipeHandler, } from "./components/SwipeableView";
41
42
  /* Deprecated: Fix or Delete! */
42
43
  export { default as DatePicker } from "./components/DatePicker/DatePicker";
43
44
  export { default as Picker } from "./components/Picker/Picker";
package/src/index.tsx CHANGED
@@ -64,6 +64,12 @@ export { YoutubePlayer } from "./components/YoutubePlayer";
64
64
 
65
65
  export { Table, TableRow, TableCell } from "./components/Table";
66
66
 
67
+ export {
68
+ SwipeableView,
69
+ SwipeableViewButton,
70
+ SwipeableViewSwipeHandler,
71
+ } from "./components/SwipeableView";
72
+
67
73
  /* Deprecated: Fix or Delete! */
68
74
  export { default as DatePicker } from "./components/DatePicker/DatePicker";
69
75
  export { default as Picker } from "./components/Picker/Picker";
@@ -1,4 +1,4 @@
1
- import { COMPONENT_TYPES, createStaticBoolProp, CONTAINER_COMPONENT_STYLES_SECTIONS, Triggers, createActionProp, createColorProp, createStaticNumberProp, createArrayProp, } from "@draftbit/types";
1
+ import { COMPONENT_TYPES, createStaticBoolProp, CONTAINER_COMPONENT_STYLES_SECTIONS, Triggers, createActionProp, createColorProp, createStaticNumberProp, createArrayProp, GROUPS, createTextEnumProp, FORM_TYPES, } from "@draftbit/types";
2
2
  export const SEED_DATA = {
3
3
  name: "Bottom Sheet",
4
4
  tag: "BottomSheet",
@@ -11,16 +11,32 @@ export const SEED_DATA = {
11
11
  label: "On settle",
12
12
  description: "Action to execute when sheet settles on a snap point",
13
13
  }),
14
- snapPoints: createArrayProp({
15
- label: "Snap points",
16
- description: "An array of numerical values (that represent distance from the top) where bottom sheet can snap to place. Accepts numbers and percentages (minimum 2 snap points)",
17
- defaultValue: ["10%", "50%", "80%"],
14
+ topSnapPosition: createStaticNumberProp({
15
+ label: "Top snap position",
16
+ description: "Top most postion where bottom sheet can snap to. A numerical value that represents distance from the top",
17
+ defaultValue: "10%",
18
+ required: false,
19
+ formType: FORM_TYPES.numeric,
18
20
  }),
19
- initialSnapIndex: createStaticNumberProp({
20
- label: "Initial snap index",
21
- description: "Index of the snap point to be used as the initial point",
22
- defaultValue: 0,
21
+ middleSnapPosition: createStaticNumberProp({
22
+ label: "Middle snap position",
23
+ description: "Middle postion where bottom sheet can snap to. A numerical value that represents distance from the top",
24
+ defaultValue: "50%",
23
25
  required: false,
26
+ formType: FORM_TYPES.numeric,
27
+ }),
28
+ bottomSnapPosition: createStaticNumberProp({
29
+ label: "Bottom snap position",
30
+ description: "Bottom most postion where bottom sheet can snap to. A numerical value that represents distance from the top",
31
+ defaultValue: "80%",
32
+ required: false,
33
+ formType: FORM_TYPES.numeric,
34
+ }),
35
+ initialSnapPosition: createTextEnumProp({
36
+ label: "Initial snap position",
37
+ description: "Initial snap position that bottom sheet will snap to",
38
+ options: ["top", "middle", "bottom"],
39
+ defaultValue: "bottom",
24
40
  }),
25
41
  showHandle: createStaticBoolProp({
26
42
  label: "Show handle",
@@ -59,5 +75,17 @@ export const SEED_DATA = {
59
75
  description: "When true, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction.",
60
76
  defaultValue: true,
61
77
  }),
78
+ snapPoints: createArrayProp({
79
+ label: "Custom Snap points",
80
+ description: "An array of numerical values (that represent distance from the top) where bottom sheet can snap to. Accepts numbers and percentages (minimum 2 snap points). Overrides snap position props",
81
+ defaultValue: null,
82
+ }),
83
+ initialSnapIndex: createStaticNumberProp({
84
+ label: "Initial snap index",
85
+ description: "Index of the snap point to be used as the initial point. Overrides initial snap position",
86
+ defaultValue: null,
87
+ required: false,
88
+ group: GROUPS.advanced,
89
+ }),
62
90
  },
63
91
  };