@draftbit/core 49.0.1-10a8bd.2 → 49.0.1-2cdf19.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/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/Progress/CircularProgress/CircularProgress.js +1 -1
- package/lib/commonjs/components/Progress/IndeterminateProgress.js +1 -1
- package/lib/commonjs/components/Progress/LinearProgress/LinearProgress.js +1 -1
- package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts +5 -3
- package/lib/typescript/src/components/BottomSheet/BottomSheet.js +56 -47
- package/lib/typescript/src/components/BottomSheet/BottomSheet.js.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/src/components/BottomSheet/BottomSheet.js +56 -47
- package/src/components/BottomSheet/BottomSheet.js.map +1 -1
- package/src/components/BottomSheet/BottomSheet.tsx +82 -73
- package/lib/commonjs/components/BottomSheet/BottomSheetComponent.js +0 -1
- package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.d.ts +0 -175
- package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.js +0 -444
- package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.js.map +0 -1
- package/src/components/BottomSheet/BottomSheetComponent.js +0 -444
- package/src/components/BottomSheet/BottomSheetComponent.js.map +0 -1
- package/src/components/BottomSheet/BottomSheetComponent.tsx +0 -902
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "49.0.1-
|
|
3
|
+
"version": "49.0.1-2cdf19.2+2cdf191",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"types": "lib/typescript/src/index.d.ts",
|
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@date-io/date-fns": "^1.3.13",
|
|
43
43
|
"@draftbit/react-theme-provider": "^2.1.1",
|
|
44
|
-
"@draftbit/types": "^49.0.1-
|
|
44
|
+
"@draftbit/types": "^49.0.1-2cdf19.2+2cdf191",
|
|
45
45
|
"@expo/vector-icons": "^13.0.0",
|
|
46
|
+
"@gorhom/bottom-sheet": "^5.0.0-alpha.4",
|
|
46
47
|
"@material-ui/core": "^4.11.0",
|
|
47
48
|
"@material-ui/pickers": "^3.2.10",
|
|
48
49
|
"@react-native-community/slider": "4.4.2",
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
"react-native-markdown-display": "^7.0.0-alpha.2",
|
|
65
66
|
"react-native-modal-datetime-picker": "^13.0.0",
|
|
66
67
|
"react-native-pager-view": "6.2.0",
|
|
67
|
-
"react-native-reanimated": "~
|
|
68
|
+
"react-native-reanimated": "~3.3.0",
|
|
68
69
|
"react-native-shadow-2": "^7.0.7",
|
|
69
70
|
"react-native-svg": "13.9.0",
|
|
70
71
|
"react-native-swipe-list-view": "^3.2.9",
|
|
@@ -103,5 +104,5 @@
|
|
|
103
104
|
],
|
|
104
105
|
"testEnvironment": "node"
|
|
105
106
|
},
|
|
106
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "2cdf191afdb983a28fc94617eab369fd287e7183"
|
|
107
108
|
}
|
|
@@ -1,72 +1,81 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { StyleSheet,
|
|
3
|
-
import BottomSheetComponent from "
|
|
2
|
+
import { StyleSheet, Dimensions, } from "react-native";
|
|
3
|
+
import BottomSheetComponent, { BottomSheetScrollView, } from "@gorhom/bottom-sheet";
|
|
4
4
|
import { withTheme } from "../../theming";
|
|
5
|
+
import { useDeepCompareMemo } from "../../utilities";
|
|
6
|
+
const windowHeight = Dimensions.get("window").height;
|
|
7
|
+
// Clarification:
|
|
8
|
+
// Input of snap points is sorted top -> bottom where each value represents distance from top
|
|
9
|
+
// Implementation using `@gorhom/bottom-sheet` is sorted bottom -> top where each value represents distance from bottom
|
|
5
10
|
const BottomSheet = React.forwardRef(({ 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 }, ref) => {
|
|
6
11
|
const backgroundColor = (style === null || style === void 0 ? void 0 : style.backgroundColor) || theme.colors.background;
|
|
7
|
-
const snapPoints = snapPointsProp
|
|
12
|
+
const snapPoints = snapPointsProp !== null && snapPointsProp !== void 0 ? snapPointsProp : [
|
|
8
13
|
topSnapPosition,
|
|
9
14
|
middleSnapPosition,
|
|
10
15
|
bottomSnapPosition,
|
|
11
16
|
];
|
|
17
|
+
const mappedSnapPoints = useDeepCompareMemo(() => convertSnapPointsForNewImplementation(snapPoints), snapPoints);
|
|
12
18
|
const getSnapIndexFromPosition = (position) => {
|
|
13
19
|
switch (position) {
|
|
14
|
-
case "
|
|
20
|
+
case "bottom":
|
|
15
21
|
return 0;
|
|
16
22
|
case "middle":
|
|
17
23
|
return 1;
|
|
18
|
-
case "
|
|
24
|
+
case "top":
|
|
19
25
|
return 2;
|
|
20
26
|
}
|
|
21
27
|
};
|
|
22
|
-
return (React.createElement(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
borderTopLeftRadius: topBorderRadius,
|
|
36
|
-
borderTopRightRadius: topBorderRadius,
|
|
37
|
-
borderWidth,
|
|
38
|
-
borderColor,
|
|
39
|
-
},
|
|
40
|
-
]), onSettle: onSettle, ...rest }, children)));
|
|
28
|
+
return (React.createElement(BottomSheetComponent, { ref: ref, snapPoints: mappedSnapPoints, index: initialSnapIndex != undefined
|
|
29
|
+
? mappedSnapPoints.length - initialSnapIndex - 1
|
|
30
|
+
: getSnapIndexFromPosition(initialSnapPosition), handleIndicatorStyle: [
|
|
31
|
+
{ backgroundColor: handleColor },
|
|
32
|
+
!showHandle ? { display: "none" } : {},
|
|
33
|
+
], backgroundStyle: {
|
|
34
|
+
backgroundColor,
|
|
35
|
+
borderTopLeftRadius: topBorderRadius,
|
|
36
|
+
borderTopRightRadius: topBorderRadius,
|
|
37
|
+
borderWidth,
|
|
38
|
+
borderColor,
|
|
39
|
+
}, onChange: (index) => onSettle === null || onSettle === void 0 ? void 0 : onSettle(mappedSnapPoints.length - index - 1) },
|
|
40
|
+
React.createElement(BottomSheetScrollView, { contentContainerStyle: [styles.contentContainerStyle, style], ...rest }, children)));
|
|
41
41
|
});
|
|
42
|
+
// @gorhom/bottom-sheet has a different format for snap points and requires some manipulation
|
|
43
|
+
function convertSnapPointsForNewImplementation(snapPoints) {
|
|
44
|
+
// Older implementation required snap points sorted top -> bottom, new library requires bottom -> top
|
|
45
|
+
const reversedSnapPoints = [...snapPoints].reverse();
|
|
46
|
+
// Older implementation required snap points as distance from top, new library requires them as distance from bottom
|
|
47
|
+
return reversedSnapPoints.map((point) => {
|
|
48
|
+
if (typeof point === "string") {
|
|
49
|
+
const percentNumber = extractPercentNumber(point);
|
|
50
|
+
if (percentNumber !== undefined) {
|
|
51
|
+
return `${100 - percentNumber}%`;
|
|
52
|
+
}
|
|
53
|
+
return point;
|
|
54
|
+
}
|
|
55
|
+
else if (typeof point === "number") {
|
|
56
|
+
return windowHeight - point;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return point;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function extractPercentNumber(percentString) {
|
|
64
|
+
const percentRegex = /(\d+)?%/;
|
|
65
|
+
const matches = percentString.match(percentRegex);
|
|
66
|
+
if (matches === null || matches === void 0 ? void 0 : matches.length) {
|
|
67
|
+
const percentNumber = Number(matches[1]);
|
|
68
|
+
if (!isNaN(percentNumber)) {
|
|
69
|
+
return percentNumber;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
42
74
|
const styles = StyleSheet.create({
|
|
43
|
-
//Render on top of everything
|
|
44
|
-
parentContainer: {
|
|
45
|
-
position: "absolute",
|
|
46
|
-
left: 0,
|
|
47
|
-
right: 0,
|
|
48
|
-
top: 0,
|
|
49
|
-
bottom: 0,
|
|
50
|
-
zIndex: 10,
|
|
51
|
-
overflow: "hidden",
|
|
52
|
-
},
|
|
53
75
|
contentContainerStyle: {
|
|
54
76
|
paddingHorizontal: 16,
|
|
55
77
|
paddingVertical: 10,
|
|
56
78
|
},
|
|
57
|
-
containerStyle: {
|
|
58
|
-
flex: 1,
|
|
59
|
-
overflow: "hidden",
|
|
60
|
-
},
|
|
61
|
-
handleContainer: {
|
|
62
|
-
alignItems: "center",
|
|
63
|
-
paddingVertical: 20,
|
|
64
|
-
},
|
|
65
|
-
handle: {
|
|
66
|
-
width: 40,
|
|
67
|
-
height: 2,
|
|
68
|
-
borderRadius: 4,
|
|
69
|
-
},
|
|
70
79
|
});
|
|
71
80
|
export default withTheme(BottomSheet);
|
|
72
81
|
//# sourceMappingURL=BottomSheet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.js","sourceRoot":"","sources":["BottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"BottomSheet.js","sourceRoot":"","sources":["BottomSheet.tsx"],"names":[],"mappings":"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"}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import {
|
|
3
3
|
StyleSheet,
|
|
4
|
-
View,
|
|
5
4
|
StyleProp,
|
|
6
5
|
ViewStyle,
|
|
7
6
|
ScrollViewProps,
|
|
7
|
+
Dimensions,
|
|
8
8
|
} from "react-native";
|
|
9
9
|
|
|
10
|
-
import BottomSheetComponent
|
|
10
|
+
import BottomSheetComponent, {
|
|
11
|
+
BottomSheetScrollView,
|
|
12
|
+
} from "@gorhom/bottom-sheet";
|
|
11
13
|
import type { Theme } from "../../styles/DefaultTheme";
|
|
12
14
|
import { withTheme } from "../../theming";
|
|
15
|
+
import { useDeepCompareMemo } from "../../utilities";
|
|
13
16
|
|
|
14
17
|
type SnapPosition = "top" | "middle" | "bottom";
|
|
18
|
+
|
|
19
|
+
const windowHeight = Dimensions.get("window").height;
|
|
20
|
+
|
|
15
21
|
export interface BottomSheetProps extends ScrollViewProps {
|
|
16
22
|
topSnapPosition?: string | number;
|
|
17
23
|
middleSnapPosition?: string | number;
|
|
18
24
|
bottomSnapPosition?: string | number;
|
|
25
|
+
/**
|
|
26
|
+
* As distance from top (number or percentage string), sorted from top to bottom
|
|
27
|
+
*/
|
|
19
28
|
snapPoints?: (string | number)[];
|
|
20
29
|
initialSnapIndex?: number;
|
|
21
30
|
initialSnapPosition?: SnapPosition;
|
|
@@ -32,10 +41,10 @@ export interface BottomSheetProps extends ScrollViewProps {
|
|
|
32
41
|
theme: Theme;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
>(
|
|
44
|
+
// Clarification:
|
|
45
|
+
// Input of snap points is sorted top -> bottom where each value represents distance from top
|
|
46
|
+
// Implementation using `@gorhom/bottom-sheet` is sorted bottom -> top where each value represents distance from bottom
|
|
47
|
+
const BottomSheet = React.forwardRef<BottomSheetComponent, BottomSheetProps>(
|
|
39
48
|
(
|
|
40
49
|
{
|
|
41
50
|
theme,
|
|
@@ -60,101 +69,101 @@ const BottomSheet = React.forwardRef<
|
|
|
60
69
|
const backgroundColor =
|
|
61
70
|
(style as ViewStyle)?.backgroundColor || theme.colors.background;
|
|
62
71
|
|
|
63
|
-
const snapPoints = snapPointsProp
|
|
72
|
+
const snapPoints = snapPointsProp ?? [
|
|
64
73
|
topSnapPosition,
|
|
65
74
|
middleSnapPosition,
|
|
66
75
|
bottomSnapPosition,
|
|
67
76
|
];
|
|
68
77
|
|
|
78
|
+
const mappedSnapPoints = useDeepCompareMemo(
|
|
79
|
+
() => convertSnapPointsForNewImplementation(snapPoints),
|
|
80
|
+
snapPoints
|
|
81
|
+
);
|
|
82
|
+
|
|
69
83
|
const getSnapIndexFromPosition = (position: SnapPosition) => {
|
|
70
84
|
switch (position) {
|
|
71
|
-
case "
|
|
85
|
+
case "bottom":
|
|
72
86
|
return 0;
|
|
73
87
|
case "middle":
|
|
74
88
|
return 1;
|
|
75
|
-
case "
|
|
89
|
+
case "top":
|
|
76
90
|
return 2;
|
|
77
91
|
}
|
|
78
92
|
};
|
|
79
93
|
|
|
80
94
|
return (
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
style={[styles.handle, { backgroundColor: handleColor }]}
|
|
104
|
-
/>
|
|
105
|
-
</View>
|
|
106
|
-
)}
|
|
107
|
-
</>
|
|
108
|
-
)}
|
|
95
|
+
<BottomSheetComponent
|
|
96
|
+
ref={ref}
|
|
97
|
+
snapPoints={mappedSnapPoints}
|
|
98
|
+
index={
|
|
99
|
+
initialSnapIndex != undefined
|
|
100
|
+
? mappedSnapPoints.length - initialSnapIndex - 1
|
|
101
|
+
: getSnapIndexFromPosition(initialSnapPosition)
|
|
102
|
+
}
|
|
103
|
+
handleIndicatorStyle={[
|
|
104
|
+
{ backgroundColor: handleColor },
|
|
105
|
+
!showHandle ? { display: "none" } : {},
|
|
106
|
+
]}
|
|
107
|
+
backgroundStyle={{
|
|
108
|
+
backgroundColor,
|
|
109
|
+
borderTopLeftRadius: topBorderRadius,
|
|
110
|
+
borderTopRightRadius: topBorderRadius,
|
|
111
|
+
borderWidth,
|
|
112
|
+
borderColor,
|
|
113
|
+
}}
|
|
114
|
+
onChange={(index) => onSettle?.(mappedSnapPoints.length - index - 1)}
|
|
115
|
+
>
|
|
116
|
+
<BottomSheetScrollView
|
|
109
117
|
contentContainerStyle={[styles.contentContainerStyle, style]}
|
|
110
|
-
containerStyle={StyleSheet.flatten([
|
|
111
|
-
styles.containerStyle,
|
|
112
|
-
{
|
|
113
|
-
backgroundColor,
|
|
114
|
-
borderTopLeftRadius: topBorderRadius,
|
|
115
|
-
borderTopRightRadius: topBorderRadius,
|
|
116
|
-
borderWidth,
|
|
117
|
-
borderColor,
|
|
118
|
-
},
|
|
119
|
-
])}
|
|
120
|
-
onSettle={onSettle}
|
|
121
118
|
{...rest}
|
|
122
119
|
>
|
|
123
120
|
{children}
|
|
124
|
-
</
|
|
125
|
-
</
|
|
121
|
+
</BottomSheetScrollView>
|
|
122
|
+
</BottomSheetComponent>
|
|
126
123
|
);
|
|
127
124
|
}
|
|
128
125
|
);
|
|
129
126
|
|
|
127
|
+
// @gorhom/bottom-sheet has a different format for snap points and requires some manipulation
|
|
128
|
+
function convertSnapPointsForNewImplementation(
|
|
129
|
+
snapPoints: (string | number)[]
|
|
130
|
+
) {
|
|
131
|
+
// Older implementation required snap points sorted top -> bottom, new library requires bottom -> top
|
|
132
|
+
const reversedSnapPoints = [...snapPoints].reverse();
|
|
133
|
+
|
|
134
|
+
// Older implementation required snap points as distance from top, new library requires them as distance from bottom
|
|
135
|
+
return reversedSnapPoints.map((point) => {
|
|
136
|
+
if (typeof point === "string") {
|
|
137
|
+
const percentNumber = extractPercentNumber(point);
|
|
138
|
+
if (percentNumber !== undefined) {
|
|
139
|
+
return `${100 - percentNumber}%`;
|
|
140
|
+
}
|
|
141
|
+
return point;
|
|
142
|
+
} else if (typeof point === "number") {
|
|
143
|
+
return windowHeight - point;
|
|
144
|
+
} else {
|
|
145
|
+
return point;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function extractPercentNumber(percentString: string) {
|
|
151
|
+
const percentRegex = /(\d+)?%/;
|
|
152
|
+
const matches = percentString.match(percentRegex);
|
|
153
|
+
if (matches?.length) {
|
|
154
|
+
const percentNumber = Number(matches[1]);
|
|
155
|
+
if (!isNaN(percentNumber)) {
|
|
156
|
+
return percentNumber;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
130
162
|
const styles = StyleSheet.create({
|
|
131
|
-
//Render on top of everything
|
|
132
|
-
parentContainer: {
|
|
133
|
-
position: "absolute",
|
|
134
|
-
left: 0,
|
|
135
|
-
right: 0,
|
|
136
|
-
top: 0,
|
|
137
|
-
bottom: 0,
|
|
138
|
-
zIndex: 10,
|
|
139
|
-
overflow: "hidden",
|
|
140
|
-
},
|
|
141
163
|
contentContainerStyle: {
|
|
142
164
|
paddingHorizontal: 16,
|
|
143
165
|
paddingVertical: 10,
|
|
144
166
|
},
|
|
145
|
-
containerStyle: {
|
|
146
|
-
flex: 1,
|
|
147
|
-
overflow: "hidden",
|
|
148
|
-
},
|
|
149
|
-
handleContainer: {
|
|
150
|
-
alignItems: "center",
|
|
151
|
-
paddingVertical: 20,
|
|
152
|
-
},
|
|
153
|
-
handle: {
|
|
154
|
-
width: 40,
|
|
155
|
-
height: 2,
|
|
156
|
-
borderRadius: 4,
|
|
157
|
-
},
|
|
158
167
|
});
|
|
159
168
|
|
|
160
169
|
export default withTheme(BottomSheet);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.ScrollBottomSheet=void 0;var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _reactNativeGestureHandler=require("react-native-gesture-handler");var _jsxRuntime=require("react/jsx-runtime");var _excluded=["renderHandle","initialSnapIndex","containerStyle"];var _imperativeScrollOpti,_jsxFileName="/home/runner/work/react-native-jigsaw/react-native-jigsaw/packages/core/src/components/BottomSheet/BottomSheetComponent.tsx";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=(0,_getPrototypeOf2.default)(Derived),result;if(hasNativeReflectConstruct){var NewTarget=(0,_getPrototypeOf2.default)(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return(0,_possibleConstructorReturn2.default)(this,result);};}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}var interpolateDeprecated=_reactNativeReanimated.default.interpolate,interpolateNode=_reactNativeReanimated.default.interpolateNode;var interpolate=interpolateNode!=null?interpolateNode:interpolateDeprecated;var Easing=_reactNativeReanimated.EasingNode!=null?_reactNativeReanimated.EasingNode:_reactNativeReanimated.Easing;var FlatListComponentType="FlatList";var ScrollViewComponentType="ScrollView";var SectionListComponentType="SectionList";var TimingAnimationType="timing";var SpringAnimationType="spring";var DEFAULT_SPRING_PARAMS={damping:50,mass:0.3,stiffness:121.6,overshootClamping:true,restSpeedThreshold:0.3,restDisplacementThreshold:0.3};var _Dimensions$get=_reactNative.Dimensions.get("window"),windowHeight=_Dimensions$get.height;var IOS_NORMAL_DECELERATION_RATE=0.998;var ANDROID_NORMAL_DECELERATION_RATE=0.985;var DEFAULT_ANIMATION_DURATION=250;var DEFAULT_EASING=Easing.inOut(Easing.linear);var imperativeScrollOptions=(_imperativeScrollOpti={},(0,_defineProperty2.default)(_imperativeScrollOpti,FlatListComponentType,{method:"scrollToIndex",args:{index:0,viewPosition:0,viewOffset:1000,animated:true}}),(0,_defineProperty2.default)(_imperativeScrollOpti,ScrollViewComponentType,{method:"scrollTo",args:{x:0,y:0,animated:true}}),(0,_defineProperty2.default)(_imperativeScrollOpti,SectionListComponentType,{method:"scrollToLocation",args:{itemIndex:0,sectionIndex:0,viewPosition:0,viewOffset:1000,animated:true}}),_imperativeScrollOpti);var ScrollBottomSheet=function(_Component){(0,_inherits2.default)(ScrollBottomSheet,_Component);var _super=_createSuper(ScrollBottomSheet);function ScrollBottomSheet(props){var _props$animationConfi;var _this;(0,_classCallCheck2.default)(this,ScrollBottomSheet);_this=_super.call(this,props);_this.masterDrawer=_react.default.createRef();_this.drawerHandleRef=_react.default.createRef();_this.drawerContentRef=_react.default.createRef();_this.scrollComponentRef=_react.default.createRef();_this.isManuallySetValue=new _reactNativeReanimated.Value(0);_this.manualYOffset=new _reactNativeReanimated.Value(0);_this.prevSnapIndex=-1;_this.dragY=new _reactNativeReanimated.Value(0);_this.prevDragY=new _reactNativeReanimated.Value(0);_this.tempDestSnapPoint=new _reactNativeReanimated.Value(0);_this.isAndroid=new _reactNativeReanimated.Value(Number(_reactNative.Platform.OS==="android"));_this.animationClock=new _reactNativeReanimated.Clock();_this.animationPosition=new _reactNativeReanimated.Value(0);_this.animationFinished=new _reactNativeReanimated.Value(0);_this.animationFrameTime=new _reactNativeReanimated.Value(0);_this.velocityY=new _reactNativeReanimated.Value(0);_this.lastStartScrollY=new _reactNativeReanimated.Value(0);_this.destSnapPoint=new _reactNativeReanimated.Value(0);_this.dragWithHandle=new _reactNativeReanimated.Value(0);_this.scrollUpAndPullDown=new _reactNativeReanimated.Value(0);_this.convertPercentageToDp=function(str){return Number(str.split("%")[0])*(windowHeight-_this.props.topInset)/100;};_this.getNormalisedSnapPoints=function(){return _this.props.snapPoints.map(function(p){if(typeof p==="string"){return _this.convertPercentageToDp(p);}else if(typeof p==="number"){return p;}throw new Error(`Invalid type for value ${p}: ${typeof p}. It should be either a percentage string or a number`);});};_this.getScrollComponent=function(){switch(_this.props.componentType){case"FlatList":return _reactNative.FlatList;case"ScrollView":return _reactNative.ScrollView;case"SectionList":return _reactNative.SectionList;default:throw new Error("Component type not supported: it should be one of `FlatList`, `ScrollView` or `SectionList`");}};_this.snapTo=function(index){var snapPoints=_this.getNormalisedSnapPoints();_this.isManuallySetValue.setValue(1);_this.manualYOffset.setValue(snapPoints[index]);_this.nextSnapIndex.setValue(index);};var initialSnapIndex=props.initialSnapIndex,animationType=props.animationType;var animationDriver=animationType==="timing"?0:1;var animationDuration=props.animationType==="timing"&&((_props$animationConfi=props.animationConfig)==null?void 0:_props$animationConfi.duration)||DEFAULT_ANIMATION_DURATION;var ScrollComponent=_this.getScrollComponent();_this.scrollComponent=_reactNativeReanimated.default.createAnimatedComponent(ScrollComponent);var _snapPoints=_this.getNormalisedSnapPoints();var openPosition=_snapPoints[0];var closedPosition=_this.props.enableOverScroll?windowHeight:_snapPoints[_snapPoints.length-1];var initialSnap=_snapPoints[initialSnapIndex];_this.nextSnapIndex=new _reactNativeReanimated.Value(initialSnapIndex);var initialDecelerationRate=_reactNative.Platform.select({android:props.initialSnapIndex===0?ANDROID_NORMAL_DECELERATION_RATE:0,ios:IOS_NORMAL_DECELERATION_RATE});_this.decelerationRate=new _reactNativeReanimated.Value(initialDecelerationRate);var handleGestureState=new _reactNativeReanimated.Value(-1);var handleOldGestureState=new _reactNativeReanimated.Value(-1);var drawerGestureState=new _reactNativeReanimated.Value(-1);var drawerOldGestureState=new _reactNativeReanimated.Value(-1);var lastSnapInRange=new _reactNativeReanimated.Value(1);_this.prevTranslateYOffset=new _reactNativeReanimated.Value(initialSnap);_this.translationY=new _reactNativeReanimated.Value(initialSnap);_this.lastSnap=new _reactNativeReanimated.Value(initialSnap);_this.onHandleGestureEvent=(0,_reactNativeReanimated.event)([{nativeEvent:{translationY:_this.dragY,oldState:handleOldGestureState,state:handleGestureState,velocityY:_this.velocityY}}]);_this.onDrawerGestureEvent=(0,_reactNativeReanimated.event)([{nativeEvent:{translationY:_this.dragY,oldState:drawerOldGestureState,state:drawerGestureState,velocityY:_this.velocityY}}]);_this.onScrollBeginDrag=(0,_reactNativeReanimated.event)([{nativeEvent:{contentOffset:{y:_this.lastStartScrollY}}}]);var didHandleGestureBegin=(0,_reactNativeReanimated.eq)(handleGestureState,_reactNativeGestureHandler.State.ACTIVE);var isAnimationInterrupted=(0,_reactNativeReanimated.and)((0,_reactNativeReanimated.or)((0,_reactNativeReanimated.eq)(handleGestureState,_reactNativeGestureHandler.State.BEGAN),(0,_reactNativeReanimated.eq)(drawerGestureState,_reactNativeGestureHandler.State.BEGAN),(0,_reactNativeReanimated.and)((0,_reactNativeReanimated.eq)(_this.isAndroid,0),(0,_reactNativeReanimated.eq)(animationDriver,1),(0,_reactNativeReanimated.or)((0,_reactNativeReanimated.eq)(drawerGestureState,_reactNativeGestureHandler.State.ACTIVE),(0,_reactNativeReanimated.eq)(handleGestureState,_reactNativeGestureHandler.State.ACTIVE)))),(0,_reactNativeReanimated.clockRunning)(_this.animationClock));_this.didGestureFinish=(0,_reactNativeReanimated.or)((0,_reactNativeReanimated.and)((0,_reactNativeReanimated.eq)(handleOldGestureState,_reactNativeGestureHandler.State.ACTIVE),(0,_reactNativeReanimated.eq)(handleGestureState,_reactNativeGestureHandler.State.END)),(0,_reactNativeReanimated.and)((0,_reactNativeReanimated.eq)(drawerOldGestureState,_reactNativeGestureHandler.State.ACTIVE),(0,_reactNativeReanimated.eq)(drawerGestureState,_reactNativeGestureHandler.State.END)));var isLastSnapPointInRange=function isLastSnapPointInRange(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;return i===_snapPoints.length?lastSnapInRange:(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(_this.lastSnap,_snapPoints[i]),[(0,_reactNativeReanimated.set)(lastSnapInRange,1)],isLastSnapPointInRange(i+1));};var scrollY=[(0,_reactNativeReanimated.set)(lastSnapInRange,0),isLastSnapPointInRange(),(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.or)(didHandleGestureBegin,(0,_reactNativeReanimated.and)(_this.isManuallySetValue,(0,_reactNativeReanimated.not)((0,_reactNativeReanimated.eq)(_this.manualYOffset,_snapPoints[0])))),[(0,_reactNativeReanimated.set)(_this.dragWithHandle,1),0]),(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.and)((0,_reactNativeReanimated.eq)(_this.dragWithHandle,1),(0,_reactNativeReanimated.greaterThan)(_snapPoints[0],(0,_reactNativeReanimated.add)(_this.lastSnap,_this.dragY)),(0,_reactNativeReanimated.and)((0,_reactNativeReanimated.not)((0,_reactNativeReanimated.eq)(_this.lastSnap,_snapPoints[0])),lastSnapInRange)),[(0,_reactNativeReanimated.set)(_this.lastSnap,_snapPoints[0]),(0,_reactNativeReanimated.set)(_this.dragWithHandle,0),_this.lastStartScrollY],(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(_this.dragWithHandle,1),0,_this.lastStartScrollY))];_this.didScrollUpAndPullDown=(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.and)((0,_reactNativeReanimated.greaterOrEq)(_this.dragY,_this.lastStartScrollY),(0,_reactNativeReanimated.greaterThan)(_this.lastStartScrollY,0)),(0,_reactNativeReanimated.set)(_this.scrollUpAndPullDown,1));_this.setTranslationY=(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.and)((0,_reactNativeReanimated.not)(_this.dragWithHandle),(0,_reactNativeReanimated.not)((0,_reactNativeReanimated.greaterOrEq)(_this.dragY,_this.lastStartScrollY))),(0,_reactNativeReanimated.set)(_this.translationY,(0,_reactNativeReanimated.sub)(_this.dragY,_this.lastStartScrollY)),(0,_reactNativeReanimated.set)(_this.translationY,_this.dragY));_this.extraOffset=(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(_this.scrollUpAndPullDown,1),_this.lastStartScrollY,0);var endOffsetY=(0,_reactNativeReanimated.add)(_this.lastSnap,_this.translationY,(0,_reactNativeReanimated.multiply)(1-props.friction,_this.velocityY));_this.calculateNextSnapPoint=function(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;return i===_snapPoints.length?_this.tempDestSnapPoint:(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.greaterThan)((0,_reactNativeReanimated.abs)((0,_reactNativeReanimated.sub)(_this.tempDestSnapPoint,endOffsetY)),(0,_reactNativeReanimated.abs)((0,_reactNativeReanimated.sub)((0,_reactNativeReanimated.add)(_snapPoints[i],_this.extraOffset),endOffsetY))),[(0,_reactNativeReanimated.set)(_this.tempDestSnapPoint,(0,_reactNativeReanimated.add)(_snapPoints[i],_this.extraOffset)),(0,_reactNativeReanimated.set)(_this.nextSnapIndex,i),_this.calculateNextSnapPoint(i+1)],_this.calculateNextSnapPoint(i+1));};var runAnimation=function runAnimation(_ref){var _props$animationConfi2;var clock=_ref.clock,from=_ref.from,to=_ref.to,position=_ref.position,finished=_ref.finished,velocity=_ref.velocity,frameTime=_ref.frameTime;var state={finished:finished,velocity:new _reactNativeReanimated.Value(0),position:position,time:new _reactNativeReanimated.Value(0),frameTime:frameTime};var timingConfig={duration:animationDuration,easing:props.animationType==="timing"&&((_props$animationConfi2=props.animationConfig)==null?void 0:_props$animationConfi2.easing)||DEFAULT_EASING,toValue:new _reactNativeReanimated.Value(0)};var springConfig=Object.assign({},DEFAULT_SPRING_PARAMS,props.animationType==="spring"&&props.animationConfig||{},{toValue:new _reactNativeReanimated.Value(0)});return[(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.and)((0,_reactNativeReanimated.not)((0,_reactNativeReanimated.clockRunning)(clock)),(0,_reactNativeReanimated.not)((0,_reactNativeReanimated.eq)(finished,1))),[(0,_reactNativeReanimated.set)(state.finished,0),(0,_reactNativeReanimated.set)(state.velocity,velocity),(0,_reactNativeReanimated.set)(state.time,0),(0,_reactNativeReanimated.set)(state.position,from),(0,_reactNativeReanimated.set)(state.frameTime,0),(0,_reactNativeReanimated.set)(timingConfig.toValue,to),(0,_reactNativeReanimated.set)(springConfig.toValue,to),(0,_reactNativeReanimated.startClock)(clock)]),(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(animationDriver,0),(0,_reactNativeReanimated.timing)(clock,state,timingConfig),(0,_reactNativeReanimated.spring)(clock,state,springConfig)),(0,_reactNativeReanimated.cond)(state.finished,[(0,_reactNativeReanimated.call)([_this.nextSnapIndex],function(_ref2){var _ref3=(0,_slicedToArray2.default)(_ref2,1),value=_ref3[0];if(value!==_this.prevSnapIndex){_this.props.onSettle==null?void 0:_this.props.onSettle(value);}_this.prevSnapIndex=value;}),(0,_reactNativeReanimated.set)(drawerOldGestureState,_reactNativeGestureHandler.State.END),(0,_reactNativeReanimated.set)(handleOldGestureState,_reactNativeGestureHandler.State.END),(0,_reactNativeReanimated.set)(_this.prevTranslateYOffset,state.position),(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(_this.scrollUpAndPullDown,1),[(0,_reactNativeReanimated.set)(_this.prevTranslateYOffset,(0,_reactNativeReanimated.sub)(_this.prevTranslateYOffset,_this.lastStartScrollY)),(0,_reactNativeReanimated.set)(_this.lastStartScrollY,0),(0,_reactNativeReanimated.set)(_this.scrollUpAndPullDown,0)]),(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(_this.destSnapPoint,_snapPoints[0]),[(0,_reactNativeReanimated.set)(_this.dragWithHandle,0)]),(0,_reactNativeReanimated.set)(_this.isManuallySetValue,0),(0,_reactNativeReanimated.set)(_this.manualYOffset,0),(0,_reactNativeReanimated.stopClock)(clock),_this.prevTranslateYOffset],state.position)];};var translateYOffset=(0,_reactNativeReanimated.cond)(isAnimationInterrupted,[(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.or)(_this.dragWithHandle,(0,_reactNativeReanimated.greaterOrEq)((0,_reactNativeReanimated.abs)(_this.prevDragY),_this.lastStartScrollY)),(0,_reactNativeReanimated.set)(_this.prevTranslateYOffset,_this.animationPosition)),(0,_reactNativeReanimated.set)(_this.animationFinished,1),(0,_reactNativeReanimated.set)(_this.translationY,0),(0,_reactNativeReanimated.set)(drawerOldGestureState,_reactNativeGestureHandler.State.END),(0,_reactNativeReanimated.set)(handleOldGestureState,_reactNativeGestureHandler.State.END),(0,_reactNativeReanimated.set)(_this.animationFrameTime,(0,_reactNativeReanimated.add)(animationDuration,1000)),(0,_reactNativeReanimated.set)(_this.velocityY,0),(0,_reactNativeReanimated.stopClock)(_this.animationClock),_this.prevTranslateYOffset],(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.or)(_this.didGestureFinish,_this.isManuallySetValue,(0,_reactNativeReanimated.clockRunning)(_this.animationClock)),[runAnimation({clock:_this.animationClock,from:(0,_reactNativeReanimated.cond)(_this.isManuallySetValue,_this.prevTranslateYOffset,(0,_reactNativeReanimated.add)(_this.prevTranslateYOffset,_this.translationY)),to:_this.destSnapPoint,position:_this.animationPosition,finished:_this.animationFinished,frameTime:_this.animationFrameTime,velocity:_this.velocityY})],[(0,_reactNativeReanimated.set)(_this.animationFrameTime,0),(0,_reactNativeReanimated.set)(_this.animationFinished,0),_this.prevTranslateYOffset]));_this.translateY=interpolate((0,_reactNativeReanimated.add)(translateYOffset,_this.dragY,(0,_reactNativeReanimated.multiply)(scrollY,-1)),{inputRange:[openPosition,closedPosition],outputRange:[openPosition,closedPosition],extrapolate:_reactNativeReanimated.Extrapolate.CLAMP});_this.position=interpolate(_this.translateY,{inputRange:[openPosition,_snapPoints[_snapPoints.length-1]],outputRange:[1,0],extrapolate:_reactNativeReanimated.Extrapolate.CLAMP});return _this;}(0,_createClass2.default)(ScrollBottomSheet,[{key:"render",value:function render(){var _this2=this;var _this$props=this.props,renderHandle=_this$props.renderHandle,initialSnapIndex=_this$props.initialSnapIndex,containerStyle=_this$props.containerStyle,rest=(0,_objectWithoutProperties2.default)(_this$props,_excluded);var AnimatedScrollableComponent=this.scrollComponent;var normalisedSnapPoints=this.getNormalisedSnapPoints();var initialSnap=normalisedSnapPoints[initialSnapIndex];var Content=(0,_jsxRuntime.jsxs)(_reactNativeReanimated.default.View,{style:[_reactNative.StyleSheet.absoluteFillObject,containerStyle,{transform:[{translateY:this.translateY}]}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.PanGestureHandler,{ref:this.drawerHandleRef,shouldCancelWhenOutside:false,simultaneousHandlers:this.masterDrawer,onGestureEvent:this.onHandleGestureEvent,onHandlerStateChange:this.onHandleGestureEvent,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{children:renderHandle()})}),(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.PanGestureHandler,{ref:this.drawerContentRef,simultaneousHandlers:[this.scrollComponentRef,this.masterDrawer],shouldCancelWhenOutside:false,onGestureEvent:this.onDrawerGestureEvent,onHandlerStateChange:this.onDrawerGestureEvent,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:styles.container,children:(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.NativeViewGestureHandler,{ref:this.scrollComponentRef,waitFor:this.masterDrawer,simultaneousHandlers:this.drawerContentRef,children:(0,_jsxRuntime.jsx)(AnimatedScrollableComponent,Object.assign({overScrollMode:"never",bounces:false},rest,{ref:this.props.innerRef,decelerationRate:this.decelerationRate,onScrollBeginDrag:this.onScrollBeginDrag,scrollEventThrottle:1,contentContainerStyle:[rest.contentContainerStyle,{paddingBottom:this.getNormalisedSnapPoints()[0]}]}))})})}),this.props.animatedPosition&&(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Code,{exec:(0,_reactNativeReanimated.onChange)(this.position,(0,_reactNativeReanimated.set)(this.props.animatedPosition,this.position))}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Code,{exec:(0,_reactNativeReanimated.onChange)(this.dragY,(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.not)((0,_reactNativeReanimated.eq)(this.dragY,0)),(0,_reactNativeReanimated.set)(this.prevDragY,this.dragY)))}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Code,{exec:(0,_reactNativeReanimated.onChange)(this.didGestureFinish,(0,_reactNativeReanimated.cond)(this.didGestureFinish,[this.didScrollUpAndPullDown,this.setTranslationY,(0,_reactNativeReanimated.set)(this.tempDestSnapPoint,(0,_reactNativeReanimated.add)(normalisedSnapPoints[0],this.extraOffset)),(0,_reactNativeReanimated.set)(this.nextSnapIndex,0),(0,_reactNativeReanimated.set)(this.destSnapPoint,this.calculateNextSnapPoint()),(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.and)((0,_reactNativeReanimated.greaterThan)(this.dragY,this.lastStartScrollY),this.isAndroid,(0,_reactNativeReanimated.not)(this.dragWithHandle)),(0,_reactNativeReanimated.call)([],function(){var _this2$props,_this2$props$data;var _imperativeScrollOpti2=imperativeScrollOptions[_this2.props.componentType],method=_imperativeScrollOpti2.method,args=_imperativeScrollOpti2.args;var node=_this2.props.innerRef.current;if(node&&node[method]&&(_this2.props.componentType==="FlatList"&&(((_this2$props=_this2.props)==null?void 0:(_this2$props$data=_this2$props.data)==null?void 0:_this2$props$data.length)||0)>0||_this2.props.componentType==="SectionList"&&_this2.props.sections.length>0||_this2.props.componentType==="ScrollView")){node[method](args);}})),(0,_reactNativeReanimated.set)(this.dragY,0),(0,_reactNativeReanimated.set)(this.velocityY,0),(0,_reactNativeReanimated.set)(this.lastSnap,(0,_reactNativeReanimated.sub)(this.destSnapPoint,(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(this.scrollUpAndPullDown,1),this.lastStartScrollY,0))),(0,_reactNativeReanimated.call)([this.lastSnap],function(_ref4){var _this2$masterDrawer,_this2$masterDrawer$c;var _ref5=(0,_slicedToArray2.default)(_ref4,1),value=_ref5[0];(_this2$masterDrawer=_this2.masterDrawer)==null?void 0:(_this2$masterDrawer$c=_this2$masterDrawer.current)==null?void 0:_this2$masterDrawer$c.setNativeProps({maxDeltaY:value-_this2.getNormalisedSnapPoints()[0]});}),(0,_reactNativeReanimated.set)(this.decelerationRate,(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(this.isAndroid,1),(0,_reactNativeReanimated.cond)((0,_reactNativeReanimated.eq)(this.lastSnap,normalisedSnapPoints[0]),ANDROID_NORMAL_DECELERATION_RATE,0),IOS_NORMAL_DECELERATION_RATE))]))}),(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Code,{exec:(0,_reactNativeReanimated.onChange)(this.isManuallySetValue,[(0,_reactNativeReanimated.cond)(this.isManuallySetValue,[(0,_reactNativeReanimated.set)(this.destSnapPoint,this.manualYOffset),(0,_reactNativeReanimated.set)(this.animationFinished,0),(0,_reactNativeReanimated.set)(this.lastSnap,this.manualYOffset),(0,_reactNativeReanimated.call)([this.lastSnap],function(_ref6){var _this2$masterDrawer2,_this2$masterDrawer2$;var _ref7=(0,_slicedToArray2.default)(_ref6,1),value=_ref7[0];(_this2$masterDrawer2=_this2.masterDrawer)==null?void 0:(_this2$masterDrawer2$=_this2$masterDrawer2.current)==null?void 0:_this2$masterDrawer2$.setNativeProps({maxDeltaY:value-_this2.getNormalisedSnapPoints()[0]});})],[(0,_reactNativeReanimated.set)(this.nextSnapIndex,0)])])})]});if(_reactNative.Platform.OS==="android"){return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.TapGestureHandler,{maxDurationMs:100000,ref:this.masterDrawer,maxDeltaY:initialSnap-this.getNormalisedSnapPoints()[0],shouldCancelWhenOutside:false,children:Content});}return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.TapGestureHandler,{maxDurationMs:100000,ref:this.masterDrawer,maxDeltaY:initialSnap-this.getNormalisedSnapPoints()[0],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:_reactNative.StyleSheet.absoluteFillObject,pointerEvents:"box-none",children:Content})});}}]);return ScrollBottomSheet;}(_react.Component);exports.ScrollBottomSheet=ScrollBottomSheet;ScrollBottomSheet.defaultProps={topInset:0,friction:0.95,animationType:"timing",innerRef:_react.default.createRef(),enableOverScroll:false};var _default=ScrollBottomSheet;exports.default=_default;var styles=_reactNative.StyleSheet.create({container:{flex:1}});
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TODO: Replace with https://github.com/gorhom/react-native-bottom-sheet. (@gorhom/bottom-sheet)
|
|
3
|
-
* @gorhom/bottom-sheet v5 (which is not ready yet) will support web, allowing us to transition to that better supported library
|
|
4
|
-
*
|
|
5
|
-
* We are unable to upgrade to reanimated v3 until this is removed since it relies on reanimated v1 APIs
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Slightly modfied version as taken from https://github.com/rgommezz/react-native-scroll-bottom-sheet
|
|
9
|
-
* Main previously breaking change:
|
|
10
|
-
* const node = this.props.innerRef.current?.getNode() ==> const node = this.props.innerRef.current as any
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Copyright (c) 2020 Raul Gomez Acuna
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
import React, { Component, RefObject } from "react";
|
|
20
|
-
import { FlatList, FlatListProps, ScrollView, ScrollViewProps, SectionList, SectionListProps, ViewStyle } from "react-native";
|
|
21
|
-
import Animated from "react-native-reanimated";
|
|
22
|
-
import { Assign } from "utility-types";
|
|
23
|
-
declare const FlatListComponentType: "FlatList";
|
|
24
|
-
declare const ScrollViewComponentType: "ScrollView";
|
|
25
|
-
declare const SectionListComponentType: "SectionList";
|
|
26
|
-
declare const TimingAnimationType: "timing";
|
|
27
|
-
declare const SpringAnimationType: "spring";
|
|
28
|
-
declare type AnimatedScrollableComponent = FlatList | ScrollView | SectionList;
|
|
29
|
-
declare type FlatListOption<T> = Assign<{
|
|
30
|
-
componentType: typeof FlatListComponentType;
|
|
31
|
-
}, FlatListProps<T>>;
|
|
32
|
-
declare type ScrollViewOption = Assign<{
|
|
33
|
-
componentType: typeof ScrollViewComponentType;
|
|
34
|
-
}, ScrollViewProps>;
|
|
35
|
-
declare type SectionListOption<T> = Assign<{
|
|
36
|
-
componentType: typeof SectionListComponentType;
|
|
37
|
-
}, SectionListProps<T>>;
|
|
38
|
-
declare type CommonProps = {
|
|
39
|
-
/**
|
|
40
|
-
* Array of numbers that indicate the different resting positions of the bottom sheet (in dp or %), starting from the top.
|
|
41
|
-
* If a percentage is used, that would translate to the relative amount of the total window height.
|
|
42
|
-
* For instance, if 50% is used, that'd be windowHeight * 0.5. If you wanna take into account safe areas during
|
|
43
|
-
* the calculation, such as status bars and notches, please use 'topInset' prop
|
|
44
|
-
*/
|
|
45
|
-
snapPoints: Array<string | number>;
|
|
46
|
-
/**
|
|
47
|
-
* Index that references the initial resting position of the drawer, starting from the top
|
|
48
|
-
*/
|
|
49
|
-
initialSnapIndex: number;
|
|
50
|
-
/**
|
|
51
|
-
* Render prop for the handle
|
|
52
|
-
*/
|
|
53
|
-
renderHandle: () => React.ReactNode;
|
|
54
|
-
/**
|
|
55
|
-
* Callback that is executed right after the drawer settles on one of the snapping points.
|
|
56
|
-
* The new index is provided on the callback
|
|
57
|
-
* @param index
|
|
58
|
-
*/
|
|
59
|
-
onSettle?: (index: number) => void;
|
|
60
|
-
/**
|
|
61
|
-
* Animated value that tracks the position of the drawer, being:
|
|
62
|
-
* 0 => closed
|
|
63
|
-
* 1 => fully opened
|
|
64
|
-
*/
|
|
65
|
-
animatedPosition?: Animated.Value<number>;
|
|
66
|
-
/**
|
|
67
|
-
* This value is useful if you want to take into consideration safe area insets
|
|
68
|
-
* when applying percentages for snapping points. We recommend using react-native-safe-area-context
|
|
69
|
-
* library for that.
|
|
70
|
-
* @see https://github.com/th3rdwave/react-native-safe-area-context#usage, insets.top
|
|
71
|
-
*/
|
|
72
|
-
topInset: number;
|
|
73
|
-
/**
|
|
74
|
-
* Reference to FlatList, ScrollView or SectionList in order to execute its imperative methods.
|
|
75
|
-
*/
|
|
76
|
-
innerRef: RefObject<FlatList | ScrollView | SectionList>;
|
|
77
|
-
containerStyle?: Animated.AnimateStyle<ViewStyle>;
|
|
78
|
-
friction: number;
|
|
79
|
-
enableOverScroll: boolean;
|
|
80
|
-
};
|
|
81
|
-
declare type TimingAnimationProps = {
|
|
82
|
-
animationType: typeof TimingAnimationType;
|
|
83
|
-
/**
|
|
84
|
-
* Configuration for the timing reanimated function
|
|
85
|
-
*/
|
|
86
|
-
animationConfig?: Partial<Animated.TimingConfig>;
|
|
87
|
-
};
|
|
88
|
-
declare type SpringAnimationProps = {
|
|
89
|
-
animationType: typeof SpringAnimationType;
|
|
90
|
-
/**
|
|
91
|
-
* Configuration for the spring reanimated function
|
|
92
|
-
*/
|
|
93
|
-
animationConfig?: Partial<Animated.SpringConfig>;
|
|
94
|
-
};
|
|
95
|
-
declare type Props<T> = CommonProps & (FlatListOption<T> | ScrollViewOption | SectionListOption<T>) & (TimingAnimationProps | SpringAnimationProps);
|
|
96
|
-
export declare class ScrollBottomSheet<T extends any> extends Component<Props<T>> {
|
|
97
|
-
static defaultProps: {
|
|
98
|
-
topInset: number;
|
|
99
|
-
friction: number;
|
|
100
|
-
animationType: string;
|
|
101
|
-
innerRef: React.RefObject<AnimatedScrollableComponent>;
|
|
102
|
-
enableOverScroll: boolean;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Gesture Handler references
|
|
106
|
-
*/
|
|
107
|
-
private masterDrawer;
|
|
108
|
-
private drawerHandleRef;
|
|
109
|
-
private drawerContentRef;
|
|
110
|
-
private scrollComponentRef;
|
|
111
|
-
/**
|
|
112
|
-
* ScrollView prop
|
|
113
|
-
*/
|
|
114
|
-
private onScrollBeginDrag;
|
|
115
|
-
/**
|
|
116
|
-
* Pan gesture handler events for drawer handle and content
|
|
117
|
-
*/
|
|
118
|
-
private onHandleGestureEvent;
|
|
119
|
-
private onDrawerGestureEvent;
|
|
120
|
-
/**
|
|
121
|
-
* Main Animated Value that drives the top position of the UI drawer at any point in time
|
|
122
|
-
*/
|
|
123
|
-
private translateY;
|
|
124
|
-
/**
|
|
125
|
-
* Animated value that keeps track of the position: 0 => closed, 1 => opened
|
|
126
|
-
*/
|
|
127
|
-
private position;
|
|
128
|
-
/**
|
|
129
|
-
* Flag to indicate imperative snapping
|
|
130
|
-
*/
|
|
131
|
-
private isManuallySetValue;
|
|
132
|
-
/**
|
|
133
|
-
* Manual snapping amount
|
|
134
|
-
*/
|
|
135
|
-
private manualYOffset;
|
|
136
|
-
/**
|
|
137
|
-
* Keeps track of the current index
|
|
138
|
-
*/
|
|
139
|
-
private nextSnapIndex;
|
|
140
|
-
/**
|
|
141
|
-
* Deceleration rate of the scroll component. This is used only on Android to
|
|
142
|
-
* compensate the unexpected glide it gets sometimes.
|
|
143
|
-
*/
|
|
144
|
-
private decelerationRate;
|
|
145
|
-
private prevSnapIndex;
|
|
146
|
-
private dragY;
|
|
147
|
-
private prevDragY;
|
|
148
|
-
private tempDestSnapPoint;
|
|
149
|
-
private isAndroid;
|
|
150
|
-
private animationClock;
|
|
151
|
-
private animationPosition;
|
|
152
|
-
private animationFinished;
|
|
153
|
-
private animationFrameTime;
|
|
154
|
-
private velocityY;
|
|
155
|
-
private lastStartScrollY;
|
|
156
|
-
private prevTranslateYOffset;
|
|
157
|
-
private translationY;
|
|
158
|
-
private destSnapPoint;
|
|
159
|
-
private lastSnap;
|
|
160
|
-
private dragWithHandle;
|
|
161
|
-
private scrollUpAndPullDown;
|
|
162
|
-
private didGestureFinish;
|
|
163
|
-
private didScrollUpAndPullDown;
|
|
164
|
-
private setTranslationY;
|
|
165
|
-
private extraOffset;
|
|
166
|
-
private calculateNextSnapPoint;
|
|
167
|
-
private scrollComponent;
|
|
168
|
-
convertPercentageToDp: (str: string) => number;
|
|
169
|
-
constructor(props: Props<T>);
|
|
170
|
-
private getNormalisedSnapPoints;
|
|
171
|
-
private getScrollComponent;
|
|
172
|
-
snapTo: (index: number) => void;
|
|
173
|
-
render(): React.JSX.Element;
|
|
174
|
-
}
|
|
175
|
-
export default ScrollBottomSheet;
|