react-native-bottom-sheet-stack 1.7.4 → 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.
- package/lib/commonjs/BottomSheetBackdrop.js +51 -27
- package/lib/commonjs/BottomSheetBackdrop.js.map +1 -1
- package/lib/commonjs/BottomSheetManaged.js +52 -46
- package/lib/commonjs/BottomSheetManaged.js.map +1 -1
- package/lib/commonjs/BottomSheetPersistent.js +2 -2
- package/lib/commonjs/BottomSheetPersistent.js.map +1 -1
- package/lib/commonjs/BottomSheetPortal.js +3 -2
- package/lib/commonjs/BottomSheetPortal.js.map +1 -1
- package/lib/commonjs/QueueItem.js +81 -64
- package/lib/commonjs/QueueItem.js.map +1 -1
- package/lib/commonjs/animatedRegistry.js +22 -6
- package/lib/commonjs/animatedRegistry.js.map +1 -1
- package/lib/commonjs/bottomSheetCoordinator.js +1 -1
- package/lib/commonjs/bottomSheetCoordinator.js.map +1 -1
- package/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/store/store.js +8 -1
- package/lib/commonjs/store/store.js.map +1 -1
- package/lib/commonjs/useTracePropChanges.js +37 -0
- package/lib/commonjs/useTracePropChanges.js.map +1 -0
- package/lib/typescript/example/src/App.d.ts.map +1 -1
- package/lib/typescript/example/src/components/BottomSheetDebugMonitor.d.ts +13 -0
- package/lib/typescript/example/src/components/BottomSheetDebugMonitor.d.ts.map +1 -0
- package/lib/typescript/src/BottomSheetBackdrop.d.ts +1 -2
- package/lib/typescript/src/BottomSheetBackdrop.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetManaged.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetPersistent.d.ts.map +1 -1
- package/lib/typescript/src/BottomSheetPortal.d.ts.map +1 -1
- package/lib/typescript/src/QueueItem.d.ts.map +1 -1
- package/lib/typescript/src/animatedRegistry.d.ts +7 -1
- package/lib/typescript/src/animatedRegistry.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/store/store.d.ts.map +1 -1
- package/lib/typescript/src/useTracePropChanges.d.ts +2 -0
- package/lib/typescript/src/useTracePropChanges.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/BottomSheetBackdrop.tsx +21 -8
- package/src/BottomSheetManaged.tsx +21 -9
- package/src/BottomSheetPersistent.tsx +2 -2
- package/src/BottomSheetPortal.tsx +4 -2
- package/src/QueueItem.tsx +31 -20
- package/src/animatedRegistry.ts +23 -7
- package/src/bottomSheetCoordinator.ts +4 -1
- package/src/index.tsx +6 -1
- package/src/store/store.ts +13 -2
- package/src/useTracePropChanges.ts +27 -0
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
|
-
|
|
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
|
-
|
|
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}
|
|
60
|
+
<BottomSheetBackdrop sheetId={id} />
|
|
58
61
|
</View>
|
|
59
62
|
)}
|
|
60
63
|
|
|
61
|
-
<
|
|
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
|
-
</
|
|
75
|
+
</ScaleWrapper>
|
|
81
76
|
</>
|
|
82
77
|
);
|
|
83
78
|
});
|
|
84
79
|
|
|
85
|
-
const
|
|
86
|
-
|
|
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
|
+
};
|
package/src/animatedRegistry.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 (
|
|
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 {
|
|
42
|
+
export {
|
|
43
|
+
__resetAnimatedIndexes,
|
|
44
|
+
__getAllAnimatedIndexes,
|
|
45
|
+
} from './animatedRegistry';
|
|
41
46
|
export { __resetPortalSessions } from './portalSessionRegistry';
|
package/src/store/store.ts
CHANGED
|
@@ -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)
|
|
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
|
+
}
|