@hero-design/rn 8.8.1 → 8.9.1
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/.turbo/turbo-build.log +9 -9
- package/assets/fonts/hero-icons-mobile.ttf +0 -0
- package/es/index.js +400 -618
- package/lib/assets/fonts/hero-icons-mobile.ttf +0 -0
- package/lib/index.js +399 -618
- package/package.json +9 -9
- package/src/components/Carousel/CarouselItem.tsx +4 -2
- package/src/components/Carousel/__tests__/__snapshots__/index.spec.tsx.snap +288 -22
- package/src/components/Carousel/__tests__/index.spec.tsx +17 -8
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerAndroid.spec.tsx.snap +2 -1
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +2 -1
- package/src/components/Icon/HeroIcon/glyphMap.json +1 -1
- package/src/components/Icon/IconList.ts +2 -0
- package/src/components/Progress/__tests__/__snapshots__/index.spec.js.snap +9 -9
- package/src/components/RichTextEditor/RichTextEditor.tsx +3 -2
- package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +4 -2
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +10 -5
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/index.spec.tsx.snap +10 -5
- package/src/components/TextInput/StyledTextInput.tsx +2 -1
- package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +126 -110
- package/src/components/TextInput/index.tsx +3 -2
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerAndroid.spec.tsx.snap +28 -25
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +28 -25
- package/src/index.ts +0 -2
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +8 -5
- package/src/theme/components/progress.ts +4 -4
- package/src/theme/components/textInput.ts +6 -2
- package/types/components/Accordion/StyledAccordion.d.ts +1 -0
- package/types/components/Alert/StyledAlert.d.ts +1 -0
- package/types/components/Attachment/StyledAttachment.d.ts +1 -0
- package/types/components/Avatar/AvatarStack/StyledAvatarStack.d.ts +1 -0
- package/types/components/Avatar/StyledAvatar.d.ts +1 -0
- package/types/components/Badge/StyledBadge.d.ts +1 -0
- package/types/components/BottomNavigation/StyledBottomNavigation.d.ts +1 -0
- package/types/components/BottomSheet/BottomSheetContext.d.ts +1 -0
- package/types/components/BottomSheet/StyledBottomSheet.d.ts +1 -0
- package/types/components/Box/StyledBox.d.ts +1 -0
- package/types/components/Box/types.d.ts +1 -0
- package/types/components/Button/LoadingIndicator/StyledLoadingIndicator.d.ts +1 -0
- package/types/components/Button/StyledButton.d.ts +1 -0
- package/types/components/Button/UtilityButton/StyledUtilityButton.d.ts +1 -0
- package/types/components/Calendar/StyledCalendar.d.ts +1 -0
- package/types/components/Card/DataCard/StyledDataCard.d.ts +1 -0
- package/types/components/Card/StyledCard.d.ts +1 -0
- package/types/components/Carousel/StyledCarousel.d.ts +1 -0
- package/types/components/Checkbox/StyledCheckbox.d.ts +1 -0
- package/types/components/Collapse/StyledCollapse.d.ts +1 -0
- package/types/components/ContentNavigator/StyledContentNavigator.d.ts +1 -0
- package/types/components/DatePicker/StyledDatePicker.d.ts +1 -0
- package/types/components/Divider/StyledDivider.d.ts +1 -0
- package/types/components/Drawer/StyledDrawer.d.ts +1 -0
- package/types/components/Empty/StyledEmpty.d.ts +1 -0
- package/types/components/FAB/ActionGroup/StyledActionGroup.d.ts +1 -0
- package/types/components/FAB/ActionGroup/StyledActionItem.d.ts +1 -0
- package/types/components/FAB/StyledFAB.d.ts +1 -0
- package/types/components/Icon/HeroIcon/index.d.ts +1 -0
- package/types/components/Icon/IconList.d.ts +1 -1
- package/types/components/Icon/index.d.ts +1 -1
- package/types/components/Icon/utils.d.ts +1 -1
- package/types/components/List/StyledBasicListItem.d.ts +1 -0
- package/types/components/List/StyledListItem.d.ts +1 -0
- package/types/components/PageControl/StyledPageControl.d.ts +1 -0
- package/types/components/PinInput/StyledPinInput.d.ts +1 -0
- package/types/components/Progress/StyledProgressBar.d.ts +1 -0
- package/types/components/Progress/StyledProgressCircle.d.ts +1 -0
- package/types/components/Radio/StyledRadio.d.ts +1 -0
- package/types/components/Radio/index.d.ts +1 -0
- package/types/components/RichTextEditor/StyledRichTextEditor.d.ts +1 -0
- package/types/components/RichTextEditor/StyledToolbar.d.ts +1 -0
- package/types/components/RichTextEditor/index.d.ts +1 -0
- package/types/components/SectionHeading/StyledHeading.d.ts +1 -0
- package/types/components/Select/StyledSelect.d.ts +1 -0
- package/types/components/Select/helpers.d.ts +1 -0
- package/types/components/Spinner/StyledSpinner.d.ts +1 -0
- package/types/components/Swipeable/StyledSwipeable.d.ts +1 -0
- package/types/components/Switch/SelectorSwitch/StyledSelectorSwitch.d.ts +1 -0
- package/types/components/Switch/StyledSwitch.d.ts +1 -0
- package/types/components/Tabs/StyledScrollableTabs.d.ts +1 -0
- package/types/components/Tabs/StyledTabs.d.ts +1 -0
- package/types/components/Tag/StyledTag.d.ts +1 -0
- package/types/components/TextInput/StyledTextInput.d.ts +1 -0
- package/types/components/TextInput/index.d.ts +1 -1
- package/types/components/TimePicker/StyledTimePicker.d.ts +1 -0
- package/types/components/Toast/StyledToast.d.ts +1 -0
- package/types/components/Toast/ToastContext.d.ts +1 -0
- package/types/components/Toast/index.d.ts +1 -0
- package/types/components/Toolbar/StyledToolbar.d.ts +1 -0
- package/types/components/Typography/Text/StyledText.d.ts +1 -0
- package/types/index.d.ts +1 -2
- package/types/theme/ThemeProvider.d.ts +1 -0
- package/types/theme/components/textInput.d.ts +4 -1
- package/src/components/SwipeableV2/StyledSwipeable.tsx +0 -14
- package/src/components/SwipeableV2/__tests__/__snapshots__/index.spec.tsx.snap +0 -161
- package/src/components/SwipeableV2/__tests__/index.spec.tsx +0 -48
- package/src/components/SwipeableV2/index.tsx +0 -364
- package/types/components/SwipeableV2/StyledSwipeable.d.ts +0 -15
- package/types/components/SwipeableV2/index.d.ts +0 -46
package/types/index.d.ts
CHANGED
|
@@ -28,7 +28,6 @@ import Progress from './components/Progress';
|
|
|
28
28
|
import Slider from './components/Slider';
|
|
29
29
|
import Spinner from './components/Spinner';
|
|
30
30
|
import Swipeable from './components/Swipeable';
|
|
31
|
-
import SwipeableV2 from './components/SwipeableV2';
|
|
32
31
|
import Radio from './components/Radio';
|
|
33
32
|
import SectionHeading from './components/SectionHeading';
|
|
34
33
|
import Select from './components/Select';
|
|
@@ -43,5 +42,5 @@ import Typography from './components/Typography';
|
|
|
43
42
|
import RefreshControl from './components/RefreshControl';
|
|
44
43
|
import RichTextEditor from './components/RichTextEditor';
|
|
45
44
|
import PageControl from './components/PageControl';
|
|
46
|
-
export { theme, getTheme, useTheme, scale, ThemeProvider, ThemeSwitcher, swagSystemPalette, workSystemPalette, jobsSystemPalette, walletSystemPalette, eBensSystemPalette, Accordion, Alert, Attachment, Avatar, useAvatarColors, Badge, BottomNavigation, BottomSheet, Box, Button, Calendar, Card, Carousel, Collapse, Checkbox, ContentNavigator, DatePicker, Divider, Drawer, Empty, FAB, Icon, Image, List, PinInput, Progress, PageControl, Slider, Spinner, Swipeable,
|
|
45
|
+
export { theme, getTheme, useTheme, scale, ThemeProvider, ThemeSwitcher, swagSystemPalette, workSystemPalette, jobsSystemPalette, walletSystemPalette, eBensSystemPalette, Accordion, Alert, Attachment, Avatar, useAvatarColors, Badge, BottomNavigation, BottomSheet, Box, Button, Calendar, Card, Carousel, Collapse, Checkbox, ContentNavigator, DatePicker, Divider, Drawer, Empty, FAB, Icon, Image, List, PinInput, Progress, PageControl, Slider, Spinner, Swipeable, Radio, SectionHeading, Select, Switch, Tabs, Tag, TextInput, TimePicker, Toast, Toolbar, Typography, RefreshControl, RichTextEditor, };
|
|
47
46
|
export * from './types';
|
|
@@ -47,11 +47,11 @@ declare const getTextInputTheme: (theme: GlobalTheme) => {
|
|
|
47
47
|
labelPaddingBottom: number;
|
|
48
48
|
labelHorizontalPadding: number;
|
|
49
49
|
inputHorizontalMargin: number;
|
|
50
|
-
containerMarginVertical: number;
|
|
51
50
|
errorContainerMarginRight: number;
|
|
52
51
|
errorMarginLeft: number;
|
|
53
52
|
maxLengthLabelMarginLeft: number;
|
|
54
53
|
errorAndHelpTextContainerPaddingLeft: number;
|
|
54
|
+
containerMarginTop: number;
|
|
55
55
|
};
|
|
56
56
|
fontSizes: {
|
|
57
57
|
text: number;
|
|
@@ -73,5 +73,8 @@ declare const getTextInputTheme: (theme: GlobalTheme) => {
|
|
|
73
73
|
text: number;
|
|
74
74
|
labelInsideTextInput: number;
|
|
75
75
|
};
|
|
76
|
+
sizes: {
|
|
77
|
+
errorAndHelpTextContainerHeight: number;
|
|
78
|
+
};
|
|
76
79
|
};
|
|
77
80
|
export default getTextInputTheme;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import styled from '@emotion/native';
|
|
2
|
-
import { Animated, View } from 'react-native';
|
|
3
|
-
|
|
4
|
-
export type ActionIntent = 'primary' | 'success' | 'danger';
|
|
5
|
-
|
|
6
|
-
const StyledWrapper = styled(View)(() => ({
|
|
7
|
-
flexDirection: 'row',
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
const StyledContent = styled(Animated.View)(() => ({
|
|
11
|
-
flex: 1,
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
export { StyledWrapper, StyledContent };
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Swipeable renders correctly 1`] = `
|
|
4
|
-
<View
|
|
5
|
-
onLayout={[Function]}
|
|
6
|
-
onMoveShouldSetResponder={[Function]}
|
|
7
|
-
onMoveShouldSetResponderCapture={[Function]}
|
|
8
|
-
onResponderEnd={[Function]}
|
|
9
|
-
onResponderGrant={[Function]}
|
|
10
|
-
onResponderMove={[Function]}
|
|
11
|
-
onResponderReject={[Function]}
|
|
12
|
-
onResponderRelease={[Function]}
|
|
13
|
-
onResponderStart={[Function]}
|
|
14
|
-
onResponderTerminate={[Function]}
|
|
15
|
-
onResponderTerminationRequest={[Function]}
|
|
16
|
-
onStartShouldSetResponder={[Function]}
|
|
17
|
-
onStartShouldSetResponderCapture={[Function]}
|
|
18
|
-
style={
|
|
19
|
-
Array [
|
|
20
|
-
Object {
|
|
21
|
-
"flexDirection": "row",
|
|
22
|
-
},
|
|
23
|
-
Array [
|
|
24
|
-
Object {
|
|
25
|
-
"flexDirection": "row",
|
|
26
|
-
},
|
|
27
|
-
undefined,
|
|
28
|
-
],
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
>
|
|
32
|
-
<View
|
|
33
|
-
collapsable={false}
|
|
34
|
-
style={
|
|
35
|
-
Object {
|
|
36
|
-
"marginLeft": -0,
|
|
37
|
-
"transform": Array [
|
|
38
|
-
Object {
|
|
39
|
-
"translateX": 0.5,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
"width": 0,
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
>
|
|
46
|
-
<View
|
|
47
|
-
style={
|
|
48
|
-
Array [
|
|
49
|
-
Object {
|
|
50
|
-
"alignItems": "flex-end",
|
|
51
|
-
"flex": 1,
|
|
52
|
-
"justifyContent": "center",
|
|
53
|
-
},
|
|
54
|
-
]
|
|
55
|
-
}
|
|
56
|
-
>
|
|
57
|
-
<Text
|
|
58
|
-
style={
|
|
59
|
-
Array [
|
|
60
|
-
Object {
|
|
61
|
-
"color": "#001f23",
|
|
62
|
-
"fontFamily": "BeVietnamPro-Regular",
|
|
63
|
-
"fontSize": 14,
|
|
64
|
-
"letterSpacing": 0.42,
|
|
65
|
-
"lineHeight": 22,
|
|
66
|
-
},
|
|
67
|
-
undefined,
|
|
68
|
-
]
|
|
69
|
-
}
|
|
70
|
-
themeFontSize="medium"
|
|
71
|
-
themeFontWeight="regular"
|
|
72
|
-
themeIntent="body"
|
|
73
|
-
themeTypeface="neutral"
|
|
74
|
-
>
|
|
75
|
-
Archive
|
|
76
|
-
</Text>
|
|
77
|
-
</View>
|
|
78
|
-
</View>
|
|
79
|
-
<View
|
|
80
|
-
collapsable={false}
|
|
81
|
-
style={
|
|
82
|
-
Object {
|
|
83
|
-
"flex": 1,
|
|
84
|
-
"transform": Array [
|
|
85
|
-
Object {
|
|
86
|
-
"translateX": 0.5,
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
>
|
|
92
|
-
<Text
|
|
93
|
-
style={
|
|
94
|
-
Array [
|
|
95
|
-
Object {
|
|
96
|
-
"color": "#001f23",
|
|
97
|
-
"fontFamily": "BeVietnamPro-Regular",
|
|
98
|
-
"fontSize": 14,
|
|
99
|
-
"letterSpacing": 0.42,
|
|
100
|
-
"lineHeight": 22,
|
|
101
|
-
},
|
|
102
|
-
undefined,
|
|
103
|
-
]
|
|
104
|
-
}
|
|
105
|
-
themeFontSize="medium"
|
|
106
|
-
themeFontWeight="regular"
|
|
107
|
-
themeIntent="body"
|
|
108
|
-
themeTypeface="neutral"
|
|
109
|
-
>
|
|
110
|
-
Swipeable Item
|
|
111
|
-
</Text>
|
|
112
|
-
</View>
|
|
113
|
-
<View
|
|
114
|
-
collapsable={false}
|
|
115
|
-
style={
|
|
116
|
-
Object {
|
|
117
|
-
"marginRight": -0,
|
|
118
|
-
"transform": Array [
|
|
119
|
-
Object {
|
|
120
|
-
"translateX": 0.5,
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
"width": 0,
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
>
|
|
127
|
-
<View
|
|
128
|
-
style={
|
|
129
|
-
Array [
|
|
130
|
-
Object {
|
|
131
|
-
"alignItems": "flex-start",
|
|
132
|
-
"flex": 1,
|
|
133
|
-
"justifyContent": "center",
|
|
134
|
-
},
|
|
135
|
-
]
|
|
136
|
-
}
|
|
137
|
-
>
|
|
138
|
-
<Text
|
|
139
|
-
style={
|
|
140
|
-
Array [
|
|
141
|
-
Object {
|
|
142
|
-
"color": "#001f23",
|
|
143
|
-
"fontFamily": "BeVietnamPro-Regular",
|
|
144
|
-
"fontSize": 14,
|
|
145
|
-
"letterSpacing": 0.42,
|
|
146
|
-
"lineHeight": 22,
|
|
147
|
-
},
|
|
148
|
-
undefined,
|
|
149
|
-
]
|
|
150
|
-
}
|
|
151
|
-
themeFontSize="medium"
|
|
152
|
-
themeFontWeight="regular"
|
|
153
|
-
themeIntent="body"
|
|
154
|
-
themeTypeface="neutral"
|
|
155
|
-
>
|
|
156
|
-
Approve
|
|
157
|
-
</Text>
|
|
158
|
-
</View>
|
|
159
|
-
</View>
|
|
160
|
-
</View>
|
|
161
|
-
`;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View } from 'react-native';
|
|
3
|
-
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
4
|
-
import Typography from '../../Typography';
|
|
5
|
-
import SwipeableV2 from '..';
|
|
6
|
-
|
|
7
|
-
describe('Swipeable', () => {
|
|
8
|
-
it('renders correctly', () => {
|
|
9
|
-
const { toJSON, getByText } = renderWithTheme(
|
|
10
|
-
<SwipeableV2
|
|
11
|
-
leftContent={
|
|
12
|
-
<View
|
|
13
|
-
style={[
|
|
14
|
-
{
|
|
15
|
-
flex: 1,
|
|
16
|
-
alignItems: 'flex-end',
|
|
17
|
-
justifyContent: 'center',
|
|
18
|
-
},
|
|
19
|
-
]}
|
|
20
|
-
>
|
|
21
|
-
<Typography.Text>Archive</Typography.Text>
|
|
22
|
-
</View>
|
|
23
|
-
}
|
|
24
|
-
rightContent={
|
|
25
|
-
<View
|
|
26
|
-
style={[
|
|
27
|
-
{
|
|
28
|
-
flex: 1,
|
|
29
|
-
alignItems: 'flex-start',
|
|
30
|
-
justifyContent: 'center',
|
|
31
|
-
},
|
|
32
|
-
]}
|
|
33
|
-
>
|
|
34
|
-
<Typography.Text>Approve</Typography.Text>
|
|
35
|
-
</View>
|
|
36
|
-
}
|
|
37
|
-
rightActionsWidth={168}
|
|
38
|
-
>
|
|
39
|
-
<Typography.Text>Swipeable Item</Typography.Text>
|
|
40
|
-
</SwipeableV2>
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
expect(getByText('Swipeable Item')).toBeDefined();
|
|
44
|
-
expect(getByText('Archive')).toBeDefined();
|
|
45
|
-
expect(getByText('Approve')).toBeDefined();
|
|
46
|
-
expect(toJSON()).toMatchSnapshot();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Animated,
|
|
4
|
-
Easing,
|
|
5
|
-
GestureResponderEvent,
|
|
6
|
-
PanResponder,
|
|
7
|
-
PanResponderGestureState,
|
|
8
|
-
StyleProp,
|
|
9
|
-
StyleSheet,
|
|
10
|
-
ViewStyle,
|
|
11
|
-
} from 'react-native';
|
|
12
|
-
import { noop } from '../../utils/functions';
|
|
13
|
-
import { scale } from '../../utils/scale';
|
|
14
|
-
import { StyledContent, StyledWrapper } from './StyledSwipeable';
|
|
15
|
-
|
|
16
|
-
const swipeStartMinDistance = 15;
|
|
17
|
-
|
|
18
|
-
export type SwipeableV2Props = {
|
|
19
|
-
/**
|
|
20
|
-
* Content panel that is going to be revealed from the left side when user swipes right.
|
|
21
|
-
*/
|
|
22
|
-
leftContent?: React.ReactNode;
|
|
23
|
-
/**
|
|
24
|
-
* Content panel that is going to be revealed from the right side when user swipes left.
|
|
25
|
-
*/
|
|
26
|
-
rightContent?: React.ReactNode;
|
|
27
|
-
/**
|
|
28
|
-
* If the user swipe a distance greater than this value, the callback onSwipeRightEnd is called.
|
|
29
|
-
*/
|
|
30
|
-
leftActionsWidth?: number;
|
|
31
|
-
/**
|
|
32
|
-
* If the user swipe a distance greater than this value, the callback onSwipeLeftEnd is called.
|
|
33
|
-
*/
|
|
34
|
-
rightActionsWidth?: number;
|
|
35
|
-
/**
|
|
36
|
-
* Callback when start swiping to left.
|
|
37
|
-
*/
|
|
38
|
-
onSwipeLeftStart?: (
|
|
39
|
-
event: GestureResponderEvent,
|
|
40
|
-
gestureState: PanResponderGestureState
|
|
41
|
-
) => void;
|
|
42
|
-
/**
|
|
43
|
-
* Callback when end swiping to left.
|
|
44
|
-
*/
|
|
45
|
-
onSwipeLeftEnd?: (
|
|
46
|
-
event: GestureResponderEvent,
|
|
47
|
-
gestureState: PanResponderGestureState
|
|
48
|
-
) => void;
|
|
49
|
-
/**
|
|
50
|
-
* Callback when start swiping to right.
|
|
51
|
-
*/
|
|
52
|
-
onSwipeRightStart?: (
|
|
53
|
-
event: GestureResponderEvent,
|
|
54
|
-
gestureState: PanResponderGestureState
|
|
55
|
-
) => void;
|
|
56
|
-
/**
|
|
57
|
-
* Callback when end swiping to right.
|
|
58
|
-
*/
|
|
59
|
-
onSwipeRightEnd?: (
|
|
60
|
-
event: GestureResponderEvent,
|
|
61
|
-
gestureState: PanResponderGestureState
|
|
62
|
-
) => void;
|
|
63
|
-
/**
|
|
64
|
-
* additional styles
|
|
65
|
-
*/
|
|
66
|
-
style?: StyleProp<ViewStyle>;
|
|
67
|
-
/**
|
|
68
|
-
* React node that is swipeable.
|
|
69
|
-
*/
|
|
70
|
-
children: React.ReactNode;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
type PropsWithDefaultValue = Required<
|
|
74
|
-
Omit<SwipeableV2Props, 'leftContent' | 'rightContent' | 'style'>
|
|
75
|
-
> &
|
|
76
|
-
Pick<SwipeableV2Props, 'leftContent' | 'rightContent' | 'style'>;
|
|
77
|
-
|
|
78
|
-
type ContextValues = PropsWithDefaultValue & {
|
|
79
|
-
canSwipeLeft: boolean;
|
|
80
|
-
canSwipeRight: boolean;
|
|
81
|
-
unmountedRef: React.MutableRefObject<boolean>;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
type State = {
|
|
85
|
-
pan: Animated.ValueXY;
|
|
86
|
-
lastOffset: { x: number; y: number };
|
|
87
|
-
leftActionActivated: boolean;
|
|
88
|
-
rightActionActivated: boolean;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const ReleaseAnimationConfig = {
|
|
92
|
-
toValue: { x: 0, y: 0 },
|
|
93
|
-
duration: 100,
|
|
94
|
-
easing: Easing.elastic(0.5),
|
|
95
|
-
useNativeDriver: true,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const animationToNewState = (pan: Animated.ValueXY) => {
|
|
99
|
-
const animationConfig = ReleaseAnimationConfig;
|
|
100
|
-
|
|
101
|
-
pan.flattenOffset();
|
|
102
|
-
|
|
103
|
-
return Animated.timing(pan, animationConfig);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const hanleOnPanResponderEnd = (
|
|
107
|
-
state: State,
|
|
108
|
-
contextValues: ContextValues,
|
|
109
|
-
event: GestureResponderEvent,
|
|
110
|
-
gestureState: PanResponderGestureState
|
|
111
|
-
) => {
|
|
112
|
-
const { unmountedRef, onSwipeLeftEnd, onSwipeRightEnd } = contextValues;
|
|
113
|
-
const { leftActionActivated, rightActionActivated, pan } = state;
|
|
114
|
-
const animationConfig = ReleaseAnimationConfig;
|
|
115
|
-
|
|
116
|
-
animationToNewState(pan).start(() => {
|
|
117
|
-
if (unmountedRef.current) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (leftActionActivated && onSwipeRightEnd) {
|
|
122
|
-
onSwipeRightEnd(event, gestureState);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (rightActionActivated && onSwipeLeftEnd) {
|
|
126
|
-
onSwipeLeftEnd(event, gestureState);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
...state,
|
|
132
|
-
lastOffset: {
|
|
133
|
-
x: animationConfig.toValue.x,
|
|
134
|
-
y: animationConfig.toValue.y,
|
|
135
|
-
},
|
|
136
|
-
leftActionActivated: false,
|
|
137
|
-
rightActionActivated: false,
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const hanleOnPanResponderMove = (
|
|
142
|
-
state: State,
|
|
143
|
-
contextValues: ContextValues,
|
|
144
|
-
event: GestureResponderEvent,
|
|
145
|
-
gestureState: PanResponderGestureState
|
|
146
|
-
) => {
|
|
147
|
-
const {
|
|
148
|
-
leftActionsWidth,
|
|
149
|
-
rightActionsWidth,
|
|
150
|
-
onSwipeLeftStart,
|
|
151
|
-
onSwipeRightStart,
|
|
152
|
-
canSwipeRight,
|
|
153
|
-
canSwipeLeft,
|
|
154
|
-
} = contextValues;
|
|
155
|
-
const { lastOffset, leftActionActivated, rightActionActivated } = state;
|
|
156
|
-
|
|
157
|
-
const { dx } = gestureState;
|
|
158
|
-
const x = dx + lastOffset.x;
|
|
159
|
-
let nextLeftActionActivated = leftActionActivated;
|
|
160
|
-
let nextRightActionActivated = rightActionActivated;
|
|
161
|
-
|
|
162
|
-
Animated.event(
|
|
163
|
-
[
|
|
164
|
-
null,
|
|
165
|
-
{
|
|
166
|
-
dx: state.pan.x,
|
|
167
|
-
dy: state.pan.y,
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
{ useNativeDriver: false }
|
|
171
|
-
)(event, gestureState);
|
|
172
|
-
|
|
173
|
-
if (!leftActionActivated && canSwipeRight && x >= leftActionsWidth) {
|
|
174
|
-
nextLeftActionActivated = true;
|
|
175
|
-
onSwipeRightStart(event, gestureState);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (leftActionActivated && canSwipeRight && x < leftActionsWidth) {
|
|
179
|
-
nextLeftActionActivated = false;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (!rightActionActivated && canSwipeLeft && x <= -rightActionsWidth) {
|
|
183
|
-
nextRightActionActivated = true;
|
|
184
|
-
onSwipeLeftStart(event, gestureState);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (rightActionActivated && canSwipeLeft && x > -rightActionsWidth) {
|
|
188
|
-
nextRightActionActivated = false;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const needsUpdate =
|
|
192
|
-
nextLeftActionActivated !== leftActionActivated ||
|
|
193
|
-
nextRightActionActivated !== rightActionActivated;
|
|
194
|
-
|
|
195
|
-
if (needsUpdate) {
|
|
196
|
-
return {
|
|
197
|
-
...state,
|
|
198
|
-
leftActionActivated: nextLeftActionActivated,
|
|
199
|
-
rightActionActivated: nextRightActionActivated,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
return state;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const SwipeableV2 = ({
|
|
206
|
-
children,
|
|
207
|
-
leftContent,
|
|
208
|
-
rightContent,
|
|
209
|
-
style,
|
|
210
|
-
leftActionsWidth = scale(200),
|
|
211
|
-
onSwipeLeftStart = noop,
|
|
212
|
-
onSwipeLeftEnd = noop,
|
|
213
|
-
rightActionsWidth = scale(200),
|
|
214
|
-
onSwipeRightStart = noop,
|
|
215
|
-
onSwipeRightEnd = noop,
|
|
216
|
-
...rest
|
|
217
|
-
}: SwipeableV2Props) => {
|
|
218
|
-
const propsWithDefaultValue: PropsWithDefaultValue = {
|
|
219
|
-
children,
|
|
220
|
-
leftContent,
|
|
221
|
-
rightContent,
|
|
222
|
-
style,
|
|
223
|
-
leftActionsWidth,
|
|
224
|
-
onSwipeLeftStart,
|
|
225
|
-
onSwipeLeftEnd,
|
|
226
|
-
rightActionsWidth,
|
|
227
|
-
onSwipeRightStart,
|
|
228
|
-
onSwipeRightEnd,
|
|
229
|
-
...rest,
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const unmountedRef = React.useRef(false);
|
|
233
|
-
useEffect(() => {
|
|
234
|
-
return () => {
|
|
235
|
-
unmountedRef.current = true;
|
|
236
|
-
};
|
|
237
|
-
}, []);
|
|
238
|
-
|
|
239
|
-
const [width, setWidth] = React.useState(0);
|
|
240
|
-
const canSwipeRight = !!leftContent;
|
|
241
|
-
|
|
242
|
-
const canSwipeLeft = !!rightContent;
|
|
243
|
-
|
|
244
|
-
const propsRef = React.useRef<ContextValues>(
|
|
245
|
-
undefined as unknown as ContextValues
|
|
246
|
-
);
|
|
247
|
-
|
|
248
|
-
const [state, setState] = React.useState<State>({
|
|
249
|
-
pan: new Animated.ValueXY({
|
|
250
|
-
x: 0,
|
|
251
|
-
y: 0,
|
|
252
|
-
}),
|
|
253
|
-
lastOffset: { x: 0, y: 0 },
|
|
254
|
-
leftActionActivated: false,
|
|
255
|
-
rightActionActivated: false,
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
propsRef.current = {
|
|
259
|
-
...propsWithDefaultValue,
|
|
260
|
-
canSwipeLeft,
|
|
261
|
-
canSwipeRight,
|
|
262
|
-
unmountedRef,
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
const transform = [
|
|
266
|
-
{
|
|
267
|
-
translateX: state.pan.x.interpolate({
|
|
268
|
-
inputRange: [canSwipeLeft ? -width : 0, canSwipeRight ? width : 0],
|
|
269
|
-
outputRange: [
|
|
270
|
-
canSwipeLeft ? -width + StyleSheet.hairlineWidth : 0,
|
|
271
|
-
canSwipeRight ? width - StyleSheet.hairlineWidth : 0,
|
|
272
|
-
],
|
|
273
|
-
extrapolate: 'clamp',
|
|
274
|
-
}),
|
|
275
|
-
},
|
|
276
|
-
];
|
|
277
|
-
|
|
278
|
-
const panResponder = React.useRef(
|
|
279
|
-
PanResponder.create({
|
|
280
|
-
onMoveShouldSetPanResponder: (
|
|
281
|
-
_: GestureResponderEvent,
|
|
282
|
-
gestureState: PanResponderGestureState
|
|
283
|
-
) => {
|
|
284
|
-
return Math.abs(gestureState.dx) > swipeStartMinDistance;
|
|
285
|
-
},
|
|
286
|
-
onMoveShouldSetPanResponderCapture: (
|
|
287
|
-
_: GestureResponderEvent,
|
|
288
|
-
gestureState: PanResponderGestureState
|
|
289
|
-
) => {
|
|
290
|
-
return Math.abs(gestureState.dx) > swipeStartMinDistance;
|
|
291
|
-
},
|
|
292
|
-
onPanResponderGrant: () => {
|
|
293
|
-
setState((prevState) => {
|
|
294
|
-
prevState.pan.setOffset(prevState.lastOffset);
|
|
295
|
-
return prevState;
|
|
296
|
-
});
|
|
297
|
-
},
|
|
298
|
-
onPanResponderMove: (event, gestureState) => {
|
|
299
|
-
setState((prevState) => {
|
|
300
|
-
return hanleOnPanResponderMove(
|
|
301
|
-
prevState,
|
|
302
|
-
propsRef.current,
|
|
303
|
-
event,
|
|
304
|
-
gestureState
|
|
305
|
-
);
|
|
306
|
-
});
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
onPanResponderRelease: (event, gestureState) => {
|
|
310
|
-
setState((prevState) => {
|
|
311
|
-
return hanleOnPanResponderEnd(
|
|
312
|
-
prevState,
|
|
313
|
-
propsRef.current,
|
|
314
|
-
event,
|
|
315
|
-
gestureState
|
|
316
|
-
);
|
|
317
|
-
});
|
|
318
|
-
},
|
|
319
|
-
onPanResponderTerminationRequest: () => {
|
|
320
|
-
return false;
|
|
321
|
-
},
|
|
322
|
-
onPanResponderTerminate: (event, gestureState) => {
|
|
323
|
-
setState((prevState) => {
|
|
324
|
-
return hanleOnPanResponderEnd(
|
|
325
|
-
prevState,
|
|
326
|
-
propsRef.current,
|
|
327
|
-
event,
|
|
328
|
-
gestureState
|
|
329
|
-
);
|
|
330
|
-
});
|
|
331
|
-
},
|
|
332
|
-
})
|
|
333
|
-
).current;
|
|
334
|
-
|
|
335
|
-
return (
|
|
336
|
-
<StyledWrapper
|
|
337
|
-
onLayout={(event) => {
|
|
338
|
-
setWidth(event.nativeEvent.layout.width);
|
|
339
|
-
}}
|
|
340
|
-
style={[
|
|
341
|
-
{
|
|
342
|
-
flexDirection: 'row',
|
|
343
|
-
},
|
|
344
|
-
style,
|
|
345
|
-
]}
|
|
346
|
-
{...panResponder.panHandlers}
|
|
347
|
-
{...rest}
|
|
348
|
-
>
|
|
349
|
-
{canSwipeRight && (
|
|
350
|
-
<Animated.View style={[{ transform, marginLeft: -width, width }]}>
|
|
351
|
-
{leftContent}
|
|
352
|
-
</Animated.View>
|
|
353
|
-
)}
|
|
354
|
-
<StyledContent style={{ transform }}>{children}</StyledContent>
|
|
355
|
-
{canSwipeLeft && (
|
|
356
|
-
<Animated.View style={[{ transform, marginRight: -width, width }]}>
|
|
357
|
-
{rightContent}
|
|
358
|
-
</Animated.View>
|
|
359
|
-
)}
|
|
360
|
-
</StyledWrapper>
|
|
361
|
-
);
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
export default SwipeableV2;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Animated, View } from 'react-native';
|
|
2
|
-
export declare type ActionIntent = 'primary' | 'success' | 'danger';
|
|
3
|
-
declare const StyledWrapper: import("@emotion/native").StyledComponent<import("react-native").ViewProps & {
|
|
4
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
5
|
-
as?: import("react").ElementType<any> | undefined;
|
|
6
|
-
}, {}, {
|
|
7
|
-
ref?: import("react").Ref<View> | undefined;
|
|
8
|
-
}>;
|
|
9
|
-
declare const StyledContent: import("@emotion/native").StyledComponent<Animated.AnimatedProps<import("react-native").ViewProps & import("react").RefAttributes<View>> & {
|
|
10
|
-
children?: import("react").ReactNode;
|
|
11
|
-
} & {
|
|
12
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
13
|
-
as?: import("react").ElementType<any> | undefined;
|
|
14
|
-
}, {}, {}>;
|
|
15
|
-
export { StyledWrapper, StyledContent };
|