@draftbit/core 47.2.13 → 47.2.14-41b571.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/src/components/{SwipeableView/SwipeableView.d.ts → SwipeableItem/SwipeableItem.d.ts} +5 -3
- package/{src/components/SwipeableView/SwipeableView.js → lib/src/components/SwipeableItem/SwipeableItem.js} +36 -41
- package/lib/src/components/SwipeableItem/SwipeableItem.js.map +1 -0
- package/lib/src/components/SwipeableItem/SwipeableItemButton.d.ts +5 -0
- package/lib/src/components/SwipeableItem/SwipeableItemButton.js +6 -0
- package/lib/src/components/SwipeableItem/SwipeableItemButton.js.map +1 -0
- package/lib/src/components/SwipeableItem/SwipeableItemCommon.d.ts +30 -0
- package/lib/src/components/SwipeableItem/SwipeableItemCommon.js +44 -0
- package/lib/src/components/SwipeableItem/SwipeableItemCommon.js.map +1 -0
- package/lib/src/components/SwipeableItem/SwipeableList.d.ts +17 -0
- package/lib/src/components/SwipeableItem/SwipeableList.js +29 -0
- package/lib/src/components/SwipeableItem/SwipeableList.js.map +1 -0
- package/lib/src/components/SwipeableItem/index.d.ts +3 -0
- package/lib/src/components/SwipeableItem/index.js +4 -0
- package/lib/src/components/{SwipeableView → SwipeableItem}/index.js.map +1 -1
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/{lib/src/components/SwipeableView/SwipeableView.js → src/components/SwipeableItem/SwipeableItem.js} +36 -41
- package/src/components/SwipeableItem/SwipeableItem.js.map +1 -0
- package/src/components/{SwipeableView/SwipeableView.tsx → SwipeableItem/SwipeableItem.tsx} +75 -82
- package/src/components/SwipeableItem/SwipeableItemButton.js +6 -0
- package/src/components/SwipeableItem/SwipeableItemButton.js.map +1 -0
- package/src/components/SwipeableItem/SwipeableItemButton.tsx +11 -0
- package/src/components/SwipeableItem/SwipeableItemCommon.js +44 -0
- package/src/components/SwipeableItem/SwipeableItemCommon.js.map +1 -0
- package/src/components/SwipeableItem/SwipeableItemCommon.ts +80 -0
- package/src/components/SwipeableItem/SwipeableList.js +29 -0
- package/src/components/SwipeableItem/SwipeableList.js.map +1 -0
- package/src/components/SwipeableItem/SwipeableList.tsx +62 -0
- package/src/components/SwipeableItem/index.js +4 -0
- package/src/components/{SwipeableView → SwipeableItem}/index.js.map +1 -1
- package/src/components/SwipeableItem/index.tsx +3 -0
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/index.tsx +4 -4
- package/lib/src/components/SwipeableView/SwipeableView.js.map +0 -1
- package/lib/src/components/SwipeableView/SwipeableViewButton.d.ts +0 -12
- package/lib/src/components/SwipeableView/SwipeableViewButton.js +0 -6
- package/lib/src/components/SwipeableView/SwipeableViewButton.js.map +0 -1
- package/lib/src/components/SwipeableView/SwipeableViewSwipeHandler.d.ts +0 -12
- package/lib/src/components/SwipeableView/SwipeableViewSwipeHandler.js +0 -6
- package/lib/src/components/SwipeableView/SwipeableViewSwipeHandler.js.map +0 -1
- package/lib/src/components/SwipeableView/index.d.ts +0 -3
- package/lib/src/components/SwipeableView/index.js +0 -4
- package/src/components/SwipeableView/SwipeableView.js.map +0 -1
- package/src/components/SwipeableView/SwipeableViewButton.js +0 -6
- package/src/components/SwipeableView/SwipeableViewButton.js.map +0 -1
- package/src/components/SwipeableView/SwipeableViewButton.tsx +0 -18
- package/src/components/SwipeableView/SwipeableViewSwipeHandler.js +0 -6
- package/src/components/SwipeableView/SwipeableViewSwipeHandler.js.map +0 -1
- package/src/components/SwipeableView/SwipeableViewSwipeHandler.tsx +0 -20
- package/src/components/SwipeableView/index.js +0 -4
- package/src/components/SwipeableView/index.tsx +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "47.2.
|
|
3
|
+
"version": "47.2.14-41b571.2+41b571b",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@date-io/date-fns": "^1.3.13",
|
|
41
41
|
"@draftbit/react-theme-provider": "^2.1.1",
|
|
42
|
-
"@draftbit/types": "47.2.
|
|
42
|
+
"@draftbit/types": "^47.2.14-41b571.2+41b571b",
|
|
43
43
|
"@material-ui/core": "^4.11.0",
|
|
44
44
|
"@material-ui/pickers": "^3.2.10",
|
|
45
45
|
"@react-native-community/slider": "4.2.4",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"node_modules/",
|
|
78
78
|
"lib/"
|
|
79
79
|
],
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "41b571bd00c60e1c6ad2634cb069cdba1b3e2d5f"
|
|
81
81
|
}
|
|
@@ -4,13 +4,16 @@ import Pressable from "../Pressable";
|
|
|
4
4
|
import { extractBorderAndMarginStyles, extractEffectStyles, extractFlexItemStyles, extractPositionStyles, extractSizeStyles, extractStyles, } from "../../utilities";
|
|
5
5
|
import { SwipeRow } from "react-native-swipe-list-view";
|
|
6
6
|
import { withTheme } from "../../theming";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import { SwipeableListContext } from "./SwipeableList";
|
|
8
|
+
import { leftSwipeToSwipeableItemBehindItem, rightSwipeToSwipeableItemBehindItem, extractLeftSwipeProps, extractRightSwipeProps, } from "./SwipeableItemCommon";
|
|
9
|
+
const SwipeableItem = ({ theme, style, children, Icon, closeOnPress, leftOpenValue, rightOpenValue, leftActivationValue, rightActivationValue, swipeActivationPercentage = 80, stopLeftSwipe, stopRightSwipe, friction = 20, ...rest }) => {
|
|
10
|
+
const instanceOfSwipeableItemButtonProps = (object) => {
|
|
11
|
+
return "title" in object && "side" in object;
|
|
10
12
|
};
|
|
11
|
-
const
|
|
12
|
-
return
|
|
13
|
+
const isEmptyObject = (object) => {
|
|
14
|
+
return Object.keys(object).length === 0;
|
|
13
15
|
};
|
|
16
|
+
const { onStartSwiping, onStopSwiping } = React.useContext(SwipeableListContext);
|
|
14
17
|
const { viewStyles, textStyles } = extractStyles(style);
|
|
15
18
|
const { borderStyles, marginStyles } = extractBorderAndMarginStyles(viewStyles);
|
|
16
19
|
const sizeStyles = extractSizeStyles(viewStyles);
|
|
@@ -30,57 +33,49 @@ const SwipeableView = ({ theme, style, children, Icon, closeOnPress, leftOpenVal
|
|
|
30
33
|
]);
|
|
31
34
|
const [componentWidth, setComponentWidth] = React.useState(null);
|
|
32
35
|
const leftButtons = React.useMemo(() => React.Children.toArray(children).filter((child) => React.isValidElement(child) &&
|
|
33
|
-
|
|
36
|
+
instanceOfSwipeableItemButtonProps(child.props) &&
|
|
34
37
|
child.props.side === "left"), [children]);
|
|
35
38
|
const rightButtons = React.useMemo(() => React.Children.toArray(children).filter((child) => React.isValidElement(child) &&
|
|
36
|
-
|
|
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) &&
|
|
39
|
+
instanceOfSwipeableItemButtonProps(child.props) &&
|
|
43
40
|
child.props.side === "right"), [children]);
|
|
44
41
|
const remainingChildren = React.useMemo(() => React.Children.toArray(children).filter((child) => React.isValidElement(child) &&
|
|
45
|
-
!
|
|
46
|
-
|
|
42
|
+
!instanceOfSwipeableItemButtonProps(child.props)), [children]);
|
|
43
|
+
const leftSwipe = extractLeftSwipeProps(rest);
|
|
44
|
+
const rightSwipe = extractRightSwipeProps(rest);
|
|
45
|
+
const isLeftSwipeHandled = !isEmptyObject(leftSwipe);
|
|
46
|
+
const isRightSwipeHandled = !isEmptyObject(rightSwipe);
|
|
47
47
|
if (leftButtons.length > 2 || rightButtons.length > 2) {
|
|
48
|
-
throw Error("Cannot have more than 2
|
|
49
|
-
}
|
|
50
|
-
if (leftSwipeHandlers.length > 1 || rightSwipeHandlers.length > 1) {
|
|
51
|
-
throw Error("Cannot have more than 1 swiper handler per side");
|
|
48
|
+
throw Error("Cannot have more than 2 SwipeableItemButton(s) per side");
|
|
52
49
|
}
|
|
53
|
-
if ((leftButtons.length &&
|
|
54
|
-
(rightButtons.length &&
|
|
55
|
-
throw Error("
|
|
50
|
+
if ((leftButtons.length && isLeftSwipeHandled) ||
|
|
51
|
+
(rightButtons.length && isRightSwipeHandled)) {
|
|
52
|
+
throw Error("Colliding configuration in SwipeableItem. You cannot have SwipeableItemButton(s) on the side where swipe handling is configured. Either reset swipe configuration or remove the button(s).");
|
|
56
53
|
}
|
|
57
|
-
//Renders a single
|
|
58
|
-
const renderBehindItem = (
|
|
54
|
+
//Renders a single 'behind' item. Used for both buttons and swipe handler
|
|
55
|
+
const renderBehindItem = (item, index) => (React.createElement(Pressable, { key: index.toString(), onPress: item.onPress, style: [
|
|
59
56
|
styles.buttonContainer,
|
|
60
|
-
{ backgroundColor:
|
|
57
|
+
{ backgroundColor: item.backgroundColor || theme.colors.primary },
|
|
61
58
|
] },
|
|
62
|
-
|
|
63
|
-
React.createElement(Text, { style: [textStyles, { color:
|
|
64
|
-
const isLeftSwipeHandler = !!leftSwipeHandlers.length;
|
|
65
|
-
const isRightSwipeHandler = !!rightSwipeHandlers.length;
|
|
59
|
+
item.icon && (React.createElement(Icon, { name: item.icon, size: item.iconSize || 25, color: item.color || theme.colors.surface })),
|
|
60
|
+
React.createElement(Text, { style: [textStyles, { color: item.color || theme.colors.surface }] }, item.title)));
|
|
66
61
|
const defaultLeftOpenValue = componentWidth ? componentWidth / 2 : 0;
|
|
67
62
|
const defaultRightOpenValue = componentWidth ? -componentWidth / 2 : 0;
|
|
68
63
|
return (React.createElement(View, { onLayout: (event) => {
|
|
69
64
|
setComponentWidth(event.nativeEvent.layout.width);
|
|
70
65
|
}, style: [styles.parentContainer, parentContainerStyles] },
|
|
71
|
-
React.createElement(SwipeRow, { leftOpenValue:
|
|
72
|
-
, rightOpenValue:
|
|
66
|
+
React.createElement(SwipeRow, { leftOpenValue: isLeftSwipeHandled ? 0 : leftOpenValue || defaultLeftOpenValue //If in swiping mode, don't keep open
|
|
67
|
+
, rightOpenValue: isRightSwipeHandled ? 0 : rightOpenValue || defaultRightOpenValue, leftActivationValue: leftActivationValue || isLeftSwipeHandled
|
|
73
68
|
? defaultLeftOpenValue * (swipeActivationPercentage / 100) //When swipe passes activation percentage then it should be considered activated (call onSwipe)
|
|
74
|
-
: defaultLeftOpenValue, rightActivationValue: rightActivationValue ||
|
|
69
|
+
: defaultLeftOpenValue, rightActivationValue: rightActivationValue || isRightSwipeHandled
|
|
75
70
|
? defaultRightOpenValue * (swipeActivationPercentage / 100)
|
|
76
|
-
: defaultRightOpenValue, stopLeftSwipe: stopLeftSwipe || defaultLeftOpenValue, stopRightSwipe: stopRightSwipe || defaultRightOpenValue, onLeftAction:
|
|
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 },
|
|
71
|
+
: defaultRightOpenValue, stopLeftSwipe: stopLeftSwipe || defaultLeftOpenValue, stopRightSwipe: stopRightSwipe || defaultRightOpenValue, onLeftAction: isLeftSwipeHandled ? () => { var _a; return (_a = leftSwipe.onLeftSwipe) === null || _a === void 0 ? void 0 : _a.call(leftSwipe); } : undefined, onRightAction: isRightSwipeHandled ? () => { var _a; return (_a = rightSwipe.onRightSwipe) === null || _a === void 0 ? void 0 : _a.call(rightSwipe); } : undefined, swipeGestureBegan: onStartSwiping, swipeGestureEnded: onStopSwiping, closeOnRowPress: closeOnPress, friction: friction, ...rest },
|
|
81
72
|
React.createElement(View, { style: styles.behindContainer },
|
|
82
|
-
React.createElement(View, { style: styles.behindContainerItem },
|
|
83
|
-
|
|
73
|
+
React.createElement(View, { style: styles.behindContainerItem }, isLeftSwipeHandled
|
|
74
|
+
? renderBehindItem(leftSwipeToSwipeableItemBehindItem(leftSwipe), 0)
|
|
75
|
+
: leftButtons.map((item, index) => renderBehindItem(item.props, index))),
|
|
76
|
+
React.createElement(View, { style: styles.behindContainerItem }, isRightSwipeHandled
|
|
77
|
+
? renderBehindItem(rightSwipeToSwipeableItemBehindItem(rightSwipe), 0)
|
|
78
|
+
: rightButtons.map((item, index) => renderBehindItem(item.props, index)))),
|
|
84
79
|
React.createElement(View, { style: [
|
|
85
80
|
styles.surfaceContainer,
|
|
86
81
|
{
|
|
@@ -115,5 +110,5 @@ const styles = StyleSheet.create({
|
|
|
115
110
|
overflow: "hidden",
|
|
116
111
|
},
|
|
117
112
|
});
|
|
118
|
-
export default withTheme(
|
|
119
|
-
//# sourceMappingURL=
|
|
113
|
+
export default withTheme(SwipeableItem);
|
|
114
|
+
//# sourceMappingURL=SwipeableItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableItem.js","sourceRoot":"","sources":["SwipeableItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,IAAI,EAIJ,UAAU,EACV,IAAI,GACL,MAAM,cAAc,CAAC;AACtB,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,GACd,MAAM,iBAAiB,CA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/B,eAAe,EAAE;QACf,QAAQ,EAAE,QAAQ;QAClB,SAAS,EAAE,EAAE;KACd;IACD,eAAe,EAAE;QACf,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;QACd,aAAa,EAAE,KAAK;KACrB;IACD,mBAAmB,EAAE;QACnB,IAAI,EAAE,CAAC;QACP,aAAa,EAAE,KAAK;KACrB;IACD,eAAe,EAAE;QACf,IAAI,EAAE,CAAC;QACP,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;KACzB;IACD,gBAAgB,EAAE;QAChB,KAAK,EAAE,MAAM;QACb,SAAS,EAAE,EAAE;QACb,QAAQ,EAAE,QAAQ;KACnB;CACF,CAAC,CAAC;AAEH,eAAe,SAAS,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -20,10 +20,19 @@ import { SwipeRow } from "react-native-swipe-list-view";
|
|
|
20
20
|
import { IconSlot } from "../../interfaces/Icon";
|
|
21
21
|
import type { Theme } from "../../styles/DefaultTheme";
|
|
22
22
|
import { withTheme } from "../../theming";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
23
|
+
import { SwipeableItemButtonProps } from "./SwipeableItemButton";
|
|
24
|
+
import { SwipeableListContext } from "./SwipeableList";
|
|
25
|
+
import {
|
|
26
|
+
RightSwipeProps,
|
|
27
|
+
LeftSwipeProps,
|
|
28
|
+
SwipeableItemBehindItem,
|
|
29
|
+
leftSwipeToSwipeableItemBehindItem,
|
|
30
|
+
rightSwipeToSwipeableItemBehindItem,
|
|
31
|
+
extractLeftSwipeProps,
|
|
32
|
+
extractRightSwipeProps,
|
|
33
|
+
} from "./SwipeableItemCommon";
|
|
25
34
|
|
|
26
|
-
export interface
|
|
35
|
+
export interface SwipeableItemProps extends IconSlot {
|
|
27
36
|
closeOnPress?: boolean;
|
|
28
37
|
leftOpenValue?: number;
|
|
29
38
|
rightOpenValue?: number;
|
|
@@ -44,7 +53,9 @@ export interface SwipeableViewProps extends IconSlot {
|
|
|
44
53
|
theme: Theme;
|
|
45
54
|
}
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
type Props = SwipeableItemProps & RightSwipeProps & LeftSwipeProps;
|
|
57
|
+
|
|
58
|
+
const SwipeableItem: React.FC<React.PropsWithChildren<Props>> = ({
|
|
48
59
|
theme,
|
|
49
60
|
style,
|
|
50
61
|
children,
|
|
@@ -60,18 +71,19 @@ const SwipeableView: React.FC<React.PropsWithChildren<SwipeableViewProps>> = ({
|
|
|
60
71
|
friction = 20,
|
|
61
72
|
...rest
|
|
62
73
|
}) => {
|
|
63
|
-
const
|
|
74
|
+
const instanceOfSwipeableItemButtonProps = (
|
|
64
75
|
object: any
|
|
65
|
-
): object is
|
|
66
|
-
return "title" in object && "side" in object
|
|
76
|
+
): object is SwipeableItemButtonProps => {
|
|
77
|
+
return "title" in object && "side" in object;
|
|
67
78
|
};
|
|
68
79
|
|
|
69
|
-
const
|
|
70
|
-
object
|
|
71
|
-
): object is SwipeableViewSwipeHandlerProps => {
|
|
72
|
-
return "title" in object && "side" in object && "onSwipe" in object;
|
|
80
|
+
const isEmptyObject = (object: object) => {
|
|
81
|
+
return Object.keys(object).length === 0;
|
|
73
82
|
};
|
|
74
83
|
|
|
84
|
+
const { onStartSwiping, onStopSwiping } =
|
|
85
|
+
React.useContext(SwipeableListContext);
|
|
86
|
+
|
|
75
87
|
const { viewStyles, textStyles } = extractStyles(style);
|
|
76
88
|
|
|
77
89
|
const { borderStyles, marginStyles } =
|
|
@@ -103,9 +115,9 @@ const SwipeableView: React.FC<React.PropsWithChildren<SwipeableViewProps>> = ({
|
|
|
103
115
|
React.Children.toArray(children).filter(
|
|
104
116
|
(child) =>
|
|
105
117
|
React.isValidElement(child) &&
|
|
106
|
-
|
|
118
|
+
instanceOfSwipeableItemButtonProps(child.props) &&
|
|
107
119
|
child.props.side === "left"
|
|
108
|
-
) as React.ReactElement<
|
|
120
|
+
) as React.ReactElement<SwipeableItemButtonProps>[],
|
|
109
121
|
[children]
|
|
110
122
|
);
|
|
111
123
|
|
|
@@ -114,31 +126,9 @@ const SwipeableView: React.FC<React.PropsWithChildren<SwipeableViewProps>> = ({
|
|
|
114
126
|
React.Children.toArray(children).filter(
|
|
115
127
|
(child) =>
|
|
116
128
|
React.isValidElement(child) &&
|
|
117
|
-
|
|
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) &&
|
|
129
|
+
instanceOfSwipeableItemButtonProps(child.props) &&
|
|
140
130
|
child.props.side === "right"
|
|
141
|
-
) as React.ReactElement<
|
|
131
|
+
) as React.ReactElement<SwipeableItemButtonProps>[],
|
|
142
132
|
[children]
|
|
143
133
|
);
|
|
144
134
|
|
|
@@ -147,58 +137,53 @@ const SwipeableView: React.FC<React.PropsWithChildren<SwipeableViewProps>> = ({
|
|
|
147
137
|
React.Children.toArray(children).filter(
|
|
148
138
|
(child) =>
|
|
149
139
|
React.isValidElement(child) &&
|
|
150
|
-
!
|
|
151
|
-
!instanceOfSwipeableViewButtonProps(child.props)
|
|
140
|
+
!instanceOfSwipeableItemButtonProps(child.props)
|
|
152
141
|
),
|
|
153
142
|
[children]
|
|
154
143
|
);
|
|
155
144
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
145
|
+
const leftSwipe = extractLeftSwipeProps(rest);
|
|
146
|
+
const rightSwipe = extractRightSwipeProps(rest);
|
|
147
|
+
|
|
148
|
+
const isLeftSwipeHandled = !isEmptyObject(leftSwipe);
|
|
149
|
+
const isRightSwipeHandled = !isEmptyObject(rightSwipe);
|
|
159
150
|
|
|
160
|
-
if (
|
|
161
|
-
throw Error("Cannot have more than
|
|
151
|
+
if (leftButtons.length > 2 || rightButtons.length > 2) {
|
|
152
|
+
throw Error("Cannot have more than 2 SwipeableItemButton(s) per side");
|
|
162
153
|
}
|
|
163
154
|
|
|
164
155
|
if (
|
|
165
|
-
(leftButtons.length &&
|
|
166
|
-
(rightButtons.length &&
|
|
156
|
+
(leftButtons.length && isLeftSwipeHandled) ||
|
|
157
|
+
(rightButtons.length && isRightSwipeHandled)
|
|
167
158
|
) {
|
|
168
|
-
throw Error(
|
|
159
|
+
throw Error(
|
|
160
|
+
"Colliding configuration in SwipeableItem. You cannot have SwipeableItemButton(s) on the side where swipe handling is configured. Either reset swipe configuration or remove the button(s)."
|
|
161
|
+
);
|
|
169
162
|
}
|
|
170
163
|
|
|
171
|
-
//Renders a single
|
|
172
|
-
const renderBehindItem = (
|
|
173
|
-
props: SwipeableViewSwipeHandlerProps | SwipeableViewButtonProps,
|
|
174
|
-
index: number
|
|
175
|
-
) => (
|
|
164
|
+
//Renders a single 'behind' item. Used for both buttons and swipe handler
|
|
165
|
+
const renderBehindItem = (item: SwipeableItemBehindItem, index: number) => (
|
|
176
166
|
<Pressable
|
|
177
167
|
key={index.toString()}
|
|
178
|
-
onPress={(
|
|
168
|
+
onPress={(item as any).onPress}
|
|
179
169
|
style={[
|
|
180
170
|
styles.buttonContainer,
|
|
181
|
-
{ backgroundColor:
|
|
171
|
+
{ backgroundColor: item.backgroundColor || theme.colors.primary },
|
|
182
172
|
]}
|
|
183
173
|
>
|
|
184
|
-
{
|
|
174
|
+
{item.icon && (
|
|
185
175
|
<Icon
|
|
186
|
-
name={
|
|
187
|
-
size={
|
|
188
|
-
color={
|
|
176
|
+
name={item.icon}
|
|
177
|
+
size={item.iconSize || 25}
|
|
178
|
+
color={item.color || theme.colors.surface}
|
|
189
179
|
/>
|
|
190
180
|
)}
|
|
191
|
-
<Text
|
|
192
|
-
|
|
193
|
-
>
|
|
194
|
-
{props.title}
|
|
181
|
+
<Text style={[textStyles, { color: item.color || theme.colors.surface }]}>
|
|
182
|
+
{item.title}
|
|
195
183
|
</Text>
|
|
196
184
|
</Pressable>
|
|
197
185
|
);
|
|
198
186
|
|
|
199
|
-
const isLeftSwipeHandler = !!leftSwipeHandlers.length;
|
|
200
|
-
const isRightSwipeHandler = !!rightSwipeHandlers.length;
|
|
201
|
-
|
|
202
187
|
const defaultLeftOpenValue = componentWidth ? componentWidth / 2 : 0;
|
|
203
188
|
const defaultRightOpenValue = componentWidth ? -componentWidth / 2 : 0;
|
|
204
189
|
|
|
@@ -212,47 +197,55 @@ const SwipeableView: React.FC<React.PropsWithChildren<SwipeableViewProps>> = ({
|
|
|
212
197
|
{/*@ts-ignore*/}
|
|
213
198
|
<SwipeRow
|
|
214
199
|
leftOpenValue={
|
|
215
|
-
|
|
200
|
+
isLeftSwipeHandled ? 0 : leftOpenValue || defaultLeftOpenValue //If in swiping mode, don't keep open
|
|
216
201
|
}
|
|
217
202
|
rightOpenValue={
|
|
218
|
-
|
|
203
|
+
isRightSwipeHandled ? 0 : rightOpenValue || defaultRightOpenValue
|
|
219
204
|
}
|
|
220
205
|
leftActivationValue={
|
|
221
|
-
leftActivationValue ||
|
|
206
|
+
leftActivationValue || isLeftSwipeHandled
|
|
222
207
|
? defaultLeftOpenValue * (swipeActivationPercentage / 100) //When swipe passes activation percentage then it should be considered activated (call onSwipe)
|
|
223
208
|
: defaultLeftOpenValue
|
|
224
209
|
}
|
|
225
210
|
rightActivationValue={
|
|
226
|
-
rightActivationValue ||
|
|
211
|
+
rightActivationValue || isRightSwipeHandled
|
|
227
212
|
? defaultRightOpenValue * (swipeActivationPercentage / 100)
|
|
228
213
|
: defaultRightOpenValue
|
|
229
214
|
}
|
|
230
215
|
stopLeftSwipe={stopLeftSwipe || defaultLeftOpenValue}
|
|
231
216
|
stopRightSwipe={stopRightSwipe || defaultRightOpenValue}
|
|
232
217
|
onLeftAction={
|
|
233
|
-
|
|
234
|
-
? () => leftSwipeHandlers[0].props.onSwipe?.()
|
|
235
|
-
: undefined
|
|
218
|
+
isLeftSwipeHandled ? () => leftSwipe.onLeftSwipe?.() : undefined
|
|
236
219
|
}
|
|
237
220
|
onRightAction={
|
|
238
|
-
|
|
239
|
-
? () => rightSwipeHandlers[0].props.onSwipe?.()
|
|
240
|
-
: undefined
|
|
221
|
+
isRightSwipeHandled ? () => rightSwipe.onRightSwipe?.() : undefined
|
|
241
222
|
}
|
|
223
|
+
swipeGestureBegan={onStartSwiping}
|
|
224
|
+
swipeGestureEnded={onStopSwiping}
|
|
242
225
|
closeOnRowPress={closeOnPress}
|
|
243
226
|
friction={friction}
|
|
244
227
|
{...rest}
|
|
245
228
|
>
|
|
246
229
|
<View style={styles.behindContainer}>
|
|
247
230
|
<View style={styles.behindContainerItem}>
|
|
248
|
-
{
|
|
249
|
-
|
|
250
|
-
|
|
231
|
+
{isLeftSwipeHandled
|
|
232
|
+
? renderBehindItem(
|
|
233
|
+
leftSwipeToSwipeableItemBehindItem(leftSwipe),
|
|
234
|
+
0
|
|
235
|
+
)
|
|
236
|
+
: leftButtons.map((item, index) =>
|
|
237
|
+
renderBehindItem(item.props, index)
|
|
238
|
+
)}
|
|
251
239
|
</View>
|
|
252
240
|
<View style={styles.behindContainerItem}>
|
|
253
|
-
{
|
|
254
|
-
|
|
255
|
-
|
|
241
|
+
{isRightSwipeHandled
|
|
242
|
+
? renderBehindItem(
|
|
243
|
+
rightSwipeToSwipeableItemBehindItem(rightSwipe),
|
|
244
|
+
0
|
|
245
|
+
)
|
|
246
|
+
: rightButtons.map((item, index) =>
|
|
247
|
+
renderBehindItem(item.props, index)
|
|
248
|
+
)}
|
|
256
249
|
</View>
|
|
257
250
|
</View>
|
|
258
251
|
<View
|
|
@@ -298,4 +291,4 @@ const styles = StyleSheet.create({
|
|
|
298
291
|
},
|
|
299
292
|
});
|
|
300
293
|
|
|
301
|
-
export default withTheme(
|
|
294
|
+
export default withTheme(SwipeableItem);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableItemButton.js","sourceRoot":"","sources":["SwipeableItemButton.tsx"],"names":[],"mappings":"AAKA,6DAA6D;AAC7D,MAAM,mBAAmB,GAAuC,GAAG,EAAE;IACnE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SwipeableItemBehindItem } from "./SwipeableItemCommon";
|
|
3
|
+
|
|
4
|
+
export type SwipeableItemButtonProps = Omit<SwipeableItemBehindItem, "onSwipe">;
|
|
5
|
+
|
|
6
|
+
//Renders nothing, acts as a wrapper be used by SwipeableView
|
|
7
|
+
const SwipeableItemButton: React.FC<SwipeableItemButtonProps> = () => {
|
|
8
|
+
return null;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default SwipeableItemButton;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { pick } from "lodash";
|
|
2
|
+
export function extractRightSwipeProps(object) {
|
|
3
|
+
return pick(object, [
|
|
4
|
+
"onRightSwipe",
|
|
5
|
+
"rightSwipeTitle",
|
|
6
|
+
"rightSwipeIcon",
|
|
7
|
+
"rightSwipeIconSize",
|
|
8
|
+
"rightSwipeBackgroundColor",
|
|
9
|
+
"rightSwipeColor",
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
export function extractLeftSwipeProps(object) {
|
|
13
|
+
return pick(object, [
|
|
14
|
+
"onLeftSwipe",
|
|
15
|
+
"leftSwipeTitle",
|
|
16
|
+
"leftSwipeIcon",
|
|
17
|
+
"leftSwipeIconSize",
|
|
18
|
+
"leftSwipeBackgroundColor",
|
|
19
|
+
"leftSwipeColor",
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
export function rightSwipeToSwipeableItemBehindItem(swipe) {
|
|
23
|
+
return {
|
|
24
|
+
title: swipe.rightSwipeTitle || "",
|
|
25
|
+
side: "right",
|
|
26
|
+
onSwipe: swipe.onRightSwipe,
|
|
27
|
+
icon: swipe.rightSwipeIcon,
|
|
28
|
+
iconSize: swipe.rightSwipeIconSize,
|
|
29
|
+
backgroundColor: swipe.rightSwipeBackgroundColor,
|
|
30
|
+
color: swipe.rightSwipeColor,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function leftSwipeToSwipeableItemBehindItem(swipe) {
|
|
34
|
+
return {
|
|
35
|
+
title: swipe.leftSwipeTitle || "",
|
|
36
|
+
side: "left",
|
|
37
|
+
onSwipe: swipe.onLeftSwipe,
|
|
38
|
+
icon: swipe.leftSwipeIcon,
|
|
39
|
+
iconSize: swipe.leftSwipeIconSize,
|
|
40
|
+
backgroundColor: swipe.leftSwipeBackgroundColor,
|
|
41
|
+
color: swipe.leftSwipeColor,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=SwipeableItemCommon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableItemCommon.js","sourceRoot":"","sources":["SwipeableItemCommon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AA+B9B,MAAM,UAAU,sBAAsB,CAAC,MAAc;IACnD,OAAO,IAAI,CAAC,MAAM,EAAE;QAClB,cAAc;QACd,iBAAiB;QACjB,gBAAgB;QAChB,oBAAoB;QACpB,2BAA2B;QAC3B,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,OAAO,IAAI,CAAC,MAAM,EAAE;QAClB,aAAa;QACb,gBAAgB;QAChB,eAAe;QACf,mBAAmB;QACnB,0BAA0B;QAC1B,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,KAAsB;IAEtB,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,eAAe,IAAI,EAAE;QAClC,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,KAAK,CAAC,YAAY;QAC3B,IAAI,EAAE,KAAK,CAAC,cAAc;QAC1B,QAAQ,EAAE,KAAK,CAAC,kBAAkB;QAClC,eAAe,EAAE,KAAK,CAAC,yBAAyB;QAChD,KAAK,EAAE,KAAK,CAAC,eAAe;KAC7B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kCAAkC,CAChD,KAAqB;IAErB,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,cAAc,IAAI,EAAE;QACjC,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,KAAK,CAAC,WAAW;QAC1B,IAAI,EAAE,KAAK,CAAC,aAAa;QACzB,QAAQ,EAAE,KAAK,CAAC,iBAAiB;QACjC,eAAe,EAAE,KAAK,CAAC,wBAAwB;QAC/C,KAAK,EAAE,KAAK,CAAC,cAAc;KAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { pick } from "lodash";
|
|
2
|
+
|
|
3
|
+
export interface SwipeableItemBehindItem {
|
|
4
|
+
title: string;
|
|
5
|
+
side: "left" | "right";
|
|
6
|
+
onPress?: () => void;
|
|
7
|
+
onSwipe?: () => void;
|
|
8
|
+
icon?: string;
|
|
9
|
+
iconSize?: number;
|
|
10
|
+
backgroundColor?: string;
|
|
11
|
+
color?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface RightSwipeProps {
|
|
15
|
+
onRightSwipe?: () => void;
|
|
16
|
+
rightSwipeTitle?: string;
|
|
17
|
+
rightSwipeIcon?: string;
|
|
18
|
+
rightSwipeIconSize?: number;
|
|
19
|
+
rightSwipeBackgroundColor?: string;
|
|
20
|
+
rightSwipeColor?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface LeftSwipeProps {
|
|
24
|
+
onLeftSwipe?: () => void;
|
|
25
|
+
leftSwipeTitle?: string;
|
|
26
|
+
leftSwipeIcon?: string;
|
|
27
|
+
leftSwipeIconSize?: number;
|
|
28
|
+
leftSwipeBackgroundColor?: string;
|
|
29
|
+
leftSwipeColor?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function extractRightSwipeProps(object: object): RightSwipeProps {
|
|
33
|
+
return pick(object, [
|
|
34
|
+
"onRightSwipe",
|
|
35
|
+
"rightSwipeTitle",
|
|
36
|
+
"rightSwipeIcon",
|
|
37
|
+
"rightSwipeIconSize",
|
|
38
|
+
"rightSwipeBackgroundColor",
|
|
39
|
+
"rightSwipeColor",
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function extractLeftSwipeProps(object: object): LeftSwipeProps {
|
|
44
|
+
return pick(object, [
|
|
45
|
+
"onLeftSwipe",
|
|
46
|
+
"leftSwipeTitle",
|
|
47
|
+
"leftSwipeIcon",
|
|
48
|
+
"leftSwipeIconSize",
|
|
49
|
+
"leftSwipeBackgroundColor",
|
|
50
|
+
"leftSwipeColor",
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function rightSwipeToSwipeableItemBehindItem(
|
|
55
|
+
swipe: RightSwipeProps
|
|
56
|
+
): Omit<SwipeableItemBehindItem, "onPress"> {
|
|
57
|
+
return {
|
|
58
|
+
title: swipe.rightSwipeTitle || "",
|
|
59
|
+
side: "right",
|
|
60
|
+
onSwipe: swipe.onRightSwipe,
|
|
61
|
+
icon: swipe.rightSwipeIcon,
|
|
62
|
+
iconSize: swipe.rightSwipeIconSize,
|
|
63
|
+
backgroundColor: swipe.rightSwipeBackgroundColor,
|
|
64
|
+
color: swipe.rightSwipeColor,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function leftSwipeToSwipeableItemBehindItem(
|
|
69
|
+
swipe: LeftSwipeProps
|
|
70
|
+
): Omit<SwipeableItemBehindItem, "onPress"> {
|
|
71
|
+
return {
|
|
72
|
+
title: swipe.leftSwipeTitle || "",
|
|
73
|
+
side: "left",
|
|
74
|
+
onSwipe: swipe.onLeftSwipe,
|
|
75
|
+
icon: swipe.leftSwipeIcon,
|
|
76
|
+
iconSize: swipe.leftSwipeIconSize,
|
|
77
|
+
backgroundColor: swipe.leftSwipeBackgroundColor,
|
|
78
|
+
color: swipe.leftSwipeColor,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FlashList } from "@shopify/flash-list";
|
|
3
|
+
import { FlatList } from "react-native";
|
|
4
|
+
export const SwipeableListContext = React.createContext({
|
|
5
|
+
onStartSwiping: () => { },
|
|
6
|
+
onStopSwiping: () => { },
|
|
7
|
+
});
|
|
8
|
+
const SwipeableList = ({ disableScrollWhenSwiping = true, listComponent = "FlatList", ...rest }) => {
|
|
9
|
+
const [isSwiping, setIsSwiping] = React.useState(false);
|
|
10
|
+
const onStartSwiping = () => {
|
|
11
|
+
setIsSwiping(true);
|
|
12
|
+
};
|
|
13
|
+
const onStopSwiping = () => {
|
|
14
|
+
setIsSwiping(false);
|
|
15
|
+
};
|
|
16
|
+
rest.scrollEnabled = disableScrollWhenSwiping ? !isSwiping : true;
|
|
17
|
+
const renderListComponent = () => {
|
|
18
|
+
switch (listComponent) {
|
|
19
|
+
case "FlatList":
|
|
20
|
+
return React.createElement(FlatList, { ...rest });
|
|
21
|
+
case "FlashList":
|
|
22
|
+
return React.createElement(FlashList, { ...rest });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return (React.createElement(SwipeableListContext.Provider, { value: { onStartSwiping, onStopSwiping } },
|
|
26
|
+
React.createElement(React.Fragment, null, renderListComponent())));
|
|
27
|
+
};
|
|
28
|
+
export default SwipeableList;
|
|
29
|
+
//# sourceMappingURL=SwipeableList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableList.js","sourceRoot":"","sources":["SwipeableList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAkB,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAiB,QAAQ,EAAE,MAAM,cAAc,CAAC;AAoBvD,MAAM,CAAC,MAAM,oBAAoB,GAC/B,KAAK,CAAC,aAAa,CAA2B;IAC5C,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;CACxB,CAAC,CAAC;AAEL,MAAM,aAAa,GAAG,CAAmB,EACvC,wBAAwB,GAAG,IAAI,EAC/B,aAAa,GAAG,UAAU,EAC1B,GAAG,IAAI,EACwD,EAAE,EAAE;IACnE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,MAAM,cAAc,GAAG,GAAG,EAAE;QAC1B,YAAY,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,GAAG,EAAE;QACzB,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC,CAAC;IAEF,IAAI,CAAC,aAAa,GAAG,wBAAwB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAElE,MAAM,mBAAmB,GAAG,GAAG,EAAE;QAC/B,QAAQ,aAAa,EAAE;YACrB,KAAK,UAAU;gBACb,OAAO,oBAAC,QAAQ,OAAM,IAAyB,GAAI,CAAC;YACtD,KAAK,WAAW;gBACd,OAAO,oBAAC,SAAS,OAAM,IAA0B,GAAI,CAAC;SACzD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