@metamask-previews/design-system-react-native 0.30.2-preview.688b428f → 0.30.2-preview.9bd8bc3
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/dist/components/BannerAlert/BannerAlert.cjs +2 -5
- package/dist/components/BannerAlert/BannerAlert.cjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.cjs +4 -7
- package/dist/components/BannerAlert/BannerAlert.constants.cjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.d.cts +1 -2
- package/dist/components/BannerAlert/BannerAlert.constants.d.cts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.d.mts +1 -2
- package/dist/components/BannerAlert/BannerAlert.constants.d.mts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.constants.mjs +4 -7
- package/dist/components/BannerAlert/BannerAlert.constants.mjs.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.d.cts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.d.mts.map +1 -1
- package/dist/components/BannerAlert/BannerAlert.mjs +3 -6
- package/dist/components/BannerAlert/BannerAlert.mjs.map +1 -1
- package/dist/components/BannerBase/BannerBase.cjs +5 -8
- package/dist/components/BannerBase/BannerBase.cjs.map +1 -1
- package/dist/components/BannerBase/BannerBase.d.cts.map +1 -1
- package/dist/components/BannerBase/BannerBase.d.mts.map +1 -1
- package/dist/components/BannerBase/BannerBase.mjs +6 -9
- package/dist/components/BannerBase/BannerBase.mjs.map +1 -1
- package/dist/components/BottomSheet/BottomSheet.cjs +12 -7
- package/dist/components/BottomSheet/BottomSheet.cjs.map +1 -1
- package/dist/components/BottomSheet/BottomSheet.d.cts +1 -0
- package/dist/components/BottomSheet/BottomSheet.d.cts.map +1 -1
- package/dist/components/BottomSheet/BottomSheet.d.mts +1 -0
- package/dist/components/BottomSheet/BottomSheet.d.mts.map +1 -1
- package/dist/components/BottomSheet/BottomSheet.mjs +12 -7
- package/dist/components/BottomSheet/BottomSheet.mjs.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.cjs +20 -21
- package/dist/components/BottomSheetDialog/BottomSheetDialog.cjs.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.constants.cjs +16 -9
- package/dist/components/BottomSheetDialog/BottomSheetDialog.constants.cjs.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.constants.d.cts +14 -7
- package/dist/components/BottomSheetDialog/BottomSheetDialog.constants.d.cts.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.constants.d.mts +14 -7
- package/dist/components/BottomSheetDialog/BottomSheetDialog.constants.d.mts.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.constants.mjs +14 -8
- package/dist/components/BottomSheetDialog/BottomSheetDialog.constants.mjs.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.d.cts +1 -0
- package/dist/components/BottomSheetDialog/BottomSheetDialog.d.cts.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.d.mts +1 -0
- package/dist/components/BottomSheetDialog/BottomSheetDialog.d.mts.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.mjs +24 -25
- package/dist/components/BottomSheetDialog/BottomSheetDialog.mjs.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.types.cjs.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.types.d.cts +4 -0
- package/dist/components/BottomSheetDialog/BottomSheetDialog.types.d.cts.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.types.d.mts +4 -0
- package/dist/components/BottomSheetDialog/BottomSheetDialog.types.d.mts.map +1 -1
- package/dist/components/BottomSheetDialog/BottomSheetDialog.types.mjs.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.cjs +21 -5
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.cjs.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.constants.cjs +5 -3
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.constants.cjs.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.constants.d.cts +3 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.constants.d.cts.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.constants.d.mts +3 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.constants.d.mts.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.constants.mjs +4 -2
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.constants.mjs.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.d.cts +6 -2
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.d.cts.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.d.mts +6 -2
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.d.mts.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.mjs +24 -7
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.mjs.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.types.cjs.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.types.d.cts +13 -0
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.types.d.cts.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.types.d.mts +13 -0
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.types.d.mts.map +1 -1
- package/dist/components/BottomSheetOverlay/BottomSheetOverlay.types.mjs.map +1 -1
- package/dist/components/BottomSheetOverlay/index.cjs.map +1 -1
- package/dist/components/BottomSheetOverlay/index.d.cts +1 -1
- package/dist/components/BottomSheetOverlay/index.d.cts.map +1 -1
- package/dist/components/BottomSheetOverlay/index.d.mts +1 -1
- package/dist/components/BottomSheetOverlay/index.d.mts.map +1 -1
- package/dist/components/BottomSheetOverlay/index.mjs.map +1 -1
- package/dist/components/Tag/Tag.constants.cjs +2 -2
- package/dist/components/Tag/Tag.constants.cjs.map +1 -1
- package/dist/components/Tag/Tag.constants.mjs +2 -2
- package/dist/components/Tag/Tag.constants.mjs.map +1 -1
- package/dist/components/TitleAlert/TitleAlert.cjs +3 -5
- package/dist/components/TitleAlert/TitleAlert.cjs.map +1 -1
- package/dist/components/TitleAlert/TitleAlert.d.cts +1 -3
- package/dist/components/TitleAlert/TitleAlert.d.cts.map +1 -1
- package/dist/components/TitleAlert/TitleAlert.d.mts +1 -3
- package/dist/components/TitleAlert/TitleAlert.d.mts.map +1 -1
- package/dist/components/TitleAlert/TitleAlert.mjs +3 -5
- package/dist/components/TitleAlert/TitleAlert.mjs.map +1 -1
- package/dist/components/TitleAlert/TitleAlert.types.cjs.map +1 -1
- package/dist/components/TitleAlert/TitleAlert.types.d.cts +2 -2
- package/dist/components/TitleAlert/TitleAlert.types.d.mts +2 -2
- package/dist/components/TitleAlert/TitleAlert.types.mjs.map +1 -1
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +1 -1
- package/dist/components/index.d.cts.map +1 -1
- package/dist/components/index.d.mts +1 -1
- package/dist/components/index.d.mts.map +1 -1
- package/dist/components/index.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.mjs","sourceRoot":"","sources":["../../../src/components/BottomSheet/BottomSheet.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,sDAAsD;AAC5E,OAAO,QAAO,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,MAAM,EACP,cAAc;;AACf,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,QAAQ,EAAE,qBAAqB;AAC3E,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAClB,uCAAuC;AAExC,OAAO,EAAE,iBAAiB,EAAE,uCAA6B;AAEzD,OAAO,EAAE,kBAAkB,EAAE,qDAAiD;
|
|
1
|
+
{"version":3,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AAS,CAAC,CACxD,sBAAsB,CAAC,CACrB,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,CACtD,CACD,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,8BAA8B,CAAC,EAAE,KAAK,CAAC,CAAC,CACzD,OAAO,CAAC,CAAC,2BAA2B,CAAC,CACrC,IAAI,KAAK,CAAC,CAEV;QAAA,CAAC,kBAAkB,CACjB,GAAG,CAAC,CAAC,qBAAqB,CAAC,CAC3B,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,EAE7D;QAAA,CAAC,iBAAiB,CAChB,cAAc,CAAC,CAAC,cAAc,CAAC,CAC/B,cAAc,CAAC,CAAC,cAAc,CAAC,CAC/B,OAAO,CAAC,CAAC,SAAS,CAAC,CACnB,MAAM,CAAC,CAAC,QAAQ,CAAC,CACjB,GAAG,CAAC,CAAC,oBAAoB,CAAC,CAC1B,YAAY,CAAC,CAAC,YAAY,CAAC,CAC3B,WAAW,CAAC,CAAC,WAAW,CAAC,CACzB,2BAA2B,CAAC,CAAC,2BAA2B,CAAC,CAEzD;UAAA,CAAC,QAAQ,CACX;QAAA,EAAE,iBAAiB,CACrB;MAAA,EAAE,oBAAoB,CAAC,CACxB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,WAAW,CAAC,WAAW,GAAG,aAAa,CAAC","sourcesContent":["import { useTailwind } from '@metamask-previews/design-system-twrnc-preset';\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n} from 'react';\nimport { BackHandler, KeyboardAvoidingView, Platform } from 'react-native';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\n\nimport { BottomSheetDialog } from '../BottomSheetDialog';\nimport type { BottomSheetDialogRef } from '../BottomSheetDialog';\nimport { BottomSheetOverlay } from '../BottomSheetOverlay/BottomSheetOverlay';\nimport type { BottomSheetOverlayRef } from '../BottomSheetOverlay/BottomSheetOverlay.types';\n\nimport type {\n BottomSheetPostCallback,\n BottomSheetProps,\n BottomSheetRef,\n} from './BottomSheet.types';\n\nexport const BottomSheet = forwardRef<BottomSheetRef, BottomSheetProps>(\n (\n {\n children,\n onClose,\n onOpen,\n goBack,\n style,\n twClassName,\n isInteractable = true,\n isFullscreen = false,\n keyboardAvoidingViewEnabled = true,\n ...props\n },\n ref,\n ) => {\n const tw = useTailwind();\n const { bottom: screenBottomPadding } = useSafeAreaInsets();\n const { y: frameY } = useSafeAreaFrame();\n const postCallback = useRef<BottomSheetPostCallback | undefined>(undefined);\n const bottomSheetDialogRef = useRef<BottomSheetDialogRef>(null);\n const bottomSheetOverlayRef = useRef<BottomSheetOverlayRef>(null);\n const didNavigateBackRef = useRef(false);\n const closeRequestedRef = useRef(false);\n const didRunPostCallbackRef = useRef(false);\n\n const onOpenCB = useCallback(() => {\n // Reset when the sheet is opened again.\n didNavigateBackRef.current = false;\n closeRequestedRef.current = false;\n didRunPostCallbackRef.current = false;\n\n onOpen?.(Boolean(postCallback.current));\n const callback = postCallback.current;\n postCallback.current = undefined;\n callback?.();\n }, [onOpen]);\n\n const onCloseCB = useCallback(() => {\n if (goBack && !didNavigateBackRef.current) {\n didNavigateBackRef.current = true;\n goBack?.();\n }\n\n const callback = postCallback.current;\n const hasCallback = Boolean(callback);\n\n onClose?.(hasCallback);\n\n if (!didRunPostCallbackRef.current && hasCallback) {\n didRunPostCallbackRef.current = true;\n postCallback.current = undefined;\n callback?.();\n }\n }, [goBack, onClose]);\n\n const onDismissStart = useCallback(() => {\n bottomSheetOverlayRef.current?.fadeOut();\n }, []);\n\n const dismissSheet = useCallback((callback?: () => void) => {\n bottomSheetDialogRef.current?.onCloseDialog(callback);\n }, []);\n\n // Dismiss the sheet when Android back button is pressed.\n useEffect(() => {\n if (Platform.OS !== 'android') {\n return undefined;\n }\n\n const hardwareBackPress = () => {\n if (isInteractable) {\n dismissSheet();\n }\n return true;\n };\n const subscription = BackHandler.addEventListener(\n 'hardwareBackPress',\n hardwareBackPress,\n );\n return () => {\n subscription.remove();\n };\n }, [dismissSheet, isInteractable]);\n\n useImperativeHandle(ref, () => ({\n onCloseBottomSheet: (callback) => {\n if (closeRequestedRef.current) {\n return;\n }\n closeRequestedRef.current = true;\n postCallback.current = callback;\n dismissSheet();\n },\n onOpenBottomSheet: (callback) => {\n didNavigateBackRef.current = false;\n closeRequestedRef.current = false;\n didRunPostCallbackRef.current = false;\n postCallback.current = callback;\n bottomSheetDialogRef.current?.onOpenDialog();\n },\n }));\n\n return (\n <KeyboardAvoidingView\n behavior={Platform.OS === 'ios' ? 'padding' : undefined}\n keyboardVerticalOffset={\n Platform.OS === 'ios' ? -screenBottomPadding : frameY\n }\n style={[tw.style('absolute inset-0 justify-end'), style]}\n enabled={keyboardAvoidingViewEnabled}\n {...props}\n >\n <BottomSheetOverlay\n ref={bottomSheetOverlayRef}\n onPress={isInteractable ? () => dismissSheet() : undefined}\n />\n <BottomSheetDialog\n isInteractable={isInteractable}\n onDismissStart={onDismissStart}\n onClose={onCloseCB}\n onOpen={onOpenCB}\n ref={bottomSheetDialogRef}\n isFullscreen={isFullscreen}\n twClassName={twClassName}\n keyboardAvoidingViewEnabled={keyboardAvoidingViewEnabled}\n >\n {children}\n </BottomSheetDialog>\n </KeyboardAvoidingView>\n );\n },\n);\n\nBottomSheet.displayName = 'BottomSheet';\n"]}
|
|
@@ -34,13 +34,12 @@ const react_native_reanimated_1 = __importStar(require("react-native-reanimated"
|
|
|
34
34
|
const react_native_safe_area_context_1 = require("react-native-safe-area-context");
|
|
35
35
|
// Internal dependencies.
|
|
36
36
|
const BottomSheetDialog_constants_1 = require("./BottomSheetDialog.constants.cjs");
|
|
37
|
-
exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen = false, isInteractable = true, keyboardAvoidingViewEnabled = true, onClose, onOpen, style, twClassName, ...props }, ref) => {
|
|
37
|
+
exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen = false, isInteractable = true, keyboardAvoidingViewEnabled = true, onDismissStart, onClose, onOpen, style, twClassName, ...props }, ref) => {
|
|
38
38
|
const tw = (0, design_system_twrnc_preset_1.useTailwind)();
|
|
39
39
|
const currentTheme = (0, design_system_twrnc_preset_1.useTheme)();
|
|
40
|
-
const isPureBlack = (0, design_system_twrnc_preset_1.usePureBlack)();
|
|
41
40
|
const shadowLg = currentTheme === design_system_twrnc_preset_1.Theme.Light
|
|
42
41
|
? design_tokens_1.lightTheme.shadows.size.lg
|
|
43
|
-
:
|
|
42
|
+
: design_tokens_1.darkTheme.shadows.size.lg;
|
|
44
43
|
const { top: screenTopPadding, bottom: screenBottomPadding } = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
|
|
45
44
|
const { y: frameY, height: screenHeight } = (0, react_native_safe_area_context_1.useSafeAreaFrame)();
|
|
46
45
|
const maxSheetHeight = screenHeight - screenTopPadding;
|
|
@@ -57,15 +56,23 @@ exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen =
|
|
|
57
56
|
const onCloseCB = (0, react_1.useCallback)(() => {
|
|
58
57
|
onClose?.();
|
|
59
58
|
}, [onClose]);
|
|
59
|
+
const animateSheetTo = (target, onComplete) => {
|
|
60
|
+
currentYOffset.value = (0, react_native_reanimated_1.withSpring)(target, (0, BottomSheetDialog_constants_1.getBottomSheetDialogSpringConfig)(), (finished) => {
|
|
61
|
+
if (finished && onComplete) {
|
|
62
|
+
(0, react_native_reanimated_1.runOnJS)(onComplete)();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
60
66
|
const onCloseDialog = (0, react_1.useCallback)((callback) => {
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
onDismissStart?.();
|
|
68
|
+
animateSheetTo(bottomOfDialogYValue.value, () => {
|
|
69
|
+
onCloseCB();
|
|
63
70
|
if (callback) {
|
|
64
|
-
|
|
71
|
+
callback();
|
|
65
72
|
}
|
|
66
73
|
});
|
|
67
74
|
// Ref values do not affect deps.
|
|
68
|
-
}, [onCloseCB]);
|
|
75
|
+
}, [onCloseCB, onDismissStart]);
|
|
69
76
|
const gestureHandler = (0, react_1.useMemo)(() => {
|
|
70
77
|
// These gesture callbacks need explicit 'worklet' directives because this
|
|
71
78
|
// package ships a pre-built dist compiled by ts-bridge (tsc), which emits the
|
|
@@ -112,7 +119,7 @@ exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen =
|
|
|
112
119
|
BottomSheetDialog_constants_1.DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD;
|
|
113
120
|
// Check if the gesture's vertical speed has reached the threshold to determine a swipe action
|
|
114
121
|
const hasReachedSwipeThreshold = Math.abs(velocityY) >
|
|
115
|
-
BottomSheetDialog_constants_1.
|
|
122
|
+
BottomSheetDialog_constants_1.DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY;
|
|
116
123
|
const isQuickDismissing = velocityY > 0;
|
|
117
124
|
// If user is swiping
|
|
118
125
|
if (hasReachedSwipeThreshold) {
|
|
@@ -135,10 +142,7 @@ exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen =
|
|
|
135
142
|
(0, react_native_reanimated_1.runOnJS)(onCloseDialog)();
|
|
136
143
|
}
|
|
137
144
|
else {
|
|
138
|
-
|
|
139
|
-
currentYOffset.value = (0, react_native_reanimated_1.withTiming)(finalYOffset, {
|
|
140
|
-
duration: BottomSheetDialog_constants_1.DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,
|
|
141
|
-
});
|
|
145
|
+
currentYOffset.value = (0, react_native_reanimated_1.withSpring)(finalYOffset, (0, BottomSheetDialog_constants_1.getBottomSheetDialogSpringConfig)({ velocity: velocityY }));
|
|
142
146
|
}
|
|
143
147
|
});
|
|
144
148
|
return gesture;
|
|
@@ -152,15 +156,11 @@ exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen =
|
|
|
152
156
|
]);
|
|
153
157
|
// Animate in sheet on initial render.
|
|
154
158
|
const onOpenDialog = (callback) => {
|
|
155
|
-
// Starts setting the Y position of the dialog to the bottom of the dialog
|
|
156
159
|
currentYOffset.value = bottomOfDialogYValue.value;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
duration: BottomSheetDialog_constants_1.DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,
|
|
160
|
-
}, () => {
|
|
161
|
-
(0, react_native_reanimated_1.runOnJS)(onOpenCB)();
|
|
160
|
+
animateSheetTo(topOfDialogYValue.value, () => {
|
|
161
|
+
onOpenCB();
|
|
162
162
|
if (callback) {
|
|
163
|
-
|
|
163
|
+
callback();
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
};
|
|
@@ -188,7 +188,7 @@ exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen =
|
|
|
188
188
|
],
|
|
189
189
|
}), []);
|
|
190
190
|
const sheetStyle = (0, react_1.useMemo)(() => [
|
|
191
|
-
tw.style(
|
|
191
|
+
tw.style('bg-default rounded-t-3xl overflow-hidden border border-muted', twClassName),
|
|
192
192
|
{
|
|
193
193
|
maxHeight: maxSheetHeight,
|
|
194
194
|
paddingBottom: react_native_1.Platform.select({
|
|
@@ -202,7 +202,6 @@ exports.BottomSheetDialog = (0, react_1.forwardRef)(({ children, isFullscreen =
|
|
|
202
202
|
style,
|
|
203
203
|
], [
|
|
204
204
|
tw,
|
|
205
|
-
isPureBlack,
|
|
206
205
|
maxSheetHeight,
|
|
207
206
|
screenBottomPadding,
|
|
208
207
|
isFullscreen,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetDialog.cjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8FAKu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AEzC,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,IAAA,2BAAmB,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9B,YAAY;QACZ,aAAa;KACd,CAAC,CAAC,CAAC;IAEJ,OAAO,CACL,CAAC,mCAAoB,CACnB,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAC/C,QAAQ,CAAC,CAAC,uBAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CACxD,sBAAsB,CAAC,CACrB,uBAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,CACtD,CACD,OAAO,CAAC,CAAC,2BAA2B,CAAC,CACrC,IAAI,KAAK,CAAC,CAEV;QAAA,CAAC,8CAAe,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,CACvC;UAAA,CAAC,iCAAQ,CAAC,IAAI,CACZ,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAC5B,KAAK,CAAC,CAAC,kBAAkB,CAAC,CAE1B;YAAA,CAAC,cAAc,IAAI,CACjB,CAAC,mBAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CACrD;gBAAA,CAAC,mBAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC,EAC/D;cAAA,EAAE,mBAAI,CAAC,CACR,CACD;YAAA,CAAC,QAAQ,CACX;UAAA,EAAE,iCAAQ,CAAC,IAAI,CACjB;QAAA,EAAE,8CAAe,CACnB;MAAA,EAAE,mCAAoB,CAAC,CACxB,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import {\n Theme,\n usePureBlack,\n useTailwind,\n useTheme,\n} from '@metamask-previews/design-system-twrnc-preset';\nimport { lightTheme, resolveDarkTheme } from '@metamask-previews/design-tokens';\nimport { debounce } from 'lodash';\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useImperativeHandle,\n} from 'react';\nimport {\n LayoutChangeEvent,\n View,\n Platform,\n KeyboardAvoidingView,\n} from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\n\n// Internal dependencies.\nimport {\n DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD,\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION,\n} from './BottomSheetDialog.constants';\nimport type {\n BottomSheetDialogRef,\n BottomSheetDialogProps,\n} from './BottomSheetDialog.types';\n\nexport const BottomSheetDialog = forwardRef<\n BottomSheetDialogRef,\n BottomSheetDialogProps\n>(\n (\n {\n children,\n isFullscreen = false,\n isInteractable = true,\n keyboardAvoidingViewEnabled = true,\n onClose,\n onOpen,\n style,\n twClassName,\n ...props\n },\n ref,\n ) => {\n const tw = useTailwind();\n const currentTheme = useTheme();\n const isPureBlack = usePureBlack();\n const shadowLg =\n currentTheme === Theme.Light\n ? lightTheme.shadows.size.lg\n : resolveDarkTheme(isPureBlack).shadows.size.lg;\n\n const { top: screenTopPadding, bottom: screenBottomPadding } =\n useSafeAreaInsets();\n const { y: frameY, height: screenHeight } = useSafeAreaFrame();\n\n const maxSheetHeight = screenHeight - screenTopPadding;\n // X and Y values start on top left of the DIALOG\n // currentYOffset will be used to animate the Y position of the Dialog\n const currentYOffset = useSharedValue(screenHeight);\n const topOfDialogYValue = useSharedValue(0);\n const bottomOfDialogYValue = useSharedValue(screenHeight);\n const gestureStartYOffset = useSharedValue(0);\n const isMounted = useRef(false);\n\n const onOpenCB = useCallback(() => {\n onOpen?.();\n }, [onOpen]);\n const onCloseCB = useCallback(() => {\n onClose?.();\n }, [onClose]);\n\n const onCloseDialog = useCallback(\n (callback?: () => void) => {\n currentYOffset.value = withTiming(\n bottomOfDialogYValue.value,\n { duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION },\n () => {\n runOnJS(onCloseCB)();\n if (callback) {\n runOnJS(callback)();\n }\n },\n );\n // Ref values do not affect deps.\n },\n [onCloseCB],\n );\n\n const gestureHandler = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist (that's\n // why useAnimatedStyle below works), but its gesture auto-detection doesn't\n // recognize that compiled namespaced form, so without these directives the\n // callbacks run on the JS thread and slow drags lag behind the finger.\n const gesture = Gesture.Pan()\n .enabled(isInteractable)\n .onStart(() => {\n 'worklet';\n\n // Starts tracking vertical position of gesture.\n gestureStartYOffset.value = currentYOffset.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n const { translationY } = event;\n currentYOffset.value = gestureStartYOffset.value + translationY;\n // If gesture Y value goes above the bottom of Dialog Y value(bottom of dialog),\n // which means the gesture is currently below the bottom of the dialog,\n // sets it to bottom of Dialog Y value\n if (currentYOffset.value >= bottomOfDialogYValue.value) {\n currentYOffset.value = bottomOfDialogYValue.value;\n }\n // If gesture Y value goes below the top of Dialog Y value(top of dialog),\n // which means the gesture is currently above the top of the dialog,\n // sets it to top of Dialog Y value\n if (currentYOffset.value <= topOfDialogYValue.value) {\n currentYOffset.value = topOfDialogYValue.value;\n }\n })\n .onEnd((event) => {\n 'worklet';\n\n const { translationY, velocityY } = event;\n // finalYOffset is used to animate the Y position of the Dialog after the gesture event\n let finalYOffset: number;\n // Measuring dismissing swipe action\n const latestOffset = gestureStartYOffset.value + translationY;\n // Check if the swipe distance reach the dismiss offset threshold,\n // which is currently 60% of sheet height\n const hasReachedDismissOffset =\n latestOffset >\n bottomOfDialogYValue.value *\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD;\n // Check if the gesture's vertical speed has reached the threshold to determine a swipe action\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) >\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION;\n const isQuickDismissing = velocityY > 0;\n\n // If user is swiping\n if (hasReachedSwipeThreshold) {\n // Quick swipe takes priority\n if (isQuickDismissing) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n } else if (hasReachedDismissOffset) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n\n const isDismissed = finalYOffset === bottomOfDialogYValue.value;\n\n if (isDismissed) {\n runOnJS(onCloseDialog)();\n } else {\n // Only animate dialog to a certain Y position instead\n currentYOffset.value = withTiming(finalYOffset, {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n });\n }\n });\n\n return gesture;\n }, [\n isInteractable,\n currentYOffset,\n gestureStartYOffset,\n bottomOfDialogYValue,\n topOfDialogYValue,\n onCloseDialog,\n ]);\n\n // Animate in sheet on initial render.\n const onOpenDialog = (callback?: () => void) => {\n // Starts setting the Y position of the dialog to the bottom of the dialog\n currentYOffset.value = bottomOfDialogYValue.value;\n // Animate the Y position to the top of the dialog, then call onOpenCB\n currentYOffset.value = withTiming(\n topOfDialogYValue.value,\n {\n duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,\n },\n () => {\n runOnJS(onOpenCB)();\n if (callback) {\n runOnJS(callback)();\n }\n },\n );\n };\n\n const onDebouncedCloseDialog = useMemo(\n // Prevent hide from being called multiple times. Potentially caused by taps in quick succession.\n () => debounce(onCloseDialog, 2000, { leading: true }),\n [onCloseDialog],\n );\n\n useEffect(\n () =>\n // Automatically handles animation when content changes\n // Disable for now since network switches causes the screen to hang with this on.\n // LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);\n onDebouncedCloseDialog.cancel(),\n [children, onDebouncedCloseDialog],\n );\n\n const updateSheetHeight = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n bottomOfDialogYValue.value = height;\n\n if (!isMounted.current) {\n isMounted.current = true;\n onOpenDialog();\n }\n };\n\n const animatedSheetStyle = useAnimatedStyle(\n () => ({\n transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }),\n [],\n );\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n isPureBlack ? 'bg-alternative' : 'bg-default',\n 'rounded-t-3xl overflow-hidden border border-muted',\n twClassName,\n ),\n {\n maxHeight: maxSheetHeight,\n paddingBottom: Platform.select({\n ios: screenBottomPadding,\n macos: screenBottomPadding,\n default: screenBottomPadding + 16,\n }),\n ...(isFullscreen && { height: maxSheetHeight }),\n ...shadowLg,\n },\n style,\n ],\n\n [\n tw,\n isPureBlack,\n maxSheetHeight,\n screenBottomPadding,\n isFullscreen,\n shadowLg,\n style,\n twClassName,\n ],\n );\n\n const combinedSheetStyle = useMemo(\n () => [...sheetStyle, animatedSheetStyle],\n\n [sheetStyle],\n );\n\n useImperativeHandle(ref, () => ({\n onOpenDialog,\n onCloseDialog,\n }));\n\n return (\n <KeyboardAvoidingView\n style={tw.style('absolute bottom-0 inset-x-0')}\n behavior={Platform.OS === 'ios' ? 'padding' : undefined}\n keyboardVerticalOffset={\n Platform.OS === 'ios' ? -screenBottomPadding : frameY\n }\n enabled={keyboardAvoidingViewEnabled}\n {...props}\n >\n <GestureDetector gesture={gestureHandler}>\n <Animated.View\n onLayout={updateSheetHeight}\n style={combinedSheetStyle}\n >\n {isInteractable && (\n <View style={tw.style('self-stretch items-center p-1')}>\n <View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')} />\n </View>\n )}\n {children}\n </Animated.View>\n </GestureDetector>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
|
|
1
|
+
{"version":3,"file":"BottomSheetDialog.cjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8FAIuD;AACvD,oEAAyE;AACzE,mCAAkC;AAClC,+CAOe;AACf,+CAKsB;AACtB,+EAAwE;AACxE,mFAKiC;AACjC,mFAGwC;AAExC,yBAAyB;AACzB,mFAIuC;AAM1B,QAAA,iBAAiB,GAAG,IAAA,kBAAU,EAIzC,CACE,EACE,QAAQ,EACR,YAAY,GAAG,KAAK,EACpB,cAAc,GAAG,IAAI,EACrB,2BAA2B,GAAG,IAAI,EAClC,cAAc,EACd,OAAO,EACP,MAAM,EACN,KAAK,EACL,WAAW,EACX,GAAG,KAAK,EACT,EACD,GAAG,EACH,EAAE;IACF,MAAM,EAAE,GAAG,IAAA,wCAAW,GAAE,CAAC;IACzB,MAAM,YAAY,GAAG,IAAA,qCAAQ,GAAE,CAAC;IAChC,MAAM,QAAQ,GACZ,YAAY,KAAK,kCAAK,CAAC,KAAK;QAC1B,CAAC,CAAC,0BAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC5B,CAAC,CAAC,yBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;IAEhC,MAAM,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAC1D,IAAA,kDAAiB,GAAE,CAAC;IACtB,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,iDAAgB,GAAE,CAAC;IAE/D,MAAM,cAAc,GAAG,YAAY,GAAG,gBAAgB,CAAC;IACvD,iDAAiD;IACjD,sEAAsE;IACtE,MAAM,cAAc,GAAG,IAAA,wCAAc,EAAC,YAAY,CAAC,CAAC;IACpD,MAAM,iBAAiB,GAAG,IAAA,wCAAc,EAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,oBAAoB,GAAG,I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Theme,\n useTailwind,\n useTheme,\n} from '@metamask-previews/design-system-twrnc-preset';\nimport { lightTheme, darkTheme } from '@metamask-previews/design-tokens';\nimport { debounce } from 'lodash';\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useImperativeHandle,\n} from 'react';\nimport {\n LayoutChangeEvent,\n View,\n Platform,\n KeyboardAvoidingView,\n} from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\n\n// Internal dependencies.\nimport {\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD,\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY,\n getBottomSheetDialogSpringConfig,\n} from './BottomSheetDialog.constants';\nimport type {\n BottomSheetDialogRef,\n BottomSheetDialogProps,\n} from './BottomSheetDialog.types';\n\nexport const BottomSheetDialog = forwardRef<\n BottomSheetDialogRef,\n BottomSheetDialogProps\n>(\n (\n {\n children,\n isFullscreen = false,\n isInteractable = true,\n keyboardAvoidingViewEnabled = true,\n onDismissStart,\n onClose,\n onOpen,\n style,\n twClassName,\n ...props\n },\n ref,\n ) => {\n const tw = useTailwind();\n const currentTheme = useTheme();\n const shadowLg =\n currentTheme === Theme.Light\n ? lightTheme.shadows.size.lg\n : darkTheme.shadows.size.lg;\n\n const { top: screenTopPadding, bottom: screenBottomPadding } =\n useSafeAreaInsets();\n const { y: frameY, height: screenHeight } = useSafeAreaFrame();\n\n const maxSheetHeight = screenHeight - screenTopPadding;\n // X and Y values start on top left of the DIALOG\n // currentYOffset will be used to animate the Y position of the Dialog\n const currentYOffset = useSharedValue(screenHeight);\n const topOfDialogYValue = useSharedValue(0);\n const bottomOfDialogYValue = useSharedValue(screenHeight);\n const gestureStartYOffset = useSharedValue(0);\n const isMounted = useRef(false);\n\n const onOpenCB = useCallback(() => {\n onOpen?.();\n }, [onOpen]);\n const onCloseCB = useCallback(() => {\n onClose?.();\n }, [onClose]);\n\n const animateSheetTo = (target: number, onComplete?: () => void) => {\n currentYOffset.value = withSpring(\n target,\n getBottomSheetDialogSpringConfig(),\n (finished) => {\n if (finished && onComplete) {\n runOnJS(onComplete)();\n }\n },\n );\n };\n\n const onCloseDialog = useCallback(\n (callback?: () => void) => {\n onDismissStart?.();\n animateSheetTo(bottomOfDialogYValue.value, () => {\n onCloseCB();\n if (callback) {\n callback();\n }\n });\n // Ref values do not affect deps.\n },\n [onCloseCB, onDismissStart],\n );\n\n const gestureHandler = useMemo(() => {\n // These gesture callbacks need explicit 'worklet' directives because this\n // package ships a pre-built dist compiled by ts-bridge (tsc), which emits the\n // gesture chain as a namespaced call (react_native_gesture_handler_1.Gesture).\n // The consumer's Reanimated/Worklets Babel plugin does run over dist (that's\n // why useAnimatedStyle below works), but its gesture auto-detection doesn't\n // recognize that compiled namespaced form, so without these directives the\n // callbacks run on the JS thread and slow drags lag behind the finger.\n const gesture = Gesture.Pan()\n .enabled(isInteractable)\n .onStart(() => {\n 'worklet';\n\n // Starts tracking vertical position of gesture.\n gestureStartYOffset.value = currentYOffset.value;\n })\n .onUpdate((event) => {\n 'worklet';\n\n const { translationY } = event;\n currentYOffset.value = gestureStartYOffset.value + translationY;\n // If gesture Y value goes above the bottom of Dialog Y value(bottom of dialog),\n // which means the gesture is currently below the bottom of the dialog,\n // sets it to bottom of Dialog Y value\n if (currentYOffset.value >= bottomOfDialogYValue.value) {\n currentYOffset.value = bottomOfDialogYValue.value;\n }\n // If gesture Y value goes below the top of Dialog Y value(top of dialog),\n // which means the gesture is currently above the top of the dialog,\n // sets it to top of Dialog Y value\n if (currentYOffset.value <= topOfDialogYValue.value) {\n currentYOffset.value = topOfDialogYValue.value;\n }\n })\n .onEnd((event) => {\n 'worklet';\n\n const { translationY, velocityY } = event;\n // finalYOffset is used to animate the Y position of the Dialog after the gesture event\n let finalYOffset: number;\n // Measuring dismissing swipe action\n const latestOffset = gestureStartYOffset.value + translationY;\n // Check if the swipe distance reach the dismiss offset threshold,\n // which is currently 60% of sheet height\n const hasReachedDismissOffset =\n latestOffset >\n bottomOfDialogYValue.value *\n DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD;\n // Check if the gesture's vertical speed has reached the threshold to determine a swipe action\n const hasReachedSwipeThreshold =\n Math.abs(velocityY) >\n DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY;\n const isQuickDismissing = velocityY > 0;\n\n // If user is swiping\n if (hasReachedSwipeThreshold) {\n // Quick swipe takes priority\n if (isQuickDismissing) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n } else if (hasReachedDismissOffset) {\n finalYOffset = bottomOfDialogYValue.value;\n } else {\n finalYOffset = topOfDialogYValue.value;\n }\n\n const isDismissed = finalYOffset === bottomOfDialogYValue.value;\n\n if (isDismissed) {\n runOnJS(onCloseDialog)();\n } else {\n currentYOffset.value = withSpring(\n finalYOffset,\n getBottomSheetDialogSpringConfig({ velocity: velocityY }),\n );\n }\n });\n\n return gesture;\n }, [\n isInteractable,\n currentYOffset,\n gestureStartYOffset,\n bottomOfDialogYValue,\n topOfDialogYValue,\n onCloseDialog,\n ]);\n\n // Animate in sheet on initial render.\n const onOpenDialog = (callback?: () => void) => {\n currentYOffset.value = bottomOfDialogYValue.value;\n animateSheetTo(topOfDialogYValue.value, () => {\n onOpenCB();\n if (callback) {\n callback();\n }\n });\n };\n\n const onDebouncedCloseDialog = useMemo(\n // Prevent hide from being called multiple times. Potentially caused by taps in quick succession.\n () => debounce(onCloseDialog, 2000, { leading: true }),\n [onCloseDialog],\n );\n\n useEffect(\n () =>\n // Automatically handles animation when content changes\n // Disable for now since network switches causes the screen to hang with this on.\n // LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);\n onDebouncedCloseDialog.cancel(),\n [children, onDebouncedCloseDialog],\n );\n\n const updateSheetHeight = (e: LayoutChangeEvent) => {\n const { height } = e.nativeEvent.layout;\n bottomOfDialogYValue.value = height;\n\n if (!isMounted.current) {\n isMounted.current = true;\n onOpenDialog();\n }\n };\n\n const animatedSheetStyle = useAnimatedStyle(\n () => ({\n transform: [\n {\n translateY: currentYOffset.value,\n },\n ],\n }),\n [],\n );\n\n const sheetStyle = useMemo(\n () => [\n tw.style(\n 'bg-default rounded-t-3xl overflow-hidden border border-muted',\n twClassName,\n ),\n {\n maxHeight: maxSheetHeight,\n paddingBottom: Platform.select({\n ios: screenBottomPadding,\n macos: screenBottomPadding,\n default: screenBottomPadding + 16,\n }),\n ...(isFullscreen && { height: maxSheetHeight }),\n ...shadowLg,\n },\n style,\n ],\n\n [\n tw,\n maxSheetHeight,\n screenBottomPadding,\n isFullscreen,\n shadowLg,\n style,\n twClassName,\n ],\n );\n\n const combinedSheetStyle = useMemo(\n () => [...sheetStyle, animatedSheetStyle],\n\n [sheetStyle],\n );\n\n useImperativeHandle(ref, () => ({\n onOpenDialog,\n onCloseDialog,\n }));\n\n return (\n <KeyboardAvoidingView\n style={tw.style('absolute bottom-0 inset-x-0')}\n behavior={Platform.OS === 'ios' ? 'padding' : undefined}\n keyboardVerticalOffset={\n Platform.OS === 'ios' ? -screenBottomPadding : frameY\n }\n enabled={keyboardAvoidingViewEnabled}\n {...props}\n >\n <GestureDetector gesture={gestureHandler}>\n <Animated.View\n onLayout={updateSheetHeight}\n style={combinedSheetStyle}\n >\n {isInteractable && (\n <View style={tw.style('self-stretch items-center p-1')}>\n <View style={tw.style('h-1 w-10 rounded-sm bg-border-muted')} />\n </View>\n )}\n {children}\n </Animated.View>\n </GestureDetector>\n </KeyboardAvoidingView>\n );\n },\n);\n"]}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD = exports.
|
|
3
|
+
exports.DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD = exports.DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY = exports.getBottomSheetDialogSpringConfig = exports.DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG = void 0;
|
|
4
4
|
const design_tokens_1 = require("@metamask-previews/design-tokens");
|
|
5
|
-
|
|
5
|
+
/** iOS-like sheet spring: natural deceleration with minimal overshoot on open. */
|
|
6
|
+
exports.DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG = {
|
|
7
|
+
damping: 28,
|
|
8
|
+
stiffness: 320,
|
|
9
|
+
mass: 0.9,
|
|
10
|
+
overshootClamping: true,
|
|
11
|
+
};
|
|
12
|
+
const getBottomSheetDialogSpringConfig = (overrides) => ({
|
|
13
|
+
...exports.DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG,
|
|
14
|
+
...overrides,
|
|
15
|
+
});
|
|
16
|
+
exports.getBottomSheetDialogSpringConfig = getBottomSheetDialogSpringConfig;
|
|
6
17
|
/**
|
|
7
|
-
*
|
|
18
|
+
* Minimum swipe velocity (px/s) to treat the gesture as a fling for snap/dismiss.
|
|
8
19
|
*/
|
|
9
|
-
exports.
|
|
20
|
+
exports.DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY = design_tokens_1.AnimationDuration.Regularly;
|
|
10
21
|
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
exports.DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION = design_tokens_1.AnimationDuration.Regularly;
|
|
14
|
-
/**
|
|
15
|
-
* This indicates that 60% of the sheet needs to be offscreen to meet the distance threshold.
|
|
22
|
+
* Fraction of sheet height dragged down before dismiss without a fling.
|
|
16
23
|
*/
|
|
17
24
|
exports.DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD = 0.6;
|
|
18
25
|
//# sourceMappingURL=BottomSheetDialog.constants.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetDialog.constants.cjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.constants.ts"],"names":[],"mappings":";;;AAAA,oEAAqE;
|
|
1
|
+
{"version":3,"file":"BottomSheetDialog.constants.cjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.constants.ts"],"names":[],"mappings":";;;AAAA,oEAAqE;AAGrE,kFAAkF;AACrE,QAAA,uCAAuC,GAAG;IACrD,OAAO,EAAE,EAAE;IACX,SAAS,EAAE,GAAG;IACd,IAAI,EAAE,GAAG;IACT,iBAAiB,EAAE,IAAI;CACY,CAAC;AAM/B,MAAM,gCAAgC,GAAG,CAC9C,SAA4C,EAC1B,EAAE,CAAC,CAAC;IACtB,GAAG,+CAAuC;IAC1C,GAAG,SAAS;CACb,CAAC,CAAC;AALU,QAAA,gCAAgC,oCAK1C;AAEH;;GAEG;AACU,QAAA,iDAAiD,GAC5D,iCAAiB,CAAC,SAAS,CAAC;AAE9B;;GAEG;AACU,QAAA,0CAA0C,GAAG,GAAG,CAAC","sourcesContent":["import { AnimationDuration } from '@metamask-previews/design-tokens';\nimport type { WithSpringConfig } from 'react-native-reanimated';\n\n/** iOS-like sheet spring: natural deceleration with minimal overshoot on open. */\nexport const DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG = {\n damping: 28,\n stiffness: 320,\n mass: 0.9,\n overshootClamping: true,\n} as const satisfies WithSpringConfig;\n\ntype BottomSheetDialogSpringOverrides = Partial<\n Pick<WithSpringConfig, 'velocity' | 'reduceMotion' | 'energyThreshold'>\n>;\n\nexport const getBottomSheetDialogSpringConfig = (\n overrides?: BottomSheetDialogSpringOverrides,\n): WithSpringConfig => ({\n ...DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG,\n ...overrides,\n});\n\n/**\n * Minimum swipe velocity (px/s) to treat the gesture as a fling for snap/dismiss.\n */\nexport const DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY =\n AnimationDuration.Regularly;\n\n/**\n * Fraction of sheet height dragged down before dismiss without a fling.\n */\nexport const DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD = 0.6;\n"]}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { AnimationDuration } from "@metamask-previews/design-tokens";
|
|
2
|
+
import type { WithSpringConfig } from "react-native-reanimated";
|
|
3
|
+
/** iOS-like sheet spring: natural deceleration with minimal overshoot on open. */
|
|
4
|
+
export declare const DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG: {
|
|
5
|
+
readonly damping: 28;
|
|
6
|
+
readonly stiffness: 320;
|
|
7
|
+
readonly mass: 0.9;
|
|
8
|
+
readonly overshootClamping: true;
|
|
9
|
+
};
|
|
10
|
+
type BottomSheetDialogSpringOverrides = Partial<Pick<WithSpringConfig, 'velocity' | 'reduceMotion' | 'energyThreshold'>>;
|
|
11
|
+
export declare const getBottomSheetDialogSpringConfig: (overrides?: BottomSheetDialogSpringOverrides) => WithSpringConfig;
|
|
2
12
|
/**
|
|
3
|
-
*
|
|
13
|
+
* Minimum swipe velocity (px/s) to treat the gesture as a fling for snap/dismiss.
|
|
4
14
|
*/
|
|
5
|
-
export declare const
|
|
15
|
+
export declare const DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY = AnimationDuration.Regularly;
|
|
6
16
|
/**
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export declare const DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION = AnimationDuration.Regularly;
|
|
10
|
-
/**
|
|
11
|
-
* This indicates that 60% of the sheet needs to be offscreen to meet the distance threshold.
|
|
17
|
+
* Fraction of sheet height dragged down before dismiss without a fling.
|
|
12
18
|
*/
|
|
13
19
|
export declare const DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD = 0.6;
|
|
20
|
+
export {};
|
|
14
21
|
//# sourceMappingURL=BottomSheetDialog.constants.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetDialog.constants.d.cts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;
|
|
1
|
+
{"version":3,"file":"BottomSheetDialog.constants.d.cts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAAgC;AAEhE,kFAAkF;AAClF,eAAO,MAAM,uCAAuC;;;;;CAKf,CAAC;AAEtC,KAAK,gCAAgC,GAAG,OAAO,CAC7C,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,cAAc,GAAG,iBAAiB,CAAC,CACxE,CAAC;AAEF,eAAO,MAAM,gCAAgC,eAC/B,gCAAgC,KAC3C,gBAGD,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iDAAiD,8BACjC,CAAC;AAE9B;;GAEG;AACH,eAAO,MAAM,0CAA0C,MAAM,CAAC"}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { AnimationDuration } from "@metamask-previews/design-tokens";
|
|
2
|
+
import type { WithSpringConfig } from "react-native-reanimated";
|
|
3
|
+
/** iOS-like sheet spring: natural deceleration with minimal overshoot on open. */
|
|
4
|
+
export declare const DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG: {
|
|
5
|
+
readonly damping: 28;
|
|
6
|
+
readonly stiffness: 320;
|
|
7
|
+
readonly mass: 0.9;
|
|
8
|
+
readonly overshootClamping: true;
|
|
9
|
+
};
|
|
10
|
+
type BottomSheetDialogSpringOverrides = Partial<Pick<WithSpringConfig, 'velocity' | 'reduceMotion' | 'energyThreshold'>>;
|
|
11
|
+
export declare const getBottomSheetDialogSpringConfig: (overrides?: BottomSheetDialogSpringOverrides) => WithSpringConfig;
|
|
2
12
|
/**
|
|
3
|
-
*
|
|
13
|
+
* Minimum swipe velocity (px/s) to treat the gesture as a fling for snap/dismiss.
|
|
4
14
|
*/
|
|
5
|
-
export declare const
|
|
15
|
+
export declare const DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY = AnimationDuration.Regularly;
|
|
6
16
|
/**
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export declare const DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION = AnimationDuration.Regularly;
|
|
10
|
-
/**
|
|
11
|
-
* This indicates that 60% of the sheet needs to be offscreen to meet the distance threshold.
|
|
17
|
+
* Fraction of sheet height dragged down before dismiss without a fling.
|
|
12
18
|
*/
|
|
13
19
|
export declare const DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD = 0.6;
|
|
20
|
+
export {};
|
|
14
21
|
//# sourceMappingURL=BottomSheetDialog.constants.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetDialog.constants.d.mts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;
|
|
1
|
+
{"version":3,"file":"BottomSheetDialog.constants.d.mts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAAgC;AAEhE,kFAAkF;AAClF,eAAO,MAAM,uCAAuC;;;;;CAKf,CAAC;AAEtC,KAAK,gCAAgC,GAAG,OAAO,CAC7C,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,cAAc,GAAG,iBAAiB,CAAC,CACxE,CAAC;AAEF,eAAO,MAAM,gCAAgC,eAC/B,gCAAgC,KAC3C,gBAGD,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iDAAiD,8BACjC,CAAC;AAE9B;;GAEG;AACH,eAAO,MAAM,0CAA0C,MAAM,CAAC"}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { AnimationDuration } from "@metamask-previews/design-tokens";
|
|
2
|
-
|
|
2
|
+
/** iOS-like sheet spring: natural deceleration with minimal overshoot on open. */
|
|
3
|
+
export const DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG = {
|
|
4
|
+
damping: 28,
|
|
5
|
+
stiffness: 320,
|
|
6
|
+
mass: 0.9,
|
|
7
|
+
overshootClamping: true,
|
|
8
|
+
};
|
|
9
|
+
export const getBottomSheetDialogSpringConfig = (overrides) => ({
|
|
10
|
+
...DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG,
|
|
11
|
+
...overrides,
|
|
12
|
+
});
|
|
3
13
|
/**
|
|
4
|
-
*
|
|
14
|
+
* Minimum swipe velocity (px/s) to treat the gesture as a fling for snap/dismiss.
|
|
5
15
|
*/
|
|
6
|
-
export const
|
|
16
|
+
export const DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY = AnimationDuration.Regularly;
|
|
7
17
|
/**
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
export const DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_DURATION = AnimationDuration.Regularly;
|
|
11
|
-
/**
|
|
12
|
-
* This indicates that 60% of the sheet needs to be offscreen to meet the distance threshold.
|
|
18
|
+
* Fraction of sheet height dragged down before dismiss without a fling.
|
|
13
19
|
*/
|
|
14
20
|
export const DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD = 0.6;
|
|
15
21
|
//# sourceMappingURL=BottomSheetDialog.constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetDialog.constants.mjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;
|
|
1
|
+
{"version":3,"file":"BottomSheetDialog.constants.mjs","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;AAGrE,kFAAkF;AAClF,MAAM,CAAC,MAAM,uCAAuC,GAAG;IACrD,OAAO,EAAE,EAAE;IACX,SAAS,EAAE,GAAG;IACd,IAAI,EAAE,GAAG;IACT,iBAAiB,EAAE,IAAI;CACY,CAAC;AAMtC,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,SAA4C,EAC1B,EAAE,CAAC,CAAC;IACtB,GAAG,uCAAuC;IAC1C,GAAG,SAAS;CACb,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,iDAAiD,GAC5D,iBAAiB,CAAC,SAAS,CAAC;AAE9B;;GAEG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAG,CAAC","sourcesContent":["import { AnimationDuration } from '@metamask-previews/design-tokens';\nimport type { WithSpringConfig } from 'react-native-reanimated';\n\n/** iOS-like sheet spring: natural deceleration with minimal overshoot on open. */\nexport const DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG = {\n damping: 28,\n stiffness: 320,\n mass: 0.9,\n overshootClamping: true,\n} as const satisfies WithSpringConfig;\n\ntype BottomSheetDialogSpringOverrides = Partial<\n Pick<WithSpringConfig, 'velocity' | 'reduceMotion' | 'energyThreshold'>\n>;\n\nexport const getBottomSheetDialogSpringConfig = (\n overrides?: BottomSheetDialogSpringOverrides,\n): WithSpringConfig => ({\n ...DEFAULT_BOTTOMSHEETDIALOG_SPRING_CONFIG,\n ...overrides,\n});\n\n/**\n * Minimum swipe velocity (px/s) to treat the gesture as a fling for snap/dismiss.\n */\nexport const DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY =\n AnimationDuration.Regularly;\n\n/**\n * Fraction of sheet height dragged down before dismiss without a fling.\n */\nexport const DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD = 0.6;\n"]}
|
|
@@ -5,6 +5,7 @@ export declare const BottomSheetDialog: React.ForwardRefExoticComponent<{
|
|
|
5
5
|
isFullscreen?: boolean | undefined;
|
|
6
6
|
isInteractable?: boolean | undefined;
|
|
7
7
|
keyboardAvoidingViewEnabled?: boolean | undefined;
|
|
8
|
+
onDismissStart?: (() => void) | undefined;
|
|
8
9
|
onClose?: ((hasPendingAction?: boolean | undefined) => void) | undefined;
|
|
9
10
|
onOpen?: ((hasPendingAction?: boolean | undefined) => void) | undefined;
|
|
10
11
|
twClassName?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetDialog.d.cts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BottomSheetDialog.d.cts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":"AAOA,OAAO,KAON,cAAc;AAyBf,OAAO,KAAK,EACV,oBAAoB,EAErB,sCAAkC;AAEnC,eAAO,MAAM,iBAAiB;;;;;;;;;iFAoR7B,CAAC"}
|
|
@@ -5,6 +5,7 @@ export declare const BottomSheetDialog: React.ForwardRefExoticComponent<{
|
|
|
5
5
|
isFullscreen?: boolean | undefined;
|
|
6
6
|
isInteractable?: boolean | undefined;
|
|
7
7
|
keyboardAvoidingViewEnabled?: boolean | undefined;
|
|
8
|
+
onDismissStart?: (() => void) | undefined;
|
|
8
9
|
onClose?: ((hasPendingAction?: boolean | undefined) => void) | undefined;
|
|
9
10
|
onOpen?: ((hasPendingAction?: boolean | undefined) => void) | undefined;
|
|
10
11
|
twClassName?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheetDialog.d.mts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BottomSheetDialog.d.mts","sourceRoot":"","sources":["../../../src/components/BottomSheetDialog/BottomSheetDialog.tsx"],"names":[],"mappings":"AAOA,OAAO,KAON,cAAc;AAyBf,OAAO,KAAK,EACV,oBAAoB,EAErB,sCAAkC;AAEnC,eAAO,MAAM,iBAAiB;;;;;;;;;iFAoR7B,CAAC"}
|
|
@@ -4,25 +4,24 @@ function $importDefault(module) {
|
|
|
4
4
|
}
|
|
5
5
|
return module;
|
|
6
6
|
}
|
|
7
|
-
import { Theme,
|
|
8
|
-
import { lightTheme,
|
|
7
|
+
import { Theme, useTailwind, useTheme } from "@metamask-previews/design-system-twrnc-preset";
|
|
8
|
+
import { lightTheme, darkTheme } from "@metamask-previews/design-tokens";
|
|
9
9
|
import $lodash from "lodash";
|
|
10
10
|
const { debounce } = $lodash;
|
|
11
11
|
import $React, { forwardRef, useCallback, useEffect, useMemo, useRef, useImperativeHandle } from "react";
|
|
12
12
|
const React = $importDefault($React);
|
|
13
13
|
import { View, Platform, KeyboardAvoidingView } from "react-native";
|
|
14
14
|
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
15
|
-
import Animated, { runOnJS, useAnimatedStyle, useSharedValue,
|
|
15
|
+
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated";
|
|
16
16
|
import { useSafeAreaFrame, useSafeAreaInsets } from "react-native-safe-area-context";
|
|
17
17
|
// Internal dependencies.
|
|
18
|
-
import {
|
|
19
|
-
export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, isInteractable = true, keyboardAvoidingViewEnabled = true, onClose, onOpen, style, twClassName, ...props }, ref) => {
|
|
18
|
+
import { DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD, DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY, getBottomSheetDialogSpringConfig } from "./BottomSheetDialog.constants.mjs";
|
|
19
|
+
export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, isInteractable = true, keyboardAvoidingViewEnabled = true, onDismissStart, onClose, onOpen, style, twClassName, ...props }, ref) => {
|
|
20
20
|
const tw = useTailwind();
|
|
21
21
|
const currentTheme = useTheme();
|
|
22
|
-
const isPureBlack = usePureBlack();
|
|
23
22
|
const shadowLg = currentTheme === Theme.Light
|
|
24
23
|
? lightTheme.shadows.size.lg
|
|
25
|
-
:
|
|
24
|
+
: darkTheme.shadows.size.lg;
|
|
26
25
|
const { top: screenTopPadding, bottom: screenBottomPadding } = useSafeAreaInsets();
|
|
27
26
|
const { y: frameY, height: screenHeight } = useSafeAreaFrame();
|
|
28
27
|
const maxSheetHeight = screenHeight - screenTopPadding;
|
|
@@ -39,15 +38,23 @@ export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, i
|
|
|
39
38
|
const onCloseCB = useCallback(() => {
|
|
40
39
|
onClose?.();
|
|
41
40
|
}, [onClose]);
|
|
41
|
+
const animateSheetTo = (target, onComplete) => {
|
|
42
|
+
currentYOffset.value = withSpring(target, getBottomSheetDialogSpringConfig(), (finished) => {
|
|
43
|
+
if (finished && onComplete) {
|
|
44
|
+
runOnJS(onComplete)();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
42
48
|
const onCloseDialog = useCallback((callback) => {
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
onDismissStart?.();
|
|
50
|
+
animateSheetTo(bottomOfDialogYValue.value, () => {
|
|
51
|
+
onCloseCB();
|
|
45
52
|
if (callback) {
|
|
46
|
-
|
|
53
|
+
callback();
|
|
47
54
|
}
|
|
48
55
|
});
|
|
49
56
|
// Ref values do not affect deps.
|
|
50
|
-
}, [onCloseCB]);
|
|
57
|
+
}, [onCloseCB, onDismissStart]);
|
|
51
58
|
const gestureHandler = useMemo(() => {
|
|
52
59
|
// These gesture callbacks need explicit 'worklet' directives because this
|
|
53
60
|
// package ships a pre-built dist compiled by ts-bridge (tsc), which emits the
|
|
@@ -94,7 +101,7 @@ export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, i
|
|
|
94
101
|
DEFAULT_BOTTOMSHEETDIALOG_DISMISSTHRESHOLD;
|
|
95
102
|
// Check if the gesture's vertical speed has reached the threshold to determine a swipe action
|
|
96
103
|
const hasReachedSwipeThreshold = Math.abs(velocityY) >
|
|
97
|
-
|
|
104
|
+
DEFAULT_BOTTOMSHEETDIALOG_SWIPETHRESHOLD_VELOCITY;
|
|
98
105
|
const isQuickDismissing = velocityY > 0;
|
|
99
106
|
// If user is swiping
|
|
100
107
|
if (hasReachedSwipeThreshold) {
|
|
@@ -117,10 +124,7 @@ export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, i
|
|
|
117
124
|
runOnJS(onCloseDialog)();
|
|
118
125
|
}
|
|
119
126
|
else {
|
|
120
|
-
|
|
121
|
-
currentYOffset.value = withTiming(finalYOffset, {
|
|
122
|
-
duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,
|
|
123
|
-
});
|
|
127
|
+
currentYOffset.value = withSpring(finalYOffset, getBottomSheetDialogSpringConfig({ velocity: velocityY }));
|
|
124
128
|
}
|
|
125
129
|
});
|
|
126
130
|
return gesture;
|
|
@@ -134,15 +138,11 @@ export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, i
|
|
|
134
138
|
]);
|
|
135
139
|
// Animate in sheet on initial render.
|
|
136
140
|
const onOpenDialog = (callback) => {
|
|
137
|
-
// Starts setting the Y position of the dialog to the bottom of the dialog
|
|
138
141
|
currentYOffset.value = bottomOfDialogYValue.value;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
duration: DEFAULT_BOTTOMSHEETDIALOG_DISPLAY_DURATION,
|
|
142
|
-
}, () => {
|
|
143
|
-
runOnJS(onOpenCB)();
|
|
142
|
+
animateSheetTo(topOfDialogYValue.value, () => {
|
|
143
|
+
onOpenCB();
|
|
144
144
|
if (callback) {
|
|
145
|
-
|
|
145
|
+
callback();
|
|
146
146
|
}
|
|
147
147
|
});
|
|
148
148
|
};
|
|
@@ -170,7 +170,7 @@ export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, i
|
|
|
170
170
|
],
|
|
171
171
|
}), []);
|
|
172
172
|
const sheetStyle = useMemo(() => [
|
|
173
|
-
tw.style(
|
|
173
|
+
tw.style('bg-default rounded-t-3xl overflow-hidden border border-muted', twClassName),
|
|
174
174
|
{
|
|
175
175
|
maxHeight: maxSheetHeight,
|
|
176
176
|
paddingBottom: Platform.select({
|
|
@@ -184,7 +184,6 @@ export const BottomSheetDialog = forwardRef(({ children, isFullscreen = false, i
|
|
|
184
184
|
style,
|
|
185
185
|
], [
|
|
186
186
|
tw,
|
|
187
|
-
isPureBlack,
|
|
188
187
|
maxSheetHeight,
|
|
189
188
|
screenBottomPadding,
|
|
190
189
|
isFullscreen,
|