react-native-bottom-sheet-stack 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/BottomSheet.context.js.map +1 -1
- package/lib/commonjs/BottomSheetBackdrop.js +76 -0
- package/lib/commonjs/BottomSheetBackdrop.js.map +1 -0
- package/lib/commonjs/BottomSheetHost.js +203 -37
- package/lib/commonjs/BottomSheetHost.js.map +1 -1
- package/lib/commonjs/BottomSheetManaged.js +128 -38
- package/lib/commonjs/BottomSheetManaged.js.map +1 -1
- package/lib/commonjs/BottomSheetManager.context.js.map +1 -1
- package/lib/commonjs/BottomSheetManager.provider.js +38 -13
- package/lib/commonjs/BottomSheetManager.provider.js.map +1 -1
- package/lib/commonjs/BottomSheetScaleView.js +67 -0
- package/lib/commonjs/BottomSheetScaleView.js.map +1 -0
- package/lib/commonjs/animatedRegistry.js +25 -0
- package/lib/commonjs/animatedRegistry.js.map +1 -0
- package/lib/commonjs/bottomSheet.store.js.map +1 -1
- package/lib/commonjs/bottomSheetCoordinator.js +5 -6
- package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
- package/lib/commonjs/index.js +3 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/useBottomSheetManager.js +88 -44
- package/lib/commonjs/useBottomSheetManager.js.map +1 -1
- package/lib/commonjs/useBottomSheetState.js +40 -10
- package/lib/commonjs/useBottomSheetState.js.map +1 -1
- package/lib/commonjs/useScaleAnimation.js +108 -0
- package/lib/commonjs/useScaleAnimation.js.map +1 -0
- package/lib/typescript/example/src/App.d.ts +0 -2
- package/lib/typescript/example/src/App.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetBackdrop.d.ts +12 -0
- package/lib/typescript/src/BottomSheetBackdrop.d.ts.map +1 -0
- package/lib/typescript/src/BottomSheetHost.d.ts +1 -2
- package/lib/typescript/src/BottomSheetHost.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetManaged.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetManager.context.d.ts +2 -0
- package/lib/typescript/src/BottomSheetManager.context.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetManager.provider.d.ts +4 -3
- package/lib/typescript/src/BottomSheetManager.provider.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetScaleView.d.ts +18 -0
- package/lib/typescript/src/BottomSheetScaleView.d.ts.map +1 -0
- package/lib/typescript/src/animatedRegistry.d.ts +4 -0
- package/lib/typescript/src/animatedRegistry.d.ts.map +1 -0
- package/lib/typescript/src/bottomSheet.store.d.ts +4 -3
- package/lib/typescript/src/bottomSheet.store.d.ts.map +1 -1
- package/lib/typescript/src/bottomSheetCoordinator.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetManager.d.ts.map +1 -1
- package/lib/typescript/src/useBottomSheetState.d.ts.map +1 -1
- package/lib/typescript/src/useScaleAnimation.d.ts +43 -0
- package/lib/typescript/src/useScaleAnimation.d.ts.map +1 -0
- package/package.json +9 -2
- package/src/BottomSheetBackdrop.tsx +61 -0
- package/src/BottomSheetHost.tsx +51 -13
- package/src/BottomSheetManaged.tsx +26 -33
- package/src/BottomSheetManager.context.tsx +2 -0
- package/src/BottomSheetManager.provider.tsx +10 -6
- package/src/BottomSheetScaleView.tsx +41 -0
- package/src/animatedRegistry.ts +22 -0
- package/src/bottomSheet.store.ts +124 -124
- package/src/bottomSheetCoordinator.ts +5 -6
- package/src/index.tsx +2 -4
- package/src/useBottomSheetManager.tsx +37 -48
- package/src/useBottomSheetState.ts +2 -6
- package/src/useScaleAnimation.ts +114 -0
- package/lib/commonjs/ScaleBackgroundWrapper.js +0 -71
- package/lib/commonjs/ScaleBackgroundWrapper.js.map +0 -1
- package/lib/typescript/src/ScaleBackgroundWrapper.d.ts +0 -32
- package/lib/typescript/src/ScaleBackgroundWrapper.d.ts.map +0 -1
- package/src/ScaleBackgroundWrapper.tsx +0 -97
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useAnimatedStyle,
|
|
4
|
+
useDerivedValue,
|
|
5
|
+
withTiming,
|
|
6
|
+
} from 'react-native-reanimated';
|
|
7
|
+
import {
|
|
8
|
+
useBottomSheetStore,
|
|
9
|
+
type BottomSheetStore,
|
|
10
|
+
} from './bottomSheet.store';
|
|
11
|
+
|
|
12
|
+
export interface ScaleConfig {
|
|
13
|
+
/** Scale factor when sheet is open (default: 0.92) */
|
|
14
|
+
scale?: number;
|
|
15
|
+
/** Vertical translation when sheet is open (default: 10) */
|
|
16
|
+
translateY?: number;
|
|
17
|
+
/** Border radius when sheet is open (default: 12) */
|
|
18
|
+
borderRadius?: number;
|
|
19
|
+
/** Animation duration in ms (default: 300) */
|
|
20
|
+
duration?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DEFAULT_CONFIG: Required<ScaleConfig> = {
|
|
24
|
+
scale: 0.92,
|
|
25
|
+
translateY: 10,
|
|
26
|
+
borderRadius: 12,
|
|
27
|
+
duration: 300,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the number of sheets with scaleBackground above a given element.
|
|
32
|
+
* For background wrapper, pass undefined as sheetId - returns 0 or 1 (binary).
|
|
33
|
+
* For sheets, returns the count of scaleBackground sheets above it.
|
|
34
|
+
* Uses shallow comparison internally for optimal re-renders.
|
|
35
|
+
*/
|
|
36
|
+
export function useScaleDepth(groupId: string, sheetId?: string): number {
|
|
37
|
+
const prevDepthRef = useRef(0);
|
|
38
|
+
|
|
39
|
+
const scaleDepthSelector = (state: BottomSheetStore) => {
|
|
40
|
+
const { stackOrder, sheetsById } = state;
|
|
41
|
+
|
|
42
|
+
// For background: check if ANY scaleBackground sheet is active (binary 0/1)
|
|
43
|
+
// For a sheet: count scaleBackground sheets above it in the stack
|
|
44
|
+
const startIndex = sheetId ? stackOrder.indexOf(sheetId) + 1 : 0;
|
|
45
|
+
|
|
46
|
+
if (sheetId && startIndex === 0) {
|
|
47
|
+
// Sheet not found in stack, return previous value to avoid flicker
|
|
48
|
+
return prevDepthRef.current;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let depth = 0;
|
|
52
|
+
for (let i = startIndex; i < stackOrder.length; i++) {
|
|
53
|
+
const id = stackOrder[i]!;
|
|
54
|
+
const sheet = sheetsById[id];
|
|
55
|
+
if (
|
|
56
|
+
sheet &&
|
|
57
|
+
sheet.groupId === groupId &&
|
|
58
|
+
sheet.scaleBackground &&
|
|
59
|
+
sheet.status !== 'closing'
|
|
60
|
+
) {
|
|
61
|
+
depth++;
|
|
62
|
+
// For background wrapper (no sheetId), we only need to know if there's at least one
|
|
63
|
+
// Don't accumulate - background scales once, sheets below scale cumulatively
|
|
64
|
+
if (!sheetId) {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
prevDepthRef.current = depth;
|
|
71
|
+
return depth;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return useBottomSheetStore(scaleDepthSelector);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns animated style for scale effect based on depth.
|
|
79
|
+
* Uses power scaling: scale^depth for cascading effect.
|
|
80
|
+
*/
|
|
81
|
+
export function useScaleAnimatedStyle(depth: number, config?: ScaleConfig) {
|
|
82
|
+
const {
|
|
83
|
+
scale = DEFAULT_CONFIG.scale,
|
|
84
|
+
translateY = DEFAULT_CONFIG.translateY,
|
|
85
|
+
borderRadius = DEFAULT_CONFIG.borderRadius,
|
|
86
|
+
duration = DEFAULT_CONFIG.duration,
|
|
87
|
+
} = config ?? {};
|
|
88
|
+
|
|
89
|
+
const progress = useDerivedValue(() => {
|
|
90
|
+
return withTiming(depth, { duration });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return useAnimatedStyle(() => {
|
|
94
|
+
const p = progress.value;
|
|
95
|
+
|
|
96
|
+
if (p === 0) {
|
|
97
|
+
return {
|
|
98
|
+
transform: [{ scale: 1 }, { translateY: 0 }],
|
|
99
|
+
borderRadius: 0,
|
|
100
|
+
overflow: 'visible',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const currentScale = Math.pow(scale, p);
|
|
105
|
+
const currentTranslateY = translateY * p;
|
|
106
|
+
const currentBorderRadius = Math.min(borderRadius * p, borderRadius);
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
transform: [{ scale: currentScale }, { translateY: currentTranslateY }],
|
|
110
|
+
borderRadius: currentBorderRadius,
|
|
111
|
+
overflow: 'hidden',
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ScaleBackgroundWrapper = ScaleBackgroundWrapper;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _reactNative = require("react-native");
|
|
9
|
-
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
10
|
-
var _BottomSheetManager = require("./BottomSheetManager.context");
|
|
11
|
-
var _bottomSheet = require("./bottomSheet.store");
|
|
12
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
-
/**
|
|
16
|
-
* Wraps content with iOS-style scale animation when a bottom sheet with
|
|
17
|
-
* scaleBackground: true is open. Place your main content inside this wrapper,
|
|
18
|
-
* but keep BottomSheetHost outside of it.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```tsx
|
|
22
|
-
* <BottomSheetManagerProvider id="default">
|
|
23
|
-
* <ScaleBackgroundWrapper config={{ scale: 0.92 }}>
|
|
24
|
-
* <MainContent />
|
|
25
|
-
* </ScaleBackgroundWrapper>
|
|
26
|
-
* <BottomSheetHost />
|
|
27
|
-
* </BottomSheetManagerProvider>
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
function ScaleBackgroundWrapper({
|
|
31
|
-
children,
|
|
32
|
-
config
|
|
33
|
-
}) {
|
|
34
|
-
const context = (0, _react.useContext)(_BottomSheetManager.BottomSheetManagerContext);
|
|
35
|
-
const groupId = context?.groupId ?? 'default';
|
|
36
|
-
const {
|
|
37
|
-
scale = 0.92,
|
|
38
|
-
translateY = 10,
|
|
39
|
-
borderRadius = 12,
|
|
40
|
-
duration = 300
|
|
41
|
-
} = config ?? {};
|
|
42
|
-
const hasActiveScaleSheet = (0, _bottomSheet.useBottomSheetStore)(state => state.stackOrder.some(id => {
|
|
43
|
-
const sheet = state.sheetsById[id];
|
|
44
|
-
return sheet?.groupId === groupId && sheet?.scaleBackground && sheet?.status !== 'closing';
|
|
45
|
-
}));
|
|
46
|
-
const animationProgress = (0, _reactNativeReanimated.useDerivedValue)(() => (0, _reactNativeReanimated.withTiming)(hasActiveScaleSheet ? 1 : 0, {
|
|
47
|
-
duration
|
|
48
|
-
}));
|
|
49
|
-
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
50
|
-
const progress = animationProgress.value;
|
|
51
|
-
return {
|
|
52
|
-
transform: [{
|
|
53
|
-
scale: (0, _reactNativeReanimated.interpolate)(progress, [0, 1], [1, scale])
|
|
54
|
-
}, {
|
|
55
|
-
translateY: (0, _reactNativeReanimated.interpolate)(progress, [0, 1], [0, translateY])
|
|
56
|
-
}],
|
|
57
|
-
borderRadius: (0, _reactNativeReanimated.interpolate)(progress, [0, 1], [0, borderRadius]),
|
|
58
|
-
overflow: progress > 0 ? 'hidden' : 'visible'
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
62
|
-
style: [styles.scaleWrapper, animatedStyle],
|
|
63
|
-
children: children
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
const styles = _reactNative.StyleSheet.create({
|
|
67
|
-
scaleWrapper: {
|
|
68
|
-
flex: 1
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
//# sourceMappingURL=ScaleBackgroundWrapper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_reactNativeReanimated","_interopRequireWildcard","_BottomSheetManager","_bottomSheet","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","ScaleBackgroundWrapper","children","config","context","useContext","BottomSheetManagerContext","groupId","scale","translateY","borderRadius","duration","hasActiveScaleSheet","useBottomSheetStore","state","stackOrder","some","id","sheet","sheetsById","scaleBackground","status","animationProgress","useDerivedValue","withTiming","animatedStyle","useAnimatedStyle","progress","value","transform","interpolate","overflow","jsx","View","style","styles","scaleWrapper","StyleSheet","create","flex"],"sourceRoot":"../../src","sources":["ScaleBackgroundWrapper.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAC,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CAAC,CAC/D;MACDC,YAAY,EAAE,IAAAoB,kCAAW,EAACH,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAEjB,YAAY,CAAC,CAAC;MAC9DqB,QAAQ,EAAEJ,QAAQ,GAAG,CAAC,GAAI,QAAQ,GAAc;IAClD,CAAC;EACH,CAAC,CAAC;EAEF,oBACE,IAAA/C,WAAA,CAAAoD,GAAA,EAACxD,sBAAA,CAAAW,OAAQ,CAAC8C,IAAI;IAACC,KAAK,EAAE,CAACC,MAAM,CAACC,YAAY,EAAEX,aAAa,CAAE;IAAAvB,QAAA,EACxDA;EAAQ,CACI,CAAC;AAEpB;AAEA,MAAMiC,MAAM,GAAGE,uBAAU,CAACC,MAAM,CAAC;EAC/BF,YAAY,EAAE;IACZG,IAAI,EAAE;EACR;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { type PropsWithChildren } from 'react';
|
|
2
|
-
export interface ScaleBackgroundConfig {
|
|
3
|
-
/** Scale factor when sheet is open (default: 0.92) */
|
|
4
|
-
scale?: number;
|
|
5
|
-
/** Vertical translation when sheet is open (default: 10) */
|
|
6
|
-
translateY?: number;
|
|
7
|
-
/** Border radius when sheet is open (default: 12) */
|
|
8
|
-
borderRadius?: number;
|
|
9
|
-
/** Animation duration in ms (default: 300) */
|
|
10
|
-
duration?: number;
|
|
11
|
-
}
|
|
12
|
-
interface ScaleBackgroundWrapperProps extends PropsWithChildren {
|
|
13
|
-
config?: ScaleBackgroundConfig;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Wraps content with iOS-style scale animation when a bottom sheet with
|
|
17
|
-
* scaleBackground: true is open. Place your main content inside this wrapper,
|
|
18
|
-
* but keep BottomSheetHost outside of it.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```tsx
|
|
22
|
-
* <BottomSheetManagerProvider id="default">
|
|
23
|
-
* <ScaleBackgroundWrapper config={{ scale: 0.92 }}>
|
|
24
|
-
* <MainContent />
|
|
25
|
-
* </ScaleBackgroundWrapper>
|
|
26
|
-
* <BottomSheetHost />
|
|
27
|
-
* </BottomSheetManagerProvider>
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare function ScaleBackgroundWrapper({ children, config, }: ScaleBackgroundWrapperProps): import("react/jsx-runtime").JSX.Element;
|
|
31
|
-
export {};
|
|
32
|
-
//# sourceMappingURL=ScaleBackgroundWrapper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ScaleBackgroundWrapper.d.ts","sourceRoot":"","sources":["../../../src/ScaleBackgroundWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAW3D,MAAM,WAAW,qBAAqB;IACpC,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,2BAA4B,SAAQ,iBAAiB;IAC7D,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,MAAM,GACP,EAAE,2BAA2B,2CA8C7B"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { useContext, type PropsWithChildren } from 'react';
|
|
2
|
-
import { StyleSheet } from 'react-native';
|
|
3
|
-
import Animated, {
|
|
4
|
-
interpolate,
|
|
5
|
-
useAnimatedStyle,
|
|
6
|
-
useDerivedValue,
|
|
7
|
-
withTiming,
|
|
8
|
-
} from 'react-native-reanimated';
|
|
9
|
-
import { BottomSheetManagerContext } from './BottomSheetManager.context';
|
|
10
|
-
import { useBottomSheetStore } from './bottomSheet.store';
|
|
11
|
-
|
|
12
|
-
export interface ScaleBackgroundConfig {
|
|
13
|
-
/** Scale factor when sheet is open (default: 0.92) */
|
|
14
|
-
scale?: number;
|
|
15
|
-
/** Vertical translation when sheet is open (default: 10) */
|
|
16
|
-
translateY?: number;
|
|
17
|
-
/** Border radius when sheet is open (default: 12) */
|
|
18
|
-
borderRadius?: number;
|
|
19
|
-
/** Animation duration in ms (default: 300) */
|
|
20
|
-
duration?: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface ScaleBackgroundWrapperProps extends PropsWithChildren {
|
|
24
|
-
config?: ScaleBackgroundConfig;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Wraps content with iOS-style scale animation when a bottom sheet with
|
|
29
|
-
* scaleBackground: true is open. Place your main content inside this wrapper,
|
|
30
|
-
* but keep BottomSheetHost outside of it.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* <BottomSheetManagerProvider id="default">
|
|
35
|
-
* <ScaleBackgroundWrapper config={{ scale: 0.92 }}>
|
|
36
|
-
* <MainContent />
|
|
37
|
-
* </ScaleBackgroundWrapper>
|
|
38
|
-
* <BottomSheetHost />
|
|
39
|
-
* </BottomSheetManagerProvider>
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export function ScaleBackgroundWrapper({
|
|
43
|
-
children,
|
|
44
|
-
config,
|
|
45
|
-
}: ScaleBackgroundWrapperProps) {
|
|
46
|
-
const context = useContext(BottomSheetManagerContext);
|
|
47
|
-
const groupId = context?.groupId ?? 'default';
|
|
48
|
-
|
|
49
|
-
const {
|
|
50
|
-
scale = 0.92,
|
|
51
|
-
translateY = 10,
|
|
52
|
-
borderRadius = 12,
|
|
53
|
-
duration = 300,
|
|
54
|
-
} = config ?? {};
|
|
55
|
-
|
|
56
|
-
const hasActiveScaleSheet = useBottomSheetStore((state) =>
|
|
57
|
-
state.stackOrder.some((id) => {
|
|
58
|
-
const sheet = state.sheetsById[id];
|
|
59
|
-
return (
|
|
60
|
-
sheet?.groupId === groupId &&
|
|
61
|
-
sheet?.scaleBackground &&
|
|
62
|
-
sheet?.status !== 'closing'
|
|
63
|
-
);
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const animationProgress = useDerivedValue(() =>
|
|
68
|
-
withTiming(hasActiveScaleSheet ? 1 : 0, {
|
|
69
|
-
duration,
|
|
70
|
-
})
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const animatedStyle = useAnimatedStyle(() => {
|
|
74
|
-
const progress = animationProgress.value;
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
transform: [
|
|
78
|
-
{ scale: interpolate(progress, [0, 1], [1, scale]) },
|
|
79
|
-
{ translateY: interpolate(progress, [0, 1], [0, translateY]) },
|
|
80
|
-
],
|
|
81
|
-
borderRadius: interpolate(progress, [0, 1], [0, borderRadius]),
|
|
82
|
-
overflow: progress > 0 ? ('hidden' as const) : ('visible' as const),
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<Animated.View style={[styles.scaleWrapper, animatedStyle]}>
|
|
88
|
-
{children}
|
|
89
|
-
</Animated.View>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const styles = StyleSheet.create({
|
|
94
|
-
scaleWrapper: {
|
|
95
|
-
flex: 1,
|
|
96
|
-
},
|
|
97
|
-
});
|