@yahoo/uds-mobile 2.3.3 → 2.4.0
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/android/build.gradle +39 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/yahoo/uds/screencornerradius/UDSScreenCornerRadiusModule.kt +44 -0
- package/dist/bin/generateTheme.mjs +10 -0
- package/dist/bin/mobile/scripts/utils/configToRNMappings.mjs +4 -1
- package/dist/components/AndroidBackHandler.cjs +31 -0
- package/dist/components/AndroidBackHandler.d.cts +21 -0
- package/dist/components/AndroidBackHandler.d.cts.map +1 -0
- package/dist/components/AndroidBackHandler.d.ts +21 -0
- package/dist/components/AndroidBackHandler.d.ts.map +1 -0
- package/dist/components/AndroidBackHandler.js +30 -0
- package/dist/components/AndroidBackHandler.js.map +1 -0
- package/dist/components/Avatar.cjs +1 -1
- package/dist/components/Avatar.js +1 -1
- package/dist/components/Badge.cjs +1 -1
- package/dist/components/Badge.js +1 -1
- package/dist/components/BottomSheet/BottomSheet.cjs +336 -0
- package/dist/components/BottomSheet/BottomSheet.d.cts +33 -0
- package/dist/components/BottomSheet/BottomSheet.d.cts.map +1 -0
- package/dist/components/BottomSheet/BottomSheet.d.ts +33 -0
- package/dist/components/BottomSheet/BottomSheet.d.ts.map +1 -0
- package/dist/components/BottomSheet/BottomSheet.js +334 -0
- package/dist/components/BottomSheet/BottomSheet.js.map +1 -0
- package/dist/components/BottomSheet/BottomSheetContent.cjs +65 -0
- package/dist/components/BottomSheet/BottomSheetContent.d.cts +22 -0
- package/dist/components/BottomSheet/BottomSheetContent.d.cts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetContent.d.ts +22 -0
- package/dist/components/BottomSheet/BottomSheetContent.d.ts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetContent.js +63 -0
- package/dist/components/BottomSheet/BottomSheetContent.js.map +1 -0
- package/dist/components/BottomSheet/BottomSheetDismiss.cjs +28 -0
- package/dist/components/BottomSheet/BottomSheetDismiss.d.cts +25 -0
- package/dist/components/BottomSheet/BottomSheetDismiss.d.cts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetDismiss.d.ts +25 -0
- package/dist/components/BottomSheet/BottomSheetDismiss.d.ts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetDismiss.js +27 -0
- package/dist/components/BottomSheet/BottomSheetDismiss.js.map +1 -0
- package/dist/components/BottomSheet/BottomSheetHandle.cjs +56 -0
- package/dist/components/BottomSheet/BottomSheetHandle.d.cts +14 -0
- package/dist/components/BottomSheet/BottomSheetHandle.d.cts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetHandle.d.ts +14 -0
- package/dist/components/BottomSheet/BottomSheetHandle.d.ts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetHandle.js +55 -0
- package/dist/components/BottomSheet/BottomSheetHandle.js.map +1 -0
- package/dist/components/BottomSheet/BottomSheetHeader.cjs +69 -0
- package/dist/components/BottomSheet/BottomSheetHeader.d.cts +16 -0
- package/dist/components/BottomSheet/BottomSheetHeader.d.cts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetHeader.d.ts +16 -0
- package/dist/components/BottomSheet/BottomSheetHeader.d.ts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetHeader.js +68 -0
- package/dist/components/BottomSheet/BottomSheetHeader.js.map +1 -0
- package/dist/components/BottomSheet/BottomSheetInternalProvider.cjs +26 -0
- package/dist/components/BottomSheet/BottomSheetInternalProvider.d.cts +23 -0
- package/dist/components/BottomSheet/BottomSheetInternalProvider.d.cts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetInternalProvider.d.ts +23 -0
- package/dist/components/BottomSheet/BottomSheetInternalProvider.d.ts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetInternalProvider.js +24 -0
- package/dist/components/BottomSheet/BottomSheetInternalProvider.js.map +1 -0
- package/dist/components/BottomSheet/BottomSheetProvider.cjs +33 -0
- package/dist/components/BottomSheet/BottomSheetProvider.d.cts +24 -0
- package/dist/components/BottomSheet/BottomSheetProvider.d.cts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetProvider.d.ts +24 -0
- package/dist/components/BottomSheet/BottomSheetProvider.d.ts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetProvider.js +31 -0
- package/dist/components/BottomSheet/BottomSheetProvider.js.map +1 -0
- package/dist/components/BottomSheet/BottomSheetTrigger.cjs +28 -0
- package/dist/components/BottomSheet/BottomSheetTrigger.d.cts +25 -0
- package/dist/components/BottomSheet/BottomSheetTrigger.d.cts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetTrigger.d.ts +25 -0
- package/dist/components/BottomSheet/BottomSheetTrigger.d.ts.map +1 -0
- package/dist/components/BottomSheet/BottomSheetTrigger.js +27 -0
- package/dist/components/BottomSheet/BottomSheetTrigger.js.map +1 -0
- package/dist/components/BottomSheet/index.cjs +19 -0
- package/dist/components/BottomSheet/index.d.cts +11 -0
- package/dist/components/BottomSheet/index.d.ts +11 -0
- package/dist/components/BottomSheet/index.js +11 -0
- package/dist/components/BottomSheet/types.cjs +1 -0
- package/dist/components/BottomSheet/types.d.cts +173 -0
- package/dist/components/BottomSheet/types.d.cts.map +1 -0
- package/dist/components/BottomSheet/types.d.ts +173 -0
- package/dist/components/BottomSheet/types.d.ts.map +1 -0
- package/dist/components/BottomSheet/types.js +1 -0
- package/dist/components/BottomSheet/useBottomSheetDrag.cjs +191 -0
- package/dist/components/BottomSheet/useBottomSheetDrag.d.cts +69 -0
- package/dist/components/BottomSheet/useBottomSheetDrag.d.cts.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetDrag.d.ts +69 -0
- package/dist/components/BottomSheet/useBottomSheetDrag.d.ts.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetDrag.js +190 -0
- package/dist/components/BottomSheet/useBottomSheetDrag.js.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetScroll.cjs +61 -0
- package/dist/components/BottomSheet/useBottomSheetScroll.d.cts +48 -0
- package/dist/components/BottomSheet/useBottomSheetScroll.d.cts.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetScroll.d.ts +48 -0
- package/dist/components/BottomSheet/useBottomSheetScroll.d.ts.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetScroll.js +60 -0
- package/dist/components/BottomSheet/useBottomSheetScroll.js.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetSnapModel.cjs +142 -0
- package/dist/components/BottomSheet/useBottomSheetSnapModel.d.cts +79 -0
- package/dist/components/BottomSheet/useBottomSheetSnapModel.d.cts.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetSnapModel.d.ts +79 -0
- package/dist/components/BottomSheet/useBottomSheetSnapModel.d.ts.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetSnapModel.js +140 -0
- package/dist/components/BottomSheet/useBottomSheetSnapModel.js.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetStore.cjs +79 -0
- package/dist/components/BottomSheet/useBottomSheetStore.d.cts +45 -0
- package/dist/components/BottomSheet/useBottomSheetStore.d.cts.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetStore.d.ts +45 -0
- package/dist/components/BottomSheet/useBottomSheetStore.d.ts.map +1 -0
- package/dist/components/BottomSheet/useBottomSheetStore.js +77 -0
- package/dist/components/BottomSheet/useBottomSheetStore.js.map +1 -0
- package/dist/components/BottomSheet/useExpansionMargins.cjs +57 -0
- package/dist/components/BottomSheet/useExpansionMargins.d.cts +59 -0
- package/dist/components/BottomSheet/useExpansionMargins.d.cts.map +1 -0
- package/dist/components/BottomSheet/useExpansionMargins.d.ts +59 -0
- package/dist/components/BottomSheet/useExpansionMargins.d.ts.map +1 -0
- package/dist/components/BottomSheet/useExpansionMargins.js +56 -0
- package/dist/components/BottomSheet/useExpansionMargins.js.map +1 -0
- package/dist/components/BottomSheet/useKeyboardAvoidance.cjs +53 -0
- package/dist/components/BottomSheet/useKeyboardAvoidance.d.cts +31 -0
- package/dist/components/BottomSheet/useKeyboardAvoidance.d.cts.map +1 -0
- package/dist/components/BottomSheet/useKeyboardAvoidance.d.ts +31 -0
- package/dist/components/BottomSheet/useKeyboardAvoidance.d.ts.map +1 -0
- package/dist/components/BottomSheet/useKeyboardAvoidance.js +52 -0
- package/dist/components/BottomSheet/useKeyboardAvoidance.js.map +1 -0
- package/dist/components/BottomSheet/utils.cjs +77 -0
- package/dist/components/BottomSheet/utils.d.cts +50 -0
- package/dist/components/BottomSheet/utils.d.cts.map +1 -0
- package/dist/components/BottomSheet/utils.d.ts +50 -0
- package/dist/components/BottomSheet/utils.d.ts.map +1 -0
- package/dist/components/BottomSheet/utils.js +72 -0
- package/dist/components/BottomSheet/utils.js.map +1 -0
- package/dist/components/Box.cjs +1 -1
- package/dist/components/Box.js +1 -1
- package/dist/components/Button.cjs +1 -1
- package/dist/components/Button.js +1 -1
- package/dist/components/Checkbox.cjs +1 -1
- package/dist/components/Checkbox.js +1 -1
- package/dist/components/Chip.cjs +1 -1
- package/dist/components/Chip.js +1 -1
- package/dist/components/Icon.cjs +1 -1
- package/dist/components/Icon.js +1 -1
- package/dist/components/IconButton.cjs +3 -3
- package/dist/components/IconButton.js +3 -3
- package/dist/components/IconButton.js.map +1 -1
- package/dist/components/Image.cjs +1 -1
- package/dist/components/Image.js +1 -1
- package/dist/components/Input.cjs +1 -1
- package/dist/components/Input.js +1 -1
- package/dist/components/Link.cjs +1 -1
- package/dist/components/Link.js +1 -1
- package/dist/components/Pressable.cjs +1 -1
- package/dist/components/Pressable.js +1 -1
- package/dist/components/Radio.cjs +1 -1
- package/dist/components/Radio.js +1 -1
- package/dist/components/Screen.cjs +1 -1
- package/dist/components/Screen.js +1 -1
- package/dist/components/Scrim.cjs +73 -0
- package/dist/components/Scrim.d.cts +43 -0
- package/dist/components/Scrim.d.cts.map +1 -0
- package/dist/components/Scrim.d.ts +43 -0
- package/dist/components/Scrim.d.ts.map +1 -0
- package/dist/components/Scrim.js +71 -0
- package/dist/components/Scrim.js.map +1 -0
- package/dist/components/Switch.cjs +1 -1
- package/dist/components/Switch.js +1 -1
- package/dist/components/Text.cjs +1 -1
- package/dist/components/Text.js +1 -1
- package/dist/components/UDSProvider.cjs +38 -0
- package/dist/components/UDSProvider.d.cts +30 -0
- package/dist/components/UDSProvider.d.cts.map +1 -0
- package/dist/components/UDSProvider.d.ts +30 -0
- package/dist/components/UDSProvider.d.ts.map +1 -0
- package/dist/components/UDSProvider.js +37 -0
- package/dist/components/UDSProvider.js.map +1 -0
- package/dist/native/UDSScreenCornerRadiusModule.cjs +30 -0
- package/dist/native/UDSScreenCornerRadiusModule.d.cts +12 -0
- package/dist/native/UDSScreenCornerRadiusModule.d.cts.map +1 -0
- package/dist/native/UDSScreenCornerRadiusModule.d.ts +12 -0
- package/dist/native/UDSScreenCornerRadiusModule.d.ts.map +1 -0
- package/dist/native/UDSScreenCornerRadiusModule.js +17 -0
- package/dist/native/UDSScreenCornerRadiusModule.js.map +1 -0
- package/dist/portal.cjs +81 -0
- package/dist/portal.d.cts +18 -0
- package/dist/portal.d.cts.map +1 -0
- package/dist/portal.d.ts +18 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +79 -0
- package/dist/portal.js.map +1 -0
- package/dist/types/dist/index.d.cts.map +1 -1
- package/dist/types/dist/index.d.ts.map +1 -1
- package/expo-module.config.json +9 -0
- package/generated/styles.cjs +10 -0
- package/generated/styles.d.ts +15 -2
- package/generated/styles.mjs +10 -0
- package/generated/unistyles.d.ts +21 -0
- package/ios/UDSMobile.podspec +25 -0
- package/ios/UDSScreenCornerRadiusModule.swift +218 -0
- package/package.json +40 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBottomSheetScroll.d.cts","names":[],"sources":["../../../src/components/BottomSheet/useBottomSheetScroll.ts"],"mappings":";;;;;;;;;;AACoD;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuC3C,oBAAA,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
|
|
2
|
+
import * as react_native_reanimated0 from "react-native-reanimated";
|
|
3
|
+
import Animated from "react-native-reanimated";
|
|
4
|
+
import * as react_native_gesture_handler_lib_typescript_handlers_gestures_nativeGesture0 from "react-native-gesture-handler/lib/typescript/handlers/gestures/nativeGesture";
|
|
5
|
+
|
|
6
|
+
//#region src/components/BottomSheet/useBottomSheetScroll.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Low-level hook for consumers who need a custom scrollable (e.g. `FlatList`,
|
|
9
|
+
* `SectionList`) instead of `<BottomSheetContent>`.
|
|
10
|
+
*
|
|
11
|
+
* Returns all the props needed to wire a scrollable into the sheet's
|
|
12
|
+
* scroll-lock coordination (scrollEnabled toggle, offset tracking, gesture composition).
|
|
13
|
+
*
|
|
14
|
+
* Must be rendered inside a `<BottomSheet>`.
|
|
15
|
+
*
|
|
16
|
+
* @throws If used outside a `<BottomSheet>` component tree.
|
|
17
|
+
*
|
|
18
|
+
* @returns `{ scrollHandler, scrollableRef, nativeGesture, animatedProps }`
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const { scrollHandler, scrollableRef, nativeGesture, animatedProps } = useBottomSheetScroll();
|
|
23
|
+
*
|
|
24
|
+
* <GestureDetector gesture={nativeGesture}>
|
|
25
|
+
* <Animated.FlatList
|
|
26
|
+
* ref={scrollableRef}
|
|
27
|
+
* onScroll={scrollHandler}
|
|
28
|
+
* scrollEventThrottle={16}
|
|
29
|
+
* animatedProps={animatedProps}
|
|
30
|
+
* bounces={false}
|
|
31
|
+
* overScrollMode="never"
|
|
32
|
+
* {...otherProps}
|
|
33
|
+
* />
|
|
34
|
+
* </GestureDetector>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function useBottomSheetScroll(): {
|
|
38
|
+
scrollHandler: react_native_reanimated0.ScrollHandlerProcessed<Record<string, unknown>>;
|
|
39
|
+
scrollableRef: react_native_reanimated0.AnimatedRef<Animated.ScrollView>;
|
|
40
|
+
nativeGesture: react_native_gesture_handler_lib_typescript_handlers_gestures_nativeGesture0.NativeGesture;
|
|
41
|
+
animatedProps: Partial<{
|
|
42
|
+
scrollEnabled: boolean;
|
|
43
|
+
decelerationRate: number;
|
|
44
|
+
}>;
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
export { useBottomSheetScroll };
|
|
48
|
+
//# sourceMappingURL=useBottomSheetScroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBottomSheetScroll.d.ts","names":[],"sources":["../../../src/components/BottomSheet/useBottomSheetScroll.ts"],"mappings":";;;;;;;;;;AACoD;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuC3C,oBAAA,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
import { useBottomSheetInternalContext } from "./BottomSheetInternalProvider.js";
|
|
3
|
+
import { useAnimatedProps, useAnimatedRef, useAnimatedScrollHandler } from "react-native-reanimated";
|
|
4
|
+
import { Gesture } from "react-native-gesture-handler";
|
|
5
|
+
|
|
6
|
+
//#region src/components/BottomSheet/useBottomSheetScroll.ts
|
|
7
|
+
/**
|
|
8
|
+
* Low-level hook for consumers who need a custom scrollable (e.g. `FlatList`,
|
|
9
|
+
* `SectionList`) instead of `<BottomSheetContent>`.
|
|
10
|
+
*
|
|
11
|
+
* Returns all the props needed to wire a scrollable into the sheet's
|
|
12
|
+
* scroll-lock coordination (scrollEnabled toggle, offset tracking, gesture composition).
|
|
13
|
+
*
|
|
14
|
+
* Must be rendered inside a `<BottomSheet>`.
|
|
15
|
+
*
|
|
16
|
+
* @throws If used outside a `<BottomSheet>` component tree.
|
|
17
|
+
*
|
|
18
|
+
* @returns `{ scrollHandler, scrollableRef, nativeGesture, animatedProps }`
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const { scrollHandler, scrollableRef, nativeGesture, animatedProps } = useBottomSheetScroll();
|
|
23
|
+
*
|
|
24
|
+
* <GestureDetector gesture={nativeGesture}>
|
|
25
|
+
* <Animated.FlatList
|
|
26
|
+
* ref={scrollableRef}
|
|
27
|
+
* onScroll={scrollHandler}
|
|
28
|
+
* scrollEventThrottle={16}
|
|
29
|
+
* animatedProps={animatedProps}
|
|
30
|
+
* bounces={false}
|
|
31
|
+
* overScrollMode="never"
|
|
32
|
+
* {...otherProps}
|
|
33
|
+
* />
|
|
34
|
+
* </GestureDetector>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function useBottomSheetScroll() {
|
|
38
|
+
const internalCtx = useBottomSheetInternalContext();
|
|
39
|
+
const scrollableRef = useAnimatedRef();
|
|
40
|
+
const animatedProps = useAnimatedProps(() => ({
|
|
41
|
+
scrollEnabled: !internalCtx?.scrollLocked.value,
|
|
42
|
+
decelerationRate: internalCtx?.scrollLocked.value ? 0 : .998
|
|
43
|
+
}));
|
|
44
|
+
const scrollHandler = useAnimatedScrollHandler({ onScroll: (event) => {
|
|
45
|
+
if (!internalCtx) return;
|
|
46
|
+
internalCtx.scrollOffsetY.value = event.contentOffset.y;
|
|
47
|
+
} });
|
|
48
|
+
if (!internalCtx) throw new Error("useBottomSheetScroll must be used inside a BottomSheet component.");
|
|
49
|
+
const { panGestureRef } = internalCtx;
|
|
50
|
+
return {
|
|
51
|
+
scrollHandler,
|
|
52
|
+
scrollableRef,
|
|
53
|
+
nativeGesture: Gesture.Native().simultaneousWithExternalGesture(panGestureRef),
|
|
54
|
+
animatedProps
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { useBottomSheetScroll };
|
|
60
|
+
//# sourceMappingURL=useBottomSheetScroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBottomSheetScroll.js","names":[],"sources":["../../../src/components/BottomSheet/useBottomSheetScroll.ts"],"sourcesContent":["import { Gesture } from 'react-native-gesture-handler';\nimport type Animated from 'react-native-reanimated';\nimport {\n useAnimatedProps,\n useAnimatedRef,\n useAnimatedScrollHandler,\n} from 'react-native-reanimated';\n\nimport { useBottomSheetInternalContext } from './BottomSheetInternalProvider';\n\n/**\n * Low-level hook for consumers who need a custom scrollable (e.g. `FlatList`,\n * `SectionList`) instead of `<BottomSheetContent>`.\n *\n * Returns all the props needed to wire a scrollable into the sheet's\n * scroll-lock coordination (scrollEnabled toggle, offset tracking, gesture composition).\n *\n * Must be rendered inside a `<BottomSheet>`.\n *\n * @throws If used outside a `<BottomSheet>` component tree.\n *\n * @returns `{ scrollHandler, scrollableRef, nativeGesture, animatedProps }`\n *\n * @example\n * ```tsx\n * const { scrollHandler, scrollableRef, nativeGesture, animatedProps } = useBottomSheetScroll();\n *\n * <GestureDetector gesture={nativeGesture}>\n * <Animated.FlatList\n * ref={scrollableRef}\n * onScroll={scrollHandler}\n * scrollEventThrottle={16}\n * animatedProps={animatedProps}\n * bounces={false}\n * overScrollMode=\"never\"\n * {...otherProps}\n * />\n * </GestureDetector>\n * ```\n */\nfunction useBottomSheetScroll() {\n const internalCtx = useBottomSheetInternalContext();\n const scrollableRef = useAnimatedRef<Animated.ScrollView>();\n\n const animatedProps = useAnimatedProps(() => ({\n scrollEnabled: !internalCtx?.scrollLocked.value,\n decelerationRate: internalCtx?.scrollLocked.value ? 0 : 0.998,\n }));\n\n const scrollHandler = useAnimatedScrollHandler({\n onScroll: (event) => {\n if (!internalCtx) {\n return;\n }\n internalCtx.scrollOffsetY.value = event.contentOffset.y;\n },\n });\n\n if (!internalCtx) {\n throw new Error('useBottomSheetScroll must be used inside a BottomSheet component.');\n }\n\n const { panGestureRef } = internalCtx;\n\n const nativeGesture = Gesture.Native().simultaneousWithExternalGesture(panGestureRef);\n\n return {\n scrollHandler,\n scrollableRef,\n nativeGesture,\n animatedProps,\n };\n}\n\nexport { useBottomSheetScroll };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,uBAAuB;CAC9B,MAAM,cAAc,+BAA+B;CACnD,MAAM,gBAAgB,gBAAqC;CAE3D,MAAM,gBAAgB,wBAAwB;EAC5C,eAAe,CAAC,aAAa,aAAa;EAC1C,kBAAkB,aAAa,aAAa,QAAQ,IAAI;EACzD,EAAE;CAEH,MAAM,gBAAgB,yBAAyB,EAC7C,WAAW,UAAU;AACnB,MAAI,CAAC,YACH;AAEF,cAAY,cAAc,QAAQ,MAAM,cAAc;IAEzD,CAAC;AAEF,KAAI,CAAC,YACH,OAAM,IAAI,MAAM,oEAAoE;CAGtF,MAAM,EAAE,kBAAkB;AAI1B,QAAO;EACL;EACA;EACA,eALoB,QAAQ,QAAQ,CAAC,gCAAgC,cAAc;EAMnF;EACD"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
3
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
4
|
+
const require_motion = require('../../motion.cjs');
|
|
5
|
+
const require_components_BottomSheet_utils = require('./utils.cjs');
|
|
6
|
+
let react = require("react");
|
|
7
|
+
let react_native_reanimated = require("react-native-reanimated");
|
|
8
|
+
|
|
9
|
+
//#region src/components/BottomSheet/useBottomSheetSnapModel.ts
|
|
10
|
+
/**
|
|
11
|
+
* Spring configuration for sheet snap/close animations.
|
|
12
|
+
* Uses the UDS `smooth['3']` motion preset.
|
|
13
|
+
*/
|
|
14
|
+
const SHEET_SPRING_CONFIG = {
|
|
15
|
+
damping: require_motion.MOTION_CONFIG.smooth["3"].damping,
|
|
16
|
+
stiffness: require_motion.MOTION_CONFIG.smooth["3"].stiffness,
|
|
17
|
+
mass: 1
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Manages the snap-point position model for the bottom sheet.
|
|
21
|
+
*
|
|
22
|
+
* Resolves snap point strings to pixel positions, provides spring-animated
|
|
23
|
+
* `animateToSnap` / `animateToClose` functions for both JS and UI threads,
|
|
24
|
+
* and exposes shared values for `translateY`, `activeSnapIndex`, and `isAnimating`.
|
|
25
|
+
*
|
|
26
|
+
* Position model: `translateY = containerHeight - snapHeightPx - bottomInsetPx`
|
|
27
|
+
*/
|
|
28
|
+
function useBottomSheetSnapModel({ snapPointsProp, height, defaultSnapPointIndex, snapPointIndexProp, onSnapPointChange, containerHeight, bottomInsetPx, topInsetPx, fullWidthAtMaxSnap, expandedBottomInsetPx }) {
|
|
29
|
+
const resolvedSnapPoints = (0, react.useMemo)(() => {
|
|
30
|
+
if (snapPointsProp?.length) return snapPointsProp;
|
|
31
|
+
if (height !== void 0) return [height];
|
|
32
|
+
return [require_components_BottomSheet_utils.DEFAULT_SNAP_POINT];
|
|
33
|
+
}, [height, snapPointsProp]);
|
|
34
|
+
const translateY = (0, react_native_reanimated.useSharedValue)(9999);
|
|
35
|
+
const activeSnapIndex = (0, react_native_reanimated.useSharedValue)(require_components_BottomSheet_utils.clampIndex(snapPointIndexProp ?? defaultSnapPointIndex, resolvedSnapPoints.length));
|
|
36
|
+
const isAnimating = (0, react_native_reanimated.useSharedValue)(false);
|
|
37
|
+
/**
|
|
38
|
+
* Compute translateY for a snap index.
|
|
39
|
+
* Position model: translateY = containerHeight - snapHeightPx - bottomInsetPx
|
|
40
|
+
*/
|
|
41
|
+
const getTranslateYForSnap = (0, react.useCallback)((index) => {
|
|
42
|
+
"worklet";
|
|
43
|
+
const clamped = require_components_BottomSheet_utils.clampIndex(index, resolvedSnapPoints.length);
|
|
44
|
+
const sp = resolvedSnapPoints[clamped];
|
|
45
|
+
const heightPx = require_components_BottomSheet_utils.resolveHeightToPx(sp, containerHeight.value);
|
|
46
|
+
const effectiveBottomInset = fullWidthAtMaxSnap && clamped === resolvedSnapPoints.length - 1 ? expandedBottomInsetPx : bottomInsetPx;
|
|
47
|
+
const maxHeight = containerHeight.value - effectiveBottomInset - topInsetPx;
|
|
48
|
+
const clampedHeight = Math.max(0, Math.min(heightPx, maxHeight));
|
|
49
|
+
return containerHeight.value - clampedHeight - effectiveBottomInset;
|
|
50
|
+
}, [
|
|
51
|
+
resolvedSnapPoints,
|
|
52
|
+
containerHeight,
|
|
53
|
+
bottomInsetPx,
|
|
54
|
+
topInsetPx,
|
|
55
|
+
fullWidthAtMaxSnap,
|
|
56
|
+
expandedBottomInsetPx
|
|
57
|
+
]);
|
|
58
|
+
/** Compute the closed (off-screen) translateY. */
|
|
59
|
+
const getClosedTranslateY = (0, react.useCallback)(() => {
|
|
60
|
+
"worklet";
|
|
61
|
+
return containerHeight.value + bottomInsetPx;
|
|
62
|
+
}, [containerHeight, bottomInsetPx]);
|
|
63
|
+
/** Emit snap point change callback on the JS thread. */
|
|
64
|
+
const emitSnapChange = (0, react.useCallback)((index) => {
|
|
65
|
+
onSnapPointChange?.(index, resolvedSnapPoints[index]);
|
|
66
|
+
}, [onSnapPointChange, resolvedSnapPoints]);
|
|
67
|
+
return {
|
|
68
|
+
resolvedSnapPoints,
|
|
69
|
+
translateY,
|
|
70
|
+
activeSnapIndex,
|
|
71
|
+
isAnimating,
|
|
72
|
+
getTranslateYForSnap,
|
|
73
|
+
getClosedTranslateY,
|
|
74
|
+
animateToSnap: (0, react.useCallback)((index) => {
|
|
75
|
+
const clamped = require_components_BottomSheet_utils.clampIndex(index, resolvedSnapPoints.length);
|
|
76
|
+
const targetY = getTranslateYForSnap(clamped);
|
|
77
|
+
isAnimating.value = true;
|
|
78
|
+
activeSnapIndex.value = clamped;
|
|
79
|
+
translateY.value = (0, react_native_reanimated.withSpring)(targetY, SHEET_SPRING_CONFIG, (finished) => {
|
|
80
|
+
"worklet";
|
|
81
|
+
if (finished) isAnimating.value = false;
|
|
82
|
+
});
|
|
83
|
+
emitSnapChange(clamped);
|
|
84
|
+
}, [
|
|
85
|
+
resolvedSnapPoints,
|
|
86
|
+
getTranslateYForSnap,
|
|
87
|
+
isAnimating,
|
|
88
|
+
activeSnapIndex,
|
|
89
|
+
translateY,
|
|
90
|
+
emitSnapChange
|
|
91
|
+
]),
|
|
92
|
+
animateToClose: (0, react.useCallback)((onComplete) => {
|
|
93
|
+
const targetY = getClosedTranslateY();
|
|
94
|
+
isAnimating.value = true;
|
|
95
|
+
translateY.value = (0, react_native_reanimated.withSpring)(targetY, SHEET_SPRING_CONFIG, (finished) => {
|
|
96
|
+
"worklet";
|
|
97
|
+
if (finished) {
|
|
98
|
+
isAnimating.value = false;
|
|
99
|
+
if (onComplete) (0, react_native_reanimated.runOnJS)(onComplete)();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}, [
|
|
103
|
+
getClosedTranslateY,
|
|
104
|
+
isAnimating,
|
|
105
|
+
translateY
|
|
106
|
+
]),
|
|
107
|
+
animateToSnapWorklet: (0, react.useCallback)((index) => {
|
|
108
|
+
"worklet";
|
|
109
|
+
const clamped = require_components_BottomSheet_utils.clampIndex(index, resolvedSnapPoints.length);
|
|
110
|
+
const targetY = getTranslateYForSnap(clamped);
|
|
111
|
+
isAnimating.value = true;
|
|
112
|
+
activeSnapIndex.value = clamped;
|
|
113
|
+
translateY.value = (0, react_native_reanimated.withSpring)(targetY, SHEET_SPRING_CONFIG, (finished) => {
|
|
114
|
+
if (finished) isAnimating.value = false;
|
|
115
|
+
});
|
|
116
|
+
(0, react_native_reanimated.runOnJS)(emitSnapChange)(clamped);
|
|
117
|
+
}, [
|
|
118
|
+
resolvedSnapPoints,
|
|
119
|
+
getTranslateYForSnap,
|
|
120
|
+
isAnimating,
|
|
121
|
+
activeSnapIndex,
|
|
122
|
+
translateY,
|
|
123
|
+
emitSnapChange
|
|
124
|
+
]),
|
|
125
|
+
animateToCloseWorklet: (0, react.useCallback)(() => {
|
|
126
|
+
"worklet";
|
|
127
|
+
const targetY = getClosedTranslateY();
|
|
128
|
+
isAnimating.value = true;
|
|
129
|
+
translateY.value = (0, react_native_reanimated.withSpring)(targetY, SHEET_SPRING_CONFIG, (finished) => {
|
|
130
|
+
if (finished) isAnimating.value = false;
|
|
131
|
+
});
|
|
132
|
+
}, [
|
|
133
|
+
getClosedTranslateY,
|
|
134
|
+
isAnimating,
|
|
135
|
+
translateY
|
|
136
|
+
])
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
exports.SHEET_SPRING_CONFIG = SHEET_SPRING_CONFIG;
|
|
142
|
+
exports.useBottomSheetSnapModel = useBottomSheetSnapModel;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
import { BottomSheetHeight } from "./types.cjs";
|
|
3
|
+
import { SharedValue } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
//#region src/components/BottomSheet/useBottomSheetSnapModel.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Spring configuration for sheet snap/close animations.
|
|
8
|
+
* Uses the UDS `smooth['3']` motion preset.
|
|
9
|
+
*/
|
|
10
|
+
declare const SHEET_SPRING_CONFIG: {
|
|
11
|
+
readonly damping: number;
|
|
12
|
+
readonly stiffness: number;
|
|
13
|
+
readonly mass: 1;
|
|
14
|
+
};
|
|
15
|
+
/** @internal */
|
|
16
|
+
interface UseBottomSheetSnapModelParams {
|
|
17
|
+
snapPointsProp?: BottomSheetHeight[];
|
|
18
|
+
height?: BottomSheetHeight;
|
|
19
|
+
defaultSnapPointIndex: number;
|
|
20
|
+
snapPointIndexProp?: number;
|
|
21
|
+
onSnapPointChange?: (index: number, height: BottomSheetHeight) => void;
|
|
22
|
+
containerHeight: SharedValue<number>;
|
|
23
|
+
/** Bottom inset in px (margin + safe area). */
|
|
24
|
+
bottomInsetPx: number;
|
|
25
|
+
/** Top safe-area inset in px — limits maximum sheet height. */
|
|
26
|
+
topInsetPx: number;
|
|
27
|
+
/** Horizontal margin in px (currently informational, not used in snap math). */
|
|
28
|
+
sideInsetPx: number;
|
|
29
|
+
/** Whether margins collapse at the max snap point. */
|
|
30
|
+
fullWidthAtMaxSnap: boolean;
|
|
31
|
+
/** Bottom inset at max snap when fullWidthAtMaxSnap (safe area only, no margin). */
|
|
32
|
+
expandedBottomInsetPx: number;
|
|
33
|
+
}
|
|
34
|
+
interface UseBottomSheetSnapModelResult {
|
|
35
|
+
/** The resolved snap points array. */
|
|
36
|
+
resolvedSnapPoints: BottomSheetHeight[];
|
|
37
|
+
/** Animated translateY position of the sheet. */
|
|
38
|
+
translateY: SharedValue<number>;
|
|
39
|
+
/** Current active snap index. */
|
|
40
|
+
activeSnapIndex: SharedValue<number>;
|
|
41
|
+
/** Whether the sheet is currently animating. */
|
|
42
|
+
isAnimating: SharedValue<boolean>;
|
|
43
|
+
/** Compute translateY for a given snap index (worklet). */
|
|
44
|
+
getTranslateYForSnap: (index: number) => number;
|
|
45
|
+
/** Compute the closed translateY position (worklet). */
|
|
46
|
+
getClosedTranslateY: () => number;
|
|
47
|
+
/** Animate to a specific snap index. */
|
|
48
|
+
animateToSnap: (index: number) => void;
|
|
49
|
+
/** Animate to the closed position. Optional callback fires on JS thread when complete. */
|
|
50
|
+
animateToClose: (onComplete?: () => void) => void;
|
|
51
|
+
/** Animate to a specific snap index from within a worklet. */
|
|
52
|
+
animateToSnapWorklet: (index: number) => void;
|
|
53
|
+
/** Animate to the closed position from within a worklet. */
|
|
54
|
+
animateToCloseWorklet: () => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Manages the snap-point position model for the bottom sheet.
|
|
58
|
+
*
|
|
59
|
+
* Resolves snap point strings to pixel positions, provides spring-animated
|
|
60
|
+
* `animateToSnap` / `animateToClose` functions for both JS and UI threads,
|
|
61
|
+
* and exposes shared values for `translateY`, `activeSnapIndex`, and `isAnimating`.
|
|
62
|
+
*
|
|
63
|
+
* Position model: `translateY = containerHeight - snapHeightPx - bottomInsetPx`
|
|
64
|
+
*/
|
|
65
|
+
declare function useBottomSheetSnapModel({
|
|
66
|
+
snapPointsProp,
|
|
67
|
+
height,
|
|
68
|
+
defaultSnapPointIndex,
|
|
69
|
+
snapPointIndexProp,
|
|
70
|
+
onSnapPointChange,
|
|
71
|
+
containerHeight,
|
|
72
|
+
bottomInsetPx,
|
|
73
|
+
topInsetPx,
|
|
74
|
+
fullWidthAtMaxSnap,
|
|
75
|
+
expandedBottomInsetPx
|
|
76
|
+
}: UseBottomSheetSnapModelParams): UseBottomSheetSnapModelResult;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { SHEET_SPRING_CONFIG, useBottomSheetSnapModel };
|
|
79
|
+
//# sourceMappingURL=useBottomSheetSnapModel.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBottomSheetSnapModel.d.cts","names":[],"sources":["../../../src/components/BottomSheet/useBottomSheetSnapModel.ts"],"mappings":";;;;;;;AAKiD;;cAO3C,mBAAA;EAAA;;;;;UAOI,6BAAA;EACR,cAAA,GAAiB,iBAAA;EACjB,MAAA,GAAS,iBAAA;EACT,qBAAA;EACA,kBAAA;EACA,iBAAA,IAAqB,KAAA,UAAe,MAAA,EAAQ,iBAAA;EAC5C,eAAA,EAAiB,WAAA;EAAA;EAEjB,aAAA;EAF4B;EAI5B,UAAA;EATiB;EAWjB,WAAA;EAVS;EAYT,kBAAA;EAVA;EAYA,qBAAA;AAAA;AAAA,UAGQ,6BAAA;EAd4B;EAgBpC,kBAAA,EAAoB,iBAAA;EAfH;EAiBjB,UAAA,EAAY,WAAA;EAbZ;EAeA,eAAA,EAAiB,WAAA;EAXjB;EAaA,WAAA,EAAa,WAAA;EAXQ;EAarB,oBAAA,GAAuB,KAAA;EAVf;EAYR,mBAAA;;EAEA,aAAA,GAAgB,KAAA;EAVJ;EAYZ,cAAA,GAAiB,UAAA;EARJ;EAUb,oBAAA,GAAuB,KAAA;EAVC;EAYxB,qBAAA;AAAA;;;;;;;;;;iBAYO,uBAAA,CAAA;EACP,cAAA;EACA,MAAA;EACA,qBAAA;EACA,kBAAA;EACA,iBAAA;EACA,eAAA;EACA,aAAA;EACA,UAAA;EACA,kBAAA;EACA;AAAA,GACC,6BAAA,GAAgC,6BAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
import { BottomSheetHeight } from "./types.js";
|
|
3
|
+
import { SharedValue } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
//#region src/components/BottomSheet/useBottomSheetSnapModel.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Spring configuration for sheet snap/close animations.
|
|
8
|
+
* Uses the UDS `smooth['3']` motion preset.
|
|
9
|
+
*/
|
|
10
|
+
declare const SHEET_SPRING_CONFIG: {
|
|
11
|
+
readonly damping: number;
|
|
12
|
+
readonly stiffness: number;
|
|
13
|
+
readonly mass: 1;
|
|
14
|
+
};
|
|
15
|
+
/** @internal */
|
|
16
|
+
interface UseBottomSheetSnapModelParams {
|
|
17
|
+
snapPointsProp?: BottomSheetHeight[];
|
|
18
|
+
height?: BottomSheetHeight;
|
|
19
|
+
defaultSnapPointIndex: number;
|
|
20
|
+
snapPointIndexProp?: number;
|
|
21
|
+
onSnapPointChange?: (index: number, height: BottomSheetHeight) => void;
|
|
22
|
+
containerHeight: SharedValue<number>;
|
|
23
|
+
/** Bottom inset in px (margin + safe area). */
|
|
24
|
+
bottomInsetPx: number;
|
|
25
|
+
/** Top safe-area inset in px — limits maximum sheet height. */
|
|
26
|
+
topInsetPx: number;
|
|
27
|
+
/** Horizontal margin in px (currently informational, not used in snap math). */
|
|
28
|
+
sideInsetPx: number;
|
|
29
|
+
/** Whether margins collapse at the max snap point. */
|
|
30
|
+
fullWidthAtMaxSnap: boolean;
|
|
31
|
+
/** Bottom inset at max snap when fullWidthAtMaxSnap (safe area only, no margin). */
|
|
32
|
+
expandedBottomInsetPx: number;
|
|
33
|
+
}
|
|
34
|
+
interface UseBottomSheetSnapModelResult {
|
|
35
|
+
/** The resolved snap points array. */
|
|
36
|
+
resolvedSnapPoints: BottomSheetHeight[];
|
|
37
|
+
/** Animated translateY position of the sheet. */
|
|
38
|
+
translateY: SharedValue<number>;
|
|
39
|
+
/** Current active snap index. */
|
|
40
|
+
activeSnapIndex: SharedValue<number>;
|
|
41
|
+
/** Whether the sheet is currently animating. */
|
|
42
|
+
isAnimating: SharedValue<boolean>;
|
|
43
|
+
/** Compute translateY for a given snap index (worklet). */
|
|
44
|
+
getTranslateYForSnap: (index: number) => number;
|
|
45
|
+
/** Compute the closed translateY position (worklet). */
|
|
46
|
+
getClosedTranslateY: () => number;
|
|
47
|
+
/** Animate to a specific snap index. */
|
|
48
|
+
animateToSnap: (index: number) => void;
|
|
49
|
+
/** Animate to the closed position. Optional callback fires on JS thread when complete. */
|
|
50
|
+
animateToClose: (onComplete?: () => void) => void;
|
|
51
|
+
/** Animate to a specific snap index from within a worklet. */
|
|
52
|
+
animateToSnapWorklet: (index: number) => void;
|
|
53
|
+
/** Animate to the closed position from within a worklet. */
|
|
54
|
+
animateToCloseWorklet: () => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Manages the snap-point position model for the bottom sheet.
|
|
58
|
+
*
|
|
59
|
+
* Resolves snap point strings to pixel positions, provides spring-animated
|
|
60
|
+
* `animateToSnap` / `animateToClose` functions for both JS and UI threads,
|
|
61
|
+
* and exposes shared values for `translateY`, `activeSnapIndex`, and `isAnimating`.
|
|
62
|
+
*
|
|
63
|
+
* Position model: `translateY = containerHeight - snapHeightPx - bottomInsetPx`
|
|
64
|
+
*/
|
|
65
|
+
declare function useBottomSheetSnapModel({
|
|
66
|
+
snapPointsProp,
|
|
67
|
+
height,
|
|
68
|
+
defaultSnapPointIndex,
|
|
69
|
+
snapPointIndexProp,
|
|
70
|
+
onSnapPointChange,
|
|
71
|
+
containerHeight,
|
|
72
|
+
bottomInsetPx,
|
|
73
|
+
topInsetPx,
|
|
74
|
+
fullWidthAtMaxSnap,
|
|
75
|
+
expandedBottomInsetPx
|
|
76
|
+
}: UseBottomSheetSnapModelParams): UseBottomSheetSnapModelResult;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { SHEET_SPRING_CONFIG, useBottomSheetSnapModel };
|
|
79
|
+
//# sourceMappingURL=useBottomSheetSnapModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBottomSheetSnapModel.d.ts","names":[],"sources":["../../../src/components/BottomSheet/useBottomSheetSnapModel.ts"],"mappings":";;;;;;;AAKiD;;cAO3C,mBAAA;EAAA;;;;;UAOI,6BAAA;EACR,cAAA,GAAiB,iBAAA;EACjB,MAAA,GAAS,iBAAA;EACT,qBAAA;EACA,kBAAA;EACA,iBAAA,IAAqB,KAAA,UAAe,MAAA,EAAQ,iBAAA;EAC5C,eAAA,EAAiB,WAAA;EAAA;EAEjB,aAAA;EAF4B;EAI5B,UAAA;EATiB;EAWjB,WAAA;EAVS;EAYT,kBAAA;EAVA;EAYA,qBAAA;AAAA;AAAA,UAGQ,6BAAA;EAd4B;EAgBpC,kBAAA,EAAoB,iBAAA;EAfH;EAiBjB,UAAA,EAAY,WAAA;EAbZ;EAeA,eAAA,EAAiB,WAAA;EAXjB;EAaA,WAAA,EAAa,WAAA;EAXQ;EAarB,oBAAA,GAAuB,KAAA;EAVf;EAYR,mBAAA;;EAEA,aAAA,GAAgB,KAAA;EAVJ;EAYZ,cAAA,GAAiB,UAAA;EARJ;EAUb,oBAAA,GAAuB,KAAA;EAVC;EAYxB,qBAAA;AAAA;;;;;;;;;;iBAYO,uBAAA,CAAA;EACP,cAAA;EACA,MAAA;EACA,qBAAA;EACA,kBAAA;EACA,iBAAA;EACA,eAAA;EACA,aAAA;EACA,UAAA;EACA,kBAAA;EACA;AAAA,GACC,6BAAA,GAAgC,6BAAA"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
import { MOTION_CONFIG } from "../../motion.js";
|
|
3
|
+
import { DEFAULT_SNAP_POINT, clampIndex, resolveHeightToPx } from "./utils.js";
|
|
4
|
+
import { useCallback, useMemo } from "react";
|
|
5
|
+
import { runOnJS, useSharedValue, withSpring } from "react-native-reanimated";
|
|
6
|
+
|
|
7
|
+
//#region src/components/BottomSheet/useBottomSheetSnapModel.ts
|
|
8
|
+
/**
|
|
9
|
+
* Spring configuration for sheet snap/close animations.
|
|
10
|
+
* Uses the UDS `smooth['3']` motion preset.
|
|
11
|
+
*/
|
|
12
|
+
const SHEET_SPRING_CONFIG = {
|
|
13
|
+
damping: MOTION_CONFIG.smooth["3"].damping,
|
|
14
|
+
stiffness: MOTION_CONFIG.smooth["3"].stiffness,
|
|
15
|
+
mass: 1
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Manages the snap-point position model for the bottom sheet.
|
|
19
|
+
*
|
|
20
|
+
* Resolves snap point strings to pixel positions, provides spring-animated
|
|
21
|
+
* `animateToSnap` / `animateToClose` functions for both JS and UI threads,
|
|
22
|
+
* and exposes shared values for `translateY`, `activeSnapIndex`, and `isAnimating`.
|
|
23
|
+
*
|
|
24
|
+
* Position model: `translateY = containerHeight - snapHeightPx - bottomInsetPx`
|
|
25
|
+
*/
|
|
26
|
+
function useBottomSheetSnapModel({ snapPointsProp, height, defaultSnapPointIndex, snapPointIndexProp, onSnapPointChange, containerHeight, bottomInsetPx, topInsetPx, fullWidthAtMaxSnap, expandedBottomInsetPx }) {
|
|
27
|
+
const resolvedSnapPoints = useMemo(() => {
|
|
28
|
+
if (snapPointsProp?.length) return snapPointsProp;
|
|
29
|
+
if (height !== void 0) return [height];
|
|
30
|
+
return [DEFAULT_SNAP_POINT];
|
|
31
|
+
}, [height, snapPointsProp]);
|
|
32
|
+
const translateY = useSharedValue(9999);
|
|
33
|
+
const activeSnapIndex = useSharedValue(clampIndex(snapPointIndexProp ?? defaultSnapPointIndex, resolvedSnapPoints.length));
|
|
34
|
+
const isAnimating = useSharedValue(false);
|
|
35
|
+
/**
|
|
36
|
+
* Compute translateY for a snap index.
|
|
37
|
+
* Position model: translateY = containerHeight - snapHeightPx - bottomInsetPx
|
|
38
|
+
*/
|
|
39
|
+
const getTranslateYForSnap = useCallback((index) => {
|
|
40
|
+
"worklet";
|
|
41
|
+
const clamped = clampIndex(index, resolvedSnapPoints.length);
|
|
42
|
+
const sp = resolvedSnapPoints[clamped];
|
|
43
|
+
const heightPx = resolveHeightToPx(sp, containerHeight.value);
|
|
44
|
+
const effectiveBottomInset = fullWidthAtMaxSnap && clamped === resolvedSnapPoints.length - 1 ? expandedBottomInsetPx : bottomInsetPx;
|
|
45
|
+
const maxHeight = containerHeight.value - effectiveBottomInset - topInsetPx;
|
|
46
|
+
const clampedHeight = Math.max(0, Math.min(heightPx, maxHeight));
|
|
47
|
+
return containerHeight.value - clampedHeight - effectiveBottomInset;
|
|
48
|
+
}, [
|
|
49
|
+
resolvedSnapPoints,
|
|
50
|
+
containerHeight,
|
|
51
|
+
bottomInsetPx,
|
|
52
|
+
topInsetPx,
|
|
53
|
+
fullWidthAtMaxSnap,
|
|
54
|
+
expandedBottomInsetPx
|
|
55
|
+
]);
|
|
56
|
+
/** Compute the closed (off-screen) translateY. */
|
|
57
|
+
const getClosedTranslateY = useCallback(() => {
|
|
58
|
+
"worklet";
|
|
59
|
+
return containerHeight.value + bottomInsetPx;
|
|
60
|
+
}, [containerHeight, bottomInsetPx]);
|
|
61
|
+
/** Emit snap point change callback on the JS thread. */
|
|
62
|
+
const emitSnapChange = useCallback((index) => {
|
|
63
|
+
onSnapPointChange?.(index, resolvedSnapPoints[index]);
|
|
64
|
+
}, [onSnapPointChange, resolvedSnapPoints]);
|
|
65
|
+
return {
|
|
66
|
+
resolvedSnapPoints,
|
|
67
|
+
translateY,
|
|
68
|
+
activeSnapIndex,
|
|
69
|
+
isAnimating,
|
|
70
|
+
getTranslateYForSnap,
|
|
71
|
+
getClosedTranslateY,
|
|
72
|
+
animateToSnap: useCallback((index) => {
|
|
73
|
+
const clamped = clampIndex(index, resolvedSnapPoints.length);
|
|
74
|
+
const targetY = getTranslateYForSnap(clamped);
|
|
75
|
+
isAnimating.value = true;
|
|
76
|
+
activeSnapIndex.value = clamped;
|
|
77
|
+
translateY.value = withSpring(targetY, SHEET_SPRING_CONFIG, (finished) => {
|
|
78
|
+
"worklet";
|
|
79
|
+
if (finished) isAnimating.value = false;
|
|
80
|
+
});
|
|
81
|
+
emitSnapChange(clamped);
|
|
82
|
+
}, [
|
|
83
|
+
resolvedSnapPoints,
|
|
84
|
+
getTranslateYForSnap,
|
|
85
|
+
isAnimating,
|
|
86
|
+
activeSnapIndex,
|
|
87
|
+
translateY,
|
|
88
|
+
emitSnapChange
|
|
89
|
+
]),
|
|
90
|
+
animateToClose: useCallback((onComplete) => {
|
|
91
|
+
const targetY = getClosedTranslateY();
|
|
92
|
+
isAnimating.value = true;
|
|
93
|
+
translateY.value = withSpring(targetY, SHEET_SPRING_CONFIG, (finished) => {
|
|
94
|
+
"worklet";
|
|
95
|
+
if (finished) {
|
|
96
|
+
isAnimating.value = false;
|
|
97
|
+
if (onComplete) runOnJS(onComplete)();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}, [
|
|
101
|
+
getClosedTranslateY,
|
|
102
|
+
isAnimating,
|
|
103
|
+
translateY
|
|
104
|
+
]),
|
|
105
|
+
animateToSnapWorklet: useCallback((index) => {
|
|
106
|
+
"worklet";
|
|
107
|
+
const clamped = clampIndex(index, resolvedSnapPoints.length);
|
|
108
|
+
const targetY = getTranslateYForSnap(clamped);
|
|
109
|
+
isAnimating.value = true;
|
|
110
|
+
activeSnapIndex.value = clamped;
|
|
111
|
+
translateY.value = withSpring(targetY, SHEET_SPRING_CONFIG, (finished) => {
|
|
112
|
+
if (finished) isAnimating.value = false;
|
|
113
|
+
});
|
|
114
|
+
runOnJS(emitSnapChange)(clamped);
|
|
115
|
+
}, [
|
|
116
|
+
resolvedSnapPoints,
|
|
117
|
+
getTranslateYForSnap,
|
|
118
|
+
isAnimating,
|
|
119
|
+
activeSnapIndex,
|
|
120
|
+
translateY,
|
|
121
|
+
emitSnapChange
|
|
122
|
+
]),
|
|
123
|
+
animateToCloseWorklet: useCallback(() => {
|
|
124
|
+
"worklet";
|
|
125
|
+
const targetY = getClosedTranslateY();
|
|
126
|
+
isAnimating.value = true;
|
|
127
|
+
translateY.value = withSpring(targetY, SHEET_SPRING_CONFIG, (finished) => {
|
|
128
|
+
if (finished) isAnimating.value = false;
|
|
129
|
+
});
|
|
130
|
+
}, [
|
|
131
|
+
getClosedTranslateY,
|
|
132
|
+
isAnimating,
|
|
133
|
+
translateY
|
|
134
|
+
])
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
export { SHEET_SPRING_CONFIG, useBottomSheetSnapModel };
|
|
140
|
+
//# sourceMappingURL=useBottomSheetSnapModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBottomSheetSnapModel.js","names":[],"sources":["../../../src/components/BottomSheet/useBottomSheetSnapModel.ts"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport type { SharedValue } from 'react-native-reanimated';\nimport { runOnJS, useSharedValue, withSpring } from 'react-native-reanimated';\n\nimport { MOTION_CONFIG } from '../../motion';\nimport type { BottomSheetHeight } from './types';\nimport { clampIndex, DEFAULT_SNAP_POINT, resolveHeightToPx } from './utils';\n\n/**\n * Spring configuration for sheet snap/close animations.\n * Uses the UDS `smooth['3']` motion preset.\n */\nconst SHEET_SPRING_CONFIG = {\n damping: MOTION_CONFIG.smooth['3'].damping,\n stiffness: MOTION_CONFIG.smooth['3'].stiffness,\n mass: 1,\n} as const;\n\n/** @internal */\ninterface UseBottomSheetSnapModelParams {\n snapPointsProp?: BottomSheetHeight[];\n height?: BottomSheetHeight;\n defaultSnapPointIndex: number;\n snapPointIndexProp?: number;\n onSnapPointChange?: (index: number, height: BottomSheetHeight) => void;\n containerHeight: SharedValue<number>;\n /** Bottom inset in px (margin + safe area). */\n bottomInsetPx: number;\n /** Top safe-area inset in px — limits maximum sheet height. */\n topInsetPx: number;\n /** Horizontal margin in px (currently informational, not used in snap math). */\n sideInsetPx: number;\n /** Whether margins collapse at the max snap point. */\n fullWidthAtMaxSnap: boolean;\n /** Bottom inset at max snap when fullWidthAtMaxSnap (safe area only, no margin). */\n expandedBottomInsetPx: number;\n}\n\ninterface UseBottomSheetSnapModelResult {\n /** The resolved snap points array. */\n resolvedSnapPoints: BottomSheetHeight[];\n /** Animated translateY position of the sheet. */\n translateY: SharedValue<number>;\n /** Current active snap index. */\n activeSnapIndex: SharedValue<number>;\n /** Whether the sheet is currently animating. */\n isAnimating: SharedValue<boolean>;\n /** Compute translateY for a given snap index (worklet). */\n getTranslateYForSnap: (index: number) => number;\n /** Compute the closed translateY position (worklet). */\n getClosedTranslateY: () => number;\n /** Animate to a specific snap index. */\n animateToSnap: (index: number) => void;\n /** Animate to the closed position. Optional callback fires on JS thread when complete. */\n animateToClose: (onComplete?: () => void) => void;\n /** Animate to a specific snap index from within a worklet. */\n animateToSnapWorklet: (index: number) => void;\n /** Animate to the closed position from within a worklet. */\n animateToCloseWorklet: () => void;\n}\n\n/**\n * Manages the snap-point position model for the bottom sheet.\n *\n * Resolves snap point strings to pixel positions, provides spring-animated\n * `animateToSnap` / `animateToClose` functions for both JS and UI threads,\n * and exposes shared values for `translateY`, `activeSnapIndex`, and `isAnimating`.\n *\n * Position model: `translateY = containerHeight - snapHeightPx - bottomInsetPx`\n */\nfunction useBottomSheetSnapModel({\n snapPointsProp,\n height,\n defaultSnapPointIndex,\n snapPointIndexProp,\n onSnapPointChange,\n containerHeight,\n bottomInsetPx,\n topInsetPx,\n fullWidthAtMaxSnap,\n expandedBottomInsetPx,\n}: UseBottomSheetSnapModelParams): UseBottomSheetSnapModelResult {\n const resolvedSnapPoints = useMemo<BottomSheetHeight[]>(() => {\n if (snapPointsProp?.length) {\n return snapPointsProp;\n }\n if (height !== undefined) {\n return [height];\n }\n return [DEFAULT_SNAP_POINT];\n }, [height, snapPointsProp]);\n\n // Start off-screen (will be set to closed position on first layout).\n const translateY = useSharedValue(9999);\n const activeSnapIndex = useSharedValue(\n clampIndex(snapPointIndexProp ?? defaultSnapPointIndex, resolvedSnapPoints.length),\n );\n const isAnimating = useSharedValue(false);\n\n /**\n * Compute translateY for a snap index.\n * Position model: translateY = containerHeight - snapHeightPx - bottomInsetPx\n */\n const getTranslateYForSnap = useCallback(\n (index: number): number => {\n 'worklet';\n const clamped = clampIndex(index, resolvedSnapPoints.length);\n const sp = resolvedSnapPoints[clamped]!;\n const heightPx = resolveHeightToPx(sp, containerHeight.value);\n // At max snap with fullWidthAtMaxSnap, margins collapse so use reduced bottom inset.\n const isExpandedMaxSnap = fullWidthAtMaxSnap && clamped === resolvedSnapPoints.length - 1;\n const effectiveBottomInset = isExpandedMaxSnap ? expandedBottomInsetPx : bottomInsetPx;\n const maxHeight = containerHeight.value - effectiveBottomInset - topInsetPx;\n const clampedHeight = Math.max(0, Math.min(heightPx, maxHeight));\n return containerHeight.value - clampedHeight - effectiveBottomInset;\n },\n [\n resolvedSnapPoints,\n containerHeight,\n bottomInsetPx,\n topInsetPx,\n fullWidthAtMaxSnap,\n expandedBottomInsetPx,\n ],\n );\n\n /** Compute the closed (off-screen) translateY. */\n const getClosedTranslateY = useCallback((): number => {\n 'worklet';\n return containerHeight.value + bottomInsetPx;\n }, [containerHeight, bottomInsetPx]);\n\n /** Emit snap point change callback on the JS thread. */\n const emitSnapChange = useCallback(\n (index: number) => {\n onSnapPointChange?.(index, resolvedSnapPoints[index]!);\n },\n [onSnapPointChange, resolvedSnapPoints],\n );\n\n /** Animate to snap index — call from JS thread. */\n const animateToSnap = useCallback(\n (index: number) => {\n const clamped = clampIndex(index, resolvedSnapPoints.length);\n const targetY = getTranslateYForSnap(clamped);\n\n isAnimating.value = true;\n activeSnapIndex.value = clamped;\n translateY.value = withSpring(targetY, SHEET_SPRING_CONFIG, (finished) => {\n 'worklet';\n if (finished) {\n isAnimating.value = false;\n }\n });\n\n emitSnapChange(clamped);\n },\n [\n resolvedSnapPoints,\n getTranslateYForSnap,\n isAnimating,\n activeSnapIndex,\n translateY,\n emitSnapChange,\n ],\n );\n\n /** Animate to closed position — call from JS thread. */\n const animateToClose = useCallback(\n (onComplete?: () => void) => {\n const targetY = getClosedTranslateY();\n isAnimating.value = true;\n translateY.value = withSpring(targetY, SHEET_SPRING_CONFIG, (finished) => {\n 'worklet';\n if (finished) {\n isAnimating.value = false;\n if (onComplete) {\n runOnJS(onComplete)();\n }\n }\n });\n },\n [getClosedTranslateY, isAnimating, translateY],\n );\n\n /** Animate to snap — safe to call from a worklet (onEnd handler). */\n const animateToSnapWorklet = useCallback(\n (index: number) => {\n 'worklet';\n const clamped = clampIndex(index, resolvedSnapPoints.length);\n const targetY = getTranslateYForSnap(clamped);\n\n isAnimating.value = true;\n activeSnapIndex.value = clamped;\n translateY.value = withSpring(targetY, SHEET_SPRING_CONFIG, (finished) => {\n if (finished) {\n isAnimating.value = false;\n }\n });\n\n runOnJS(emitSnapChange)(clamped);\n },\n [\n resolvedSnapPoints,\n getTranslateYForSnap,\n isAnimating,\n activeSnapIndex,\n translateY,\n emitSnapChange,\n ],\n );\n\n /** Animate to closed — safe to call from a worklet. */\n const animateToCloseWorklet = useCallback(() => {\n 'worklet';\n const targetY = getClosedTranslateY();\n isAnimating.value = true;\n translateY.value = withSpring(targetY, SHEET_SPRING_CONFIG, (finished) => {\n if (finished) {\n isAnimating.value = false;\n }\n });\n }, [getClosedTranslateY, isAnimating, translateY]);\n\n return {\n resolvedSnapPoints,\n translateY,\n activeSnapIndex,\n isAnimating,\n getTranslateYForSnap,\n getClosedTranslateY,\n animateToSnap,\n animateToClose,\n animateToSnapWorklet,\n animateToCloseWorklet,\n };\n}\n\nexport { SHEET_SPRING_CONFIG, useBottomSheetSnapModel };\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,sBAAsB;CAC1B,SAAS,cAAc,OAAO,KAAK;CACnC,WAAW,cAAc,OAAO,KAAK;CACrC,MAAM;CACP;;;;;;;;;;AAsDD,SAAS,wBAAwB,EAC/B,gBACA,QACA,uBACA,oBACA,mBACA,iBACA,eACA,YACA,oBACA,yBAC+D;CAC/D,MAAM,qBAAqB,cAAmC;AAC5D,MAAI,gBAAgB,OAClB,QAAO;AAET,MAAI,WAAW,OACb,QAAO,CAAC,OAAO;AAEjB,SAAO,CAAC,mBAAmB;IAC1B,CAAC,QAAQ,eAAe,CAAC;CAG5B,MAAM,aAAa,eAAe,KAAK;CACvC,MAAM,kBAAkB,eACtB,WAAW,sBAAsB,uBAAuB,mBAAmB,OAAO,CACnF;CACD,MAAM,cAAc,eAAe,MAAM;;;;;CAMzC,MAAM,uBAAuB,aAC1B,UAA0B;AACzB;EACA,MAAM,UAAU,WAAW,OAAO,mBAAmB,OAAO;EAC5D,MAAM,KAAK,mBAAmB;EAC9B,MAAM,WAAW,kBAAkB,IAAI,gBAAgB,MAAM;EAG7D,MAAM,uBADoB,sBAAsB,YAAY,mBAAmB,SAAS,IACvC,wBAAwB;EACzE,MAAM,YAAY,gBAAgB,QAAQ,uBAAuB;EACjE,MAAM,gBAAgB,KAAK,IAAI,GAAG,KAAK,IAAI,UAAU,UAAU,CAAC;AAChE,SAAO,gBAAgB,QAAQ,gBAAgB;IAEjD;EACE;EACA;EACA;EACA;EACA;EACA;EACD,CACF;;CAGD,MAAM,sBAAsB,kBAA0B;AACpD;AACA,SAAO,gBAAgB,QAAQ;IAC9B,CAAC,iBAAiB,cAAc,CAAC;;CAGpC,MAAM,iBAAiB,aACpB,UAAkB;AACjB,sBAAoB,OAAO,mBAAmB,OAAQ;IAExD,CAAC,mBAAmB,mBAAmB,CACxC;AAsFD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,eA1FoB,aACnB,UAAkB;GACjB,MAAM,UAAU,WAAW,OAAO,mBAAmB,OAAO;GAC5D,MAAM,UAAU,qBAAqB,QAAQ;AAE7C,eAAY,QAAQ;AACpB,mBAAgB,QAAQ;AACxB,cAAW,QAAQ,WAAW,SAAS,sBAAsB,aAAa;AACxE;AACA,QAAI,SACF,aAAY,QAAQ;KAEtB;AAEF,kBAAe,QAAQ;KAEzB;GACE;GACA;GACA;GACA;GACA;GACA;GACD,CACF;EAmEC,gBAhEqB,aACpB,eAA4B;GAC3B,MAAM,UAAU,qBAAqB;AACrC,eAAY,QAAQ;AACpB,cAAW,QAAQ,WAAW,SAAS,sBAAsB,aAAa;AACxE;AACA,QAAI,UAAU;AACZ,iBAAY,QAAQ;AACpB,SAAI,WACF,SAAQ,WAAW,EAAE;;KAGzB;KAEJ;GAAC;GAAqB;GAAa;GAAW,CAC/C;EAkDC,sBA/C2B,aAC1B,UAAkB;AACjB;GACA,MAAM,UAAU,WAAW,OAAO,mBAAmB,OAAO;GAC5D,MAAM,UAAU,qBAAqB,QAAQ;AAE7C,eAAY,QAAQ;AACpB,mBAAgB,QAAQ;AACxB,cAAW,QAAQ,WAAW,SAAS,sBAAsB,aAAa;AACxE,QAAI,SACF,aAAY,QAAQ;KAEtB;AAEF,WAAQ,eAAe,CAAC,QAAQ;KAElC;GACE;GACA;GACA;GACA;GACA;GACA;GACD,CACF;EAwBC,uBArB4B,kBAAkB;AAC9C;GACA,MAAM,UAAU,qBAAqB;AACrC,eAAY,QAAQ;AACpB,cAAW,QAAQ,WAAW,SAAS,sBAAsB,aAAa;AACxE,QAAI,SACF,aAAY,QAAQ;KAEtB;KACD;GAAC;GAAqB;GAAa;GAAW,CAAC;EAajD"}
|