react-native-bottom-sheet-stack 1.7.3 → 1.7.5

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.
Files changed (53) hide show
  1. package/lib/commonjs/BottomSheetBackdrop.js +51 -27
  2. package/lib/commonjs/BottomSheetBackdrop.js.map +1 -1
  3. package/lib/commonjs/BottomSheetManaged.js +52 -46
  4. package/lib/commonjs/BottomSheetManaged.js.map +1 -1
  5. package/lib/commonjs/BottomSheetPersistent.js +49 -24
  6. package/lib/commonjs/BottomSheetPersistent.js.map +1 -1
  7. package/lib/commonjs/BottomSheetPortal.js +15 -8
  8. package/lib/commonjs/BottomSheetPortal.js.map +1 -1
  9. package/lib/commonjs/QueueItem.js +81 -64
  10. package/lib/commonjs/QueueItem.js.map +1 -1
  11. package/lib/commonjs/animatedRegistry.js +22 -6
  12. package/lib/commonjs/animatedRegistry.js.map +1 -1
  13. package/lib/commonjs/bottomSheetCoordinator.js +1 -1
  14. package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
  15. package/lib/commonjs/index.js +13 -0
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/store/store.js +8 -1
  18. package/lib/commonjs/store/store.js.map +1 -1
  19. package/lib/commonjs/useTracePropChanges.js +37 -0
  20. package/lib/commonjs/useTracePropChanges.js.map +1 -0
  21. package/lib/typescript/example/src/App.d.ts.map +1 -1
  22. package/lib/typescript/example/src/components/BottomSheetDebugMonitor.d.ts +13 -0
  23. package/lib/typescript/example/src/components/BottomSheetDebugMonitor.d.ts.map +1 -0
  24. package/lib/typescript/example/src/screens/HomeScreen.d.ts.map +1 -1
  25. package/lib/typescript/example/src/sheets/PersistentWithNestedPortal.d.ts +6 -0
  26. package/lib/typescript/example/src/sheets/PersistentWithNestedPortal.d.ts.map +1 -0
  27. package/lib/typescript/example/src/sheets/index.d.ts +1 -0
  28. package/lib/typescript/example/src/sheets/index.d.ts.map +1 -1
  29. package/lib/typescript/src/BottomSheetBackdrop.d.ts +1 -2
  30. package/lib/typescript/src/BottomSheetBackdrop.d.ts.map +1 -1
  31. package/lib/typescript/src/BottomSheetManaged.d.ts.map +1 -1
  32. package/lib/typescript/src/BottomSheetPersistent.d.ts.map +1 -1
  33. package/lib/typescript/src/BottomSheetPortal.d.ts.map +1 -1
  34. package/lib/typescript/src/QueueItem.d.ts.map +1 -1
  35. package/lib/typescript/src/animatedRegistry.d.ts +7 -1
  36. package/lib/typescript/src/animatedRegistry.d.ts.map +1 -1
  37. package/lib/typescript/src/bottomSheetCoordinator.d.ts.map +1 -1
  38. package/lib/typescript/src/index.d.ts +2 -1
  39. package/lib/typescript/src/index.d.ts.map +1 -1
  40. package/lib/typescript/src/store/store.d.ts.map +1 -1
  41. package/lib/typescript/src/useTracePropChanges.d.ts +2 -0
  42. package/lib/typescript/src/useTracePropChanges.d.ts.map +1 -0
  43. package/package.json +1 -1
  44. package/src/BottomSheetBackdrop.tsx +21 -8
  45. package/src/BottomSheetManaged.tsx +21 -9
  46. package/src/BottomSheetPersistent.tsx +18 -10
  47. package/src/BottomSheetPortal.tsx +12 -9
  48. package/src/QueueItem.tsx +31 -20
  49. package/src/animatedRegistry.ts +23 -7
  50. package/src/bottomSheetCoordinator.ts +4 -1
  51. package/src/index.tsx +6 -1
  52. package/src/store/store.ts +13 -2
  53. package/src/useTracePropChanges.ts +27 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,KAAK,2BAA2B,GACjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,2BAA2B,GACjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,oBAAoB,EACpB,KAAK,0BAA0B,GAChC,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EACV,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,yBAAyB,EACzB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,KAAK,2BAA2B,GACjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,2BAA2B,GACjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,oBAAoB,EACpB,KAAK,0BAA0B,GAChC,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EACV,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,yBAAyB,EACzB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../../src/store/store.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAElE,eAAO,MAAM,mBAAmB;;;;;;;;EA+J/B,CAAC"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../../src/store/store.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAElE,eAAO,MAAM,mBAAmB;;;;;;;;EA0K/B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function useTracePropChanges(componentName: string, props: Record<string, any>): void;
2
+ //# sourceMappingURL=useTracePropChanges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTracePropChanges.d.ts","sourceRoot":"","sources":["../../../src/useTracePropChanges.ts"],"names":[],"mappings":"AAEA,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAsB3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bottom-sheet-stack",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "Bottom Sheet Stack Manager",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "lib/commonjs/index.js",
@@ -1,3 +1,4 @@
1
+ import { useEffect, useState } from 'react';
1
2
  import { Pressable, StyleSheet } from 'react-native';
2
3
  import Animated, {
3
4
  Extrapolation,
@@ -5,17 +6,27 @@ import Animated, {
5
6
  useAnimatedStyle,
6
7
  } from 'react-native-reanimated';
7
8
  import { getAnimatedIndex } from './animatedRegistry';
9
+ import { useStartClosing } from './store';
8
10
 
9
11
  interface BottomSheetBackdropProps {
10
12
  sheetId: string;
11
- onPress?: () => void;
12
13
  }
13
14
 
14
- export function BottomSheetBackdrop({
15
- sheetId,
16
- onPress,
17
- }: BottomSheetBackdropProps) {
15
+ export function BottomSheetBackdrop({ sheetId }: BottomSheetBackdropProps) {
18
16
  const animatedIndex = getAnimatedIndex(sheetId);
17
+ const startClosing = useStartClosing();
18
+
19
+ if (!animatedIndex) {
20
+ throw new Error('animatedIndex must be defined in BottomSheetBackdrop');
21
+ }
22
+
23
+ const [initialized, setInitialized] = useState(false);
24
+
25
+ useEffect(() => {
26
+ setTimeout(() => {
27
+ setInitialized(true);
28
+ }, 64);
29
+ }, []);
19
30
 
20
31
  const animatedStyle = useAnimatedStyle(() => {
21
32
  const opacity = interpolate(
@@ -28,12 +39,14 @@ export function BottomSheetBackdrop({
28
39
  return { opacity };
29
40
  });
30
41
 
42
+ if (!initialized) {
43
+ return null;
44
+ }
45
+
31
46
  return (
32
47
  <Pressable
33
48
  style={StyleSheet.absoluteFillObject}
34
- onPress={() => {
35
- onPress?.();
36
- }}
49
+ onPress={() => startClosing(sheetId)}
37
50
  >
38
51
  <Animated.View
39
52
  style={[StyleSheet.absoluteFillObject, animatedStyle, styles.backdrop]}
@@ -5,9 +5,10 @@ import BottomSheetOriginal, {
5
5
  import { type BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
6
6
  import React from 'react';
7
7
 
8
+ import { useAnimatedReaction } from 'react-native-reanimated';
8
9
  import { getAnimatedIndex } from './animatedRegistry';
9
- import { useBottomSheetDefaultIndex } from './BottomSheetDefaultIndex.context';
10
10
  import { createSheetEventHandlers } from './bottomSheetCoordinator';
11
+ import { useBottomSheetDefaultIndex } from './BottomSheetDefaultIndex.context';
11
12
  import { useBottomSheetRefContext } from './BottomSheetRef.context';
12
13
  import { useBottomSheetContext } from './useBottomSheetContext';
13
14
 
@@ -39,24 +40,35 @@ export const BottomSheetManaged = React.forwardRef<
39
40
  const ref = contextRef ?? forwardedRef;
40
41
 
41
42
  const defaultIndex = useBottomSheetDefaultIndex();
43
+ const contextAnimatedIndex = getAnimatedIndex(id);
44
+
45
+ if (!contextAnimatedIndex) {
46
+ throw new Error('animatedIndex must be defined in BottomSheetManaged');
47
+ }
48
+
49
+ useAnimatedReaction(
50
+ () => contextAnimatedIndex.value,
51
+ (value) => {
52
+ externalAnimatedIndex?.set(value);
53
+ }
54
+ );
42
55
 
43
- const animatedIndex = externalAnimatedIndex ?? getAnimatedIndex(id);
44
56
  const { handleAnimate, handleChange, handleClose } =
45
57
  createSheetEventHandlers(id);
46
58
 
47
59
  const wrappedOnAnimate: BottomSheetProps['onAnimate'] = (
48
- fromIndex: number,
49
- toIndex: number,
50
- fromPosition: number,
51
- toPosition: number
60
+ fromIndex,
61
+ toIndex,
62
+ fromPosition,
63
+ toPosition
52
64
  ) => {
53
65
  handleAnimate(fromIndex, toIndex);
54
66
  onAnimate?.(fromIndex, toIndex, fromPosition, toPosition);
55
67
  };
56
68
 
57
69
  const wrappedOnChange: BottomSheetProps['onChange'] = (
58
- index: number,
59
- position: number,
70
+ index,
71
+ position,
60
72
  type
61
73
  ) => {
62
74
  handleChange(index);
@@ -80,7 +92,7 @@ export const BottomSheetManaged = React.forwardRef<
80
92
  ref={ref}
81
93
  {...props}
82
94
  index={defaultIndex}
83
- animatedIndex={animatedIndex}
95
+ animatedIndex={contextAnimatedIndex}
84
96
  onChange={wrappedOnChange}
85
97
  onClose={wrappedOnClose}
86
98
  onAnimate={wrappedOnAnimate}
@@ -1,10 +1,16 @@
1
1
  import type { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
2
2
  import React, { useEffect, useRef } from 'react';
3
3
 
4
- import { useMount, useSheetExists, useUnmount } from './bottomSheet.store';
4
+ import { Portal } from 'react-native-teleport';
5
+ import { BottomSheetContext } from './BottomSheet.context';
6
+ import {
7
+ useMount,
8
+ useSheetExists,
9
+ useSheetPortalSession,
10
+ useUnmount,
11
+ } from './bottomSheet.store';
5
12
  import { BottomSheetDefaultIndexContext } from './BottomSheetDefaultIndex.context';
6
13
  import { useMaybeBottomSheetManagerContext } from './BottomSheetManager.provider';
7
- import { BottomSheetPortal } from './BottomSheetPortal';
8
14
  import { BottomSheetRefContext } from './BottomSheetRef.context';
9
15
  import type { BottomSheetPortalId } from './portal.types';
10
16
  import { setSheetRef } from './refsMap';
@@ -23,7 +29,7 @@ export function BottomSheetPersistent({
23
29
  const mount = useMount();
24
30
  const unmount = useUnmount();
25
31
  const sheetExists = useSheetExists(id);
26
-
32
+ const portalSession = useSheetPortalSession(id);
27
33
  const sheetRef = useRef<BottomSheetMethods>(null);
28
34
  const groupId = bottomSheetManagerContext?.groupId || 'default';
29
35
 
@@ -49,12 +55,14 @@ export function BottomSheetPersistent({
49
55
  }
50
56
 
51
57
  return (
52
- <BottomSheetPortal id={id}>
53
- <BottomSheetDefaultIndexContext.Provider value={{ defaultIndex: -1 }}>
54
- <BottomSheetRefContext.Provider value={sheetRef}>
55
- {children}
56
- </BottomSheetRefContext.Provider>
57
- </BottomSheetDefaultIndexContext.Provider>
58
- </BottomSheetPortal>
58
+ <Portal hostName={`bottomsheet-${id}-${portalSession}`}>
59
+ <BottomSheetContext.Provider value={{ id }}>
60
+ <BottomSheetDefaultIndexContext.Provider value={{ defaultIndex: -1 }}>
61
+ <BottomSheetRefContext.Provider value={sheetRef}>
62
+ {children}
63
+ </BottomSheetRefContext.Provider>
64
+ </BottomSheetDefaultIndexContext.Provider>
65
+ </BottomSheetContext.Provider>
66
+ </Portal>
59
67
  );
60
68
  }
@@ -4,7 +4,9 @@ import React from 'react';
4
4
  import { Portal } from 'react-native-teleport';
5
5
 
6
6
  import { BottomSheetContext } from './BottomSheet.context';
7
- import { useSheetUsePortal, useSheetPortalSession } from './bottomSheet.store';
7
+ import { useSheetPortalSession } from './bottomSheet.store';
8
+ import { BottomSheetDefaultIndexContext } from './BottomSheetDefaultIndex.context';
9
+ import { BottomSheetRefContext } from './BottomSheetRef.context';
8
10
  import type { BottomSheetPortalId } from './portal.types';
9
11
  import { getSheetRef } from './refsMap';
10
12
 
@@ -14,22 +16,23 @@ interface BottomSheetPortalProps {
14
16
  }
15
17
 
16
18
  export function BottomSheetPortal({ id, children }: BottomSheetPortalProps) {
17
- const usePortal = useSheetUsePortal(id);
18
19
  const portalSession = useSheetPortalSession(id);
20
+ const ref = getSheetRef(id);
19
21
 
20
- if (!usePortal || portalSession === undefined) {
22
+ if (!portalSession || !ref) {
21
23
  return null;
22
24
  }
23
25
 
24
- const ref = getSheetRef(id);
25
- const childWithRef = React.cloneElement(children, {
26
- ref,
27
- } as { ref: typeof ref });
26
+ const portalName = `bottomsheet-${id}-${portalSession}`;
28
27
 
29
28
  return (
30
- <Portal hostName={`bottomsheet-${id}-${portalSession}`}>
29
+ <Portal hostName={portalName}>
31
30
  <BottomSheetContext.Provider value={{ id }}>
32
- {childWithRef}
31
+ <BottomSheetDefaultIndexContext.Provider value={{ defaultIndex: 0 }}>
32
+ <BottomSheetRefContext.Provider value={ref}>
33
+ {children}
34
+ </BottomSheetRefContext.Provider>
35
+ </BottomSheetDefaultIndexContext.Provider>
33
36
  </BottomSheetContext.Provider>
34
37
  </Portal>
35
38
  );
package/src/QueueItem.tsx CHANGED
@@ -1,17 +1,16 @@
1
- import { memo, useEffect } from 'react';
1
+ import { memo, useEffect, type PropsWithChildren } from 'react';
2
2
  import { StyleSheet, View } from 'react-native';
3
3
  import Animated from 'react-native-reanimated';
4
4
  import { useSafeAreaFrame } from 'react-native-safe-area-context';
5
5
  import { PortalHost } from 'react-native-teleport';
6
6
 
7
- import { cleanupAnimatedIndex } from './animatedRegistry';
7
+ import { cleanupAnimatedIndex, getAnimatedIndex } from './animatedRegistry';
8
8
  import { BottomSheetContext } from './BottomSheet.context';
9
9
  import {
10
10
  useSheetContent,
11
- useSheetUsePortal,
12
11
  useSheetKeepMounted,
13
12
  useSheetPortalSession,
14
- useStartClosing,
13
+ useSheetUsePortal,
15
14
  } from './bottomSheet.store';
16
15
  import { BottomSheetBackdrop } from './BottomSheetBackdrop';
17
16
  import { cleanupSheetRef } from './refsMap';
@@ -32,10 +31,10 @@ export const QueueItem = memo(function QueueItem({
32
31
  const usePortal = useSheetUsePortal(id);
33
32
  const keepMounted = useSheetKeepMounted(id);
34
33
  const portalSession = useSheetPortalSession(id);
35
- const startClosing = useStartClosing();
36
34
 
37
35
  const { width, height } = useSafeAreaFrame();
38
- const scaleStyle = useSheetScaleAnimatedStyle(id);
36
+
37
+ const animatedIndex = getAnimatedIndex(id);
39
38
 
40
39
  useEffect(() => {
41
40
  return () => {
@@ -47,6 +46,10 @@ export const QueueItem = memo(function QueueItem({
47
46
  const backdropZIndex = stackIndex * 2;
48
47
  const contentZIndex = stackIndex * 2 + 1;
49
48
 
49
+ if (!animatedIndex) {
50
+ return null;
51
+ }
52
+
50
53
  return (
51
54
  <>
52
55
  {isActive && (
@@ -54,19 +57,11 @@ export const QueueItem = memo(function QueueItem({
54
57
  style={[StyleSheet.absoluteFillObject, { zIndex: backdropZIndex }]}
55
58
  pointerEvents="box-none"
56
59
  >
57
- <BottomSheetBackdrop sheetId={id} onPress={() => startClosing(id)} />
60
+ <BottomSheetBackdrop sheetId={id} />
58
61
  </View>
59
62
  )}
60
63
 
61
- <Animated.View
62
- pointerEvents="box-none"
63
- style={[
64
- StyleSheet.absoluteFillObject,
65
- styles.container,
66
- { width, height, zIndex: contentZIndex },
67
- scaleStyle,
68
- ]}
69
- >
64
+ <ScaleWrapper id={id} zIndex={contentZIndex}>
70
65
  {usePortal ? (
71
66
  <PortalHost
72
67
  name={`bottomsheet-${id}-${portalSession}`}
@@ -77,11 +72,27 @@ export const QueueItem = memo(function QueueItem({
77
72
  {content}
78
73
  </BottomSheetContext.Provider>
79
74
  )}
80
- </Animated.View>
75
+ </ScaleWrapper>
81
76
  </>
82
77
  );
83
78
  });
84
79
 
85
- const styles = StyleSheet.create({
86
- container: {},
87
- });
80
+ const ScaleWrapper = ({
81
+ id,
82
+ zIndex,
83
+ children,
84
+ }: PropsWithChildren<{
85
+ id: string;
86
+ zIndex: number;
87
+ }>) => {
88
+ const scaleStyle = useSheetScaleAnimatedStyle(id);
89
+
90
+ return (
91
+ <Animated.View
92
+ pointerEvents="box-none"
93
+ style={[StyleSheet.absoluteFillObject, { zIndex }, scaleStyle]}
94
+ >
95
+ {children}
96
+ </Animated.View>
97
+ );
98
+ };
@@ -2,18 +2,26 @@ import { makeMutable, type SharedValue } from 'react-native-reanimated';
2
2
 
3
3
  /**
4
4
  * Registry for shared animated values per sheet.
5
- * This allows backdrop to access the animatedIndex from the bottom sheet.
5
+ * AnimatedIndex is created eagerly in store actions (open/mount)
6
+ * before any component renders, ensuring it's always available.
6
7
  */
7
8
  const animatedIndexRegistry = new Map<string, SharedValue<number>>();
8
9
 
9
- export function getAnimatedIndex(sheetId: string): SharedValue<number> {
10
- let animatedIndex = animatedIndexRegistry.get(sheetId);
11
-
12
- if (!animatedIndex) {
13
- animatedIndex = makeMutable(-1);
14
- animatedIndexRegistry.set(sheetId, animatedIndex);
10
+ export function ensureAnimatedIndex(sheetId: string): SharedValue<number> {
11
+ const existing = animatedIndexRegistry.get(sheetId);
12
+ if (existing) {
13
+ return existing;
15
14
  }
16
15
 
16
+ const animatedIndex = makeMutable(-1);
17
+ animatedIndexRegistry.set(sheetId, animatedIndex);
18
+ return animatedIndex;
19
+ }
20
+
21
+ export function getAnimatedIndex(
22
+ sheetId: string
23
+ ): SharedValue<number> | undefined {
24
+ const animatedIndex = animatedIndexRegistry.get(sheetId);
17
25
  return animatedIndex;
18
26
  }
19
27
 
@@ -28,3 +36,11 @@ export function cleanupAnimatedIndex(sheetId: string): void {
28
36
  export function __resetAnimatedIndexes(): void {
29
37
  animatedIndexRegistry.clear();
30
38
  }
39
+
40
+ /**
41
+ * Get all animated indexes for debugging.
42
+ * @internal
43
+ */
44
+ export function __getAllAnimatedIndexes(): Map<string, SharedValue<number>> {
45
+ return animatedIndexRegistry;
46
+ }
@@ -45,7 +45,10 @@ export function createSheetEventHandlers(sheetId: string) {
45
45
  const state = useBottomSheetStore.getState();
46
46
  const currentStatus = state.sheetsById[sheetId]?.status;
47
47
 
48
- if (toIndex === -1 && currentStatus === 'open') {
48
+ if (
49
+ toIndex === -1 &&
50
+ (currentStatus === 'open' || currentStatus === 'opening')
51
+ ) {
49
52
  startClosing(sheetId);
50
53
  }
51
54
  };
package/src/index.tsx CHANGED
@@ -35,7 +35,12 @@ export type {
35
35
  BottomSheetPortalParams,
36
36
  } from './portal.types';
37
37
 
38
+ export { useBottomSheetStore } from './bottomSheet.store';
39
+
38
40
  // Testing utilities (internal use)
39
41
  export { __resetSheetRefs } from './refsMap';
40
- export { __resetAnimatedIndexes } from './animatedRegistry';
42
+ export {
43
+ __resetAnimatedIndexes,
44
+ __getAllAnimatedIndexes,
45
+ } from './animatedRegistry';
41
46
  export { __resetPortalSessions } from './portalSessionRegistry';
@@ -7,10 +7,10 @@ import {
7
7
  getTopSheetId,
8
8
  isActivatableKeepMounted,
9
9
  isHidden,
10
- isOpening,
11
10
  removeFromStack,
12
11
  updateSheet,
13
12
  } from './helpers';
13
+ import { ensureAnimatedIndex } from '../animatedRegistry';
14
14
  import { getNextPortalSession } from '../portalSessionRegistry';
15
15
  import type { BottomSheetState, BottomSheetStore } from './types';
16
16
 
@@ -27,6 +27,13 @@ export const useBottomSheetStore = create(
27
27
  return state;
28
28
  }
29
29
 
30
+ const hasOpeningInGroup = Object.values(state.sheetsById).some(
31
+ (s) => s.groupId === sheet.groupId && s.status === 'opening'
32
+ );
33
+ if (hasOpeningInGroup) {
34
+ return state;
35
+ }
36
+
30
37
  const updatedSheetsById = applyModeToTopSheet(
31
38
  state.sheetsById,
32
39
  state.stackOrder,
@@ -39,6 +46,8 @@ export const useBottomSheetStore = create(
39
46
  ? getNextPortalSession(sheet.id)
40
47
  : undefined;
41
48
 
49
+ ensureAnimatedIndex(sheet.id);
50
+
42
51
  const newSheet: BottomSheetState = existingSheet
43
52
  ? {
44
53
  ...existingSheet,
@@ -69,7 +78,7 @@ export const useBottomSheetStore = create(
69
78
  startClosing: (id) =>
70
79
  set((state) => {
71
80
  const sheet = state.sheetsById[id];
72
- if (!sheet || isHidden(sheet) || isOpening(sheet)) return state;
81
+ if (!sheet || isHidden(sheet)) return state;
73
82
 
74
83
  let updatedSheetsById = updateSheet(state.sheetsById, id, {
75
84
  status: 'closing',
@@ -146,6 +155,8 @@ export const useBottomSheetStore = create(
146
155
  set((state) => {
147
156
  if (state.sheetsById[sheet.id]) return state;
148
157
 
158
+ ensureAnimatedIndex(sheet.id);
159
+
149
160
  // For portal-based persistent sheets, set initial portalSession
150
161
  // This session will be reused across open/close cycles
151
162
  const portalSession = sheet.usePortal
@@ -0,0 +1,27 @@
1
+ import { useEffect, useRef } from 'react';
2
+
3
+ export function useTracePropChanges(
4
+ componentName: string,
5
+ props: Record<string, any>
6
+ ) {
7
+ const prevProps = useRef(props);
8
+
9
+ useEffect(() => {
10
+ const allKeys = Object.keys({ ...props, ...prevProps.current });
11
+ allKeys.forEach((key) => {
12
+ if (prevProps.current[key] !== props[key]) {
13
+ console.log(`[${componentName}] Prop '${key}' changed.`);
14
+ if (
15
+ typeof props[key] === 'object' ||
16
+ typeof props[key] === 'function'
17
+ ) {
18
+ console.log(
19
+ `[${componentName}] New instance detected for prop '${key}'.`
20
+ );
21
+ }
22
+ }
23
+ });
24
+
25
+ prevProps.current = props;
26
+ });
27
+ }