@lodev09/react-native-true-sheet 4.0.0-beta.22 → 4.0.0-beta.24
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/README.md +2 -2
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetStackManager.kt +4 -2
- package/ios/TrueSheetContentView.mm +3 -2
- package/ios/TrueSheetView.mm +9 -0
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/fabric/TrueSheetFooterViewNativeComponent.ts +2 -3
- package/lib/module/fabric/TrueSheetViewNativeComponent.ts +74 -71
- package/lib/module/navigation/createTrueSheetRouter.js +114 -91
- package/lib/module/navigation/createTrueSheetRouter.js.map +1 -1
- package/lib/module/navigation/expo-router/extendTrueSheetRouter.js +43 -0
- package/lib/module/navigation/expo-router/extendTrueSheetRouter.js.map +1 -0
- package/lib/module/navigation/expo-router/index.js +9 -4
- package/lib/module/navigation/expo-router/index.js.map +1 -1
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.types.d.ts +2 -2
- package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
- package/lib/typescript/src/fabric/TrueSheetFooterViewNativeComponent.d.ts +2 -3
- package/lib/typescript/src/fabric/TrueSheetFooterViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +65 -66
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/navigation/createTrueSheetRouter.d.ts +27 -0
- package/lib/typescript/src/navigation/createTrueSheetRouter.d.ts.map +1 -1
- package/lib/typescript/src/navigation/expo-router/extendTrueSheetRouter.d.ts +29 -0
- package/lib/typescript/src/navigation/expo-router/extendTrueSheetRouter.d.ts.map +1 -0
- package/lib/typescript/src/navigation/expo-router/index.d.ts +3 -2
- package/lib/typescript/src/navigation/expo-router/index.d.ts.map +1 -1
- package/lib/typescript/src/navigation/expo-router/types.d.ts +1 -1
- package/lib/typescript/src/navigation/types.d.ts +2 -1
- package/lib/typescript/src/navigation/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/TrueSheet.tsx +3 -1
- package/src/TrueSheet.types.ts +2 -1
- package/src/fabric/TrueSheetFooterViewNativeComponent.ts +2 -3
- package/src/fabric/TrueSheetViewNativeComponent.ts +74 -71
- package/src/navigation/createTrueSheetRouter.ts +149 -113
- package/src/navigation/expo-router/extendTrueSheetRouter.ts +71 -0
- package/src/navigation/expo-router/index.ts +14 -6
- package/src/navigation/expo-router/types.ts +1 -1
- package/src/navigation/types.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lodev09/react-native-true-sheet",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.24",
|
|
4
4
|
"description": "The true native bottom sheet experience for your React Native Apps.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/module/index.js",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"scripts": {
|
|
54
54
|
"bare": "yarn workspace @example/bare",
|
|
55
55
|
"expo": "yarn workspace @example/expo",
|
|
56
|
+
"expo-58": "yarn workspace @example/expo-58",
|
|
56
57
|
"docs": "yarn workspace docs",
|
|
57
58
|
"test": "jest",
|
|
58
59
|
"typecheck": "tsc",
|
|
@@ -128,9 +129,7 @@
|
|
|
128
129
|
},
|
|
129
130
|
"resolutions": {
|
|
130
131
|
"@types/react": "~19.2.14",
|
|
131
|
-
"react-native-
|
|
132
|
-
"react-native-worklets": "0.10.1",
|
|
133
|
-
"react-native-screens": "patch:react-native-screens@npm%3A4.26.2#~/.yarn/patches/react-native-screens-npm-4.26.2.patch"
|
|
132
|
+
"react-native-screens@npm:^4.26.0": "patch:react-native-screens@npm%3A4.26.2#~/.yarn/patches/react-native-screens-npm-4.26.2.patch"
|
|
134
133
|
},
|
|
135
134
|
"peerDependencies": {
|
|
136
135
|
"@radix-ui/react-dialog": ">=1",
|
|
@@ -173,6 +172,7 @@
|
|
|
173
172
|
"workspaces": [
|
|
174
173
|
"example/bare",
|
|
175
174
|
"example/expo",
|
|
175
|
+
"example/expo-58",
|
|
176
176
|
"example/shared",
|
|
177
177
|
"docs"
|
|
178
178
|
],
|
|
@@ -188,6 +188,7 @@
|
|
|
188
188
|
"modulePathIgnorePatterns": [
|
|
189
189
|
"<rootDir>/example/bare/node_modules",
|
|
190
190
|
"<rootDir>/example/expo/node_modules",
|
|
191
|
+
"<rootDir>/example/expo-58/node_modules",
|
|
191
192
|
"<rootDir>/example/shared/node_modules",
|
|
192
193
|
"<rootDir>/lib/",
|
|
193
194
|
"<rootDir>/docs/node_modules",
|
package/src/TrueSheet.tsx
CHANGED
|
@@ -197,7 +197,9 @@ export class TrueSheet
|
|
|
197
197
|
let scrollableHandle: number | null = null;
|
|
198
198
|
if (scrollableRef?.current) {
|
|
199
199
|
try {
|
|
200
|
-
scrollableHandle = findNodeHandle(
|
|
200
|
+
scrollableHandle = findNodeHandle(
|
|
201
|
+
scrollableRef.current as Parameters<typeof findNodeHandle>[0]
|
|
202
|
+
);
|
|
201
203
|
} catch (error) {
|
|
202
204
|
// A stale ref (e.g. a wrapper that never clears it on unmount) makes
|
|
203
205
|
// findNodeHandle throw. Treat it as no scrollable instead of crashing.
|
package/src/TrueSheet.types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Component, ComponentType, ReactElement, ReactNode, RefObject } from 'react';
|
|
2
2
|
import type {
|
|
3
3
|
ColorValue,
|
|
4
|
+
HostInstance,
|
|
4
5
|
NativeSyntheticEvent,
|
|
5
6
|
StyleProp,
|
|
6
7
|
ViewProps,
|
|
@@ -689,7 +690,7 @@ export interface TrueSheetProps extends ViewProps {
|
|
|
689
690
|
* </TrueSheet>
|
|
690
691
|
* ```
|
|
691
692
|
*/
|
|
692
|
-
scrollableRef?: RefObject<Component<unknown> | null>;
|
|
693
|
+
scrollableRef?: RefObject<Component<unknown> | HostInstance | null>;
|
|
693
694
|
|
|
694
695
|
/**
|
|
695
696
|
* Options for scrollable behavior.
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type { ViewProps } from 'react-native';
|
|
2
|
-
import type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
|
|
1
|
+
import type { CodegenTypes, ViewProps } from 'react-native';
|
|
3
2
|
import { codegenNativeComponent } from 'react-native';
|
|
4
3
|
|
|
5
4
|
export interface NativeProps extends ViewProps {
|
|
6
5
|
// Seeds the footer's first layout with the sheet's bottom safe-area inset
|
|
7
6
|
// (insetAdjustment: 'automatic') so a late-set footer doesn't need a second
|
|
8
7
|
// layout pass — and a visible sheet resize — once native pushes the inset
|
|
9
|
-
autoBottomInset?: WithDefault<boolean, false>;
|
|
8
|
+
autoBottomInset?: CodegenTypes.WithDefault<boolean, false>;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
// interfaceOnly: shadow node/state/descriptor are custom (common/cpp) so the
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import type { ColorValue, ProcessedColorValue, ViewProps } from 'react-native';
|
|
2
|
-
import type {
|
|
3
|
-
DirectEventHandler,
|
|
4
|
-
Double,
|
|
5
|
-
Int32,
|
|
6
|
-
WithDefault,
|
|
7
|
-
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
1
|
+
import type { CodegenTypes, ColorValue, ProcessedColorValue, ViewProps } from 'react-native';
|
|
8
2
|
import { codegenNativeComponent } from 'react-native';
|
|
9
3
|
|
|
10
4
|
type GrabberOptionsType = Readonly<{
|
|
11
|
-
width?: Double;
|
|
12
|
-
height?: Double;
|
|
13
|
-
topMargin?: Double;
|
|
14
|
-
cornerRadius?: WithDefault<Double, -1>;
|
|
5
|
+
width?: CodegenTypes.Double;
|
|
6
|
+
height?: CodegenTypes.Double;
|
|
7
|
+
topMargin?: CodegenTypes.Double;
|
|
8
|
+
cornerRadius?: CodegenTypes.WithDefault<CodegenTypes.Double, -1>;
|
|
15
9
|
color?: ProcessedColorValue | null;
|
|
16
|
-
adaptive?: WithDefault<boolean, true>;
|
|
10
|
+
adaptive?: CodegenTypes.WithDefault<boolean, true>;
|
|
17
11
|
}>;
|
|
18
12
|
|
|
19
13
|
type AccessibilityOptionsType = Readonly<{
|
|
20
|
-
grabberLabel?: WithDefault<string, 'Sheet Grabber'>;
|
|
21
|
-
grabberHint?: WithDefault<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
grabberLabel?: CodegenTypes.WithDefault<string, 'Sheet Grabber'>;
|
|
15
|
+
grabberHint?: CodegenTypes.WithDefault<
|
|
16
|
+
string,
|
|
17
|
+
'Double-tap to expand. Swipe up or down to resize the sheet'
|
|
18
|
+
>;
|
|
19
|
+
expandedValue?: CodegenTypes.WithDefault<string, 'Expanded'>;
|
|
20
|
+
collapsedValue?: CodegenTypes.WithDefault<string, 'Collapsed'>;
|
|
21
|
+
detentValue?: CodegenTypes.WithDefault<string, 'Detent {index} of {count}'>;
|
|
22
|
+
expandActionLabel?: CodegenTypes.WithDefault<string, 'Expand'>;
|
|
23
|
+
collapseActionLabel?: CodegenTypes.WithDefault<string, 'Collapse'>;
|
|
24
|
+
paneTitle?: CodegenTypes.WithDefault<string, 'Bottom sheet'>;
|
|
28
25
|
}>;
|
|
29
26
|
|
|
30
27
|
type ScrollEdgeEffect = 'automatic' | 'hard' | 'soft' | 'hidden';
|
|
31
28
|
|
|
32
29
|
type ScrollableOptionsType = Readonly<{
|
|
33
|
-
contentInsetAdjustment?: WithDefault<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
contentInsetAdjustment?: CodegenTypes.WithDefault<
|
|
31
|
+
'automatic' | 'safe-area' | 'footer' | 'never',
|
|
32
|
+
'automatic'
|
|
33
|
+
>;
|
|
34
|
+
keyboardScrollOffset?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
|
|
35
|
+
keyboardOffset?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
|
|
36
|
+
scrollingExpandsSheet?: CodegenTypes.WithDefault<boolean, true>;
|
|
37
|
+
topScrollEdgeEffect?: CodegenTypes.WithDefault<ScrollEdgeEffect, 'hidden'>;
|
|
38
|
+
bottomScrollEdgeEffect?: CodegenTypes.WithDefault<ScrollEdgeEffect, 'hidden'>;
|
|
39
39
|
}>;
|
|
40
40
|
|
|
41
41
|
type FooterOptionsType = Readonly<{
|
|
42
42
|
// Named uniquely across option structs — codegen derives the enum name from
|
|
43
43
|
// the field name, so a second `position` would redefine TrueSheetViewPosition
|
|
44
|
-
footerPosition?: WithDefault<'relative' | 'absolute', 'relative'>;
|
|
45
|
-
keyboardOffset?: WithDefault<Double, 0>;
|
|
46
|
-
avoidKeyboard?: WithDefault<boolean, true>;
|
|
44
|
+
footerPosition?: CodegenTypes.WithDefault<'relative' | 'absolute', 'relative'>;
|
|
45
|
+
keyboardOffset?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
|
|
46
|
+
avoidKeyboard?: CodegenTypes.WithDefault<boolean, true>;
|
|
47
47
|
}>;
|
|
48
48
|
|
|
49
49
|
type HeaderOptionsType = Readonly<{
|
|
50
|
-
position?: WithDefault<'relative' | 'absolute', 'relative'>;
|
|
50
|
+
position?: CodegenTypes.WithDefault<'relative' | 'absolute', 'relative'>;
|
|
51
51
|
}>;
|
|
52
52
|
|
|
53
53
|
export interface DetentInfoEventPayload {
|
|
54
|
-
index: Int32;
|
|
55
|
-
position: Double;
|
|
56
|
-
detent: Double;
|
|
54
|
+
index: CodegenTypes.Int32;
|
|
55
|
+
position: CodegenTypes.Double;
|
|
56
|
+
detent: CodegenTypes.Double;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export interface PositionChangeEventPayload {
|
|
60
|
-
index: Double;
|
|
61
|
-
position: Double;
|
|
62
|
-
detent: Double;
|
|
60
|
+
index: CodegenTypes.Double;
|
|
61
|
+
position: CodegenTypes.Double;
|
|
62
|
+
detent: CodegenTypes.Double;
|
|
63
63
|
realtime: boolean;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export interface NativeProps extends ViewProps {
|
|
67
67
|
// Array properties
|
|
68
|
-
detents?: ReadonlyArray<Double>;
|
|
68
|
+
detents?: ReadonlyArray<CodegenTypes.Double>;
|
|
69
69
|
detentBackgrounds?: ReadonlyArray<
|
|
70
70
|
Readonly<{
|
|
71
71
|
color?: ProcessedColorValue | null;
|
|
@@ -74,18 +74,18 @@ export interface NativeProps extends ViewProps {
|
|
|
74
74
|
>;
|
|
75
75
|
|
|
76
76
|
// Number properties - use 0 as default to avoid nil insertion
|
|
77
|
-
maxContentHeight?: WithDefault<Double, 0>;
|
|
78
|
-
maxContentWidth?: WithDefault<Double, 0>;
|
|
79
|
-
cornerRadius?: WithDefault<Double, -1>;
|
|
80
|
-
elevation?: WithDefault<Double, -1>;
|
|
77
|
+
maxContentHeight?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
|
|
78
|
+
maxContentWidth?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
|
|
79
|
+
cornerRadius?: CodegenTypes.WithDefault<CodegenTypes.Double, -1>;
|
|
80
|
+
elevation?: CodegenTypes.WithDefault<CodegenTypes.Double, -1>;
|
|
81
81
|
|
|
82
82
|
// Color properties
|
|
83
83
|
backgroundColor?: ColorValue;
|
|
84
|
-
initialDetentIndex?: WithDefault<Int32, -1>;
|
|
85
|
-
dimmedDetentIndex?: WithDefault<Int32, 0>;
|
|
84
|
+
initialDetentIndex?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
|
|
85
|
+
dimmedDetentIndex?: CodegenTypes.WithDefault<CodegenTypes.Int32, 0>;
|
|
86
86
|
|
|
87
87
|
// String properties - use empty string as default to avoid nil insertion
|
|
88
|
-
backgroundBlur?: WithDefault<
|
|
88
|
+
backgroundBlur?: CodegenTypes.WithDefault<
|
|
89
89
|
| 'none'
|
|
90
90
|
| 'light'
|
|
91
91
|
| 'dark'
|
|
@@ -111,43 +111,46 @@ export interface NativeProps extends ViewProps {
|
|
|
111
111
|
'none'
|
|
112
112
|
>;
|
|
113
113
|
|
|
114
|
-
placement?: WithDefault<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
placement?: CodegenTypes.WithDefault<
|
|
115
|
+
'automatic' | 'leading' | 'center' | 'trailing',
|
|
116
|
+
'automatic'
|
|
117
|
+
>;
|
|
118
|
+
placementOffset?: CodegenTypes.WithDefault<CodegenTypes.Double, 16>;
|
|
119
|
+
insetAdjustment?: CodegenTypes.WithDefault<'automatic' | 'never', 'automatic'>;
|
|
120
|
+
dismissThreshold?: CodegenTypes.WithDefault<'half' | 'short', 'half'>;
|
|
118
121
|
|
|
119
122
|
// Boolean properties - match defaults from TrueSheet.types.ts
|
|
120
|
-
grabber?: WithDefault<boolean, true>;
|
|
123
|
+
grabber?: CodegenTypes.WithDefault<boolean, true>;
|
|
121
124
|
grabberOptions?: GrabberOptionsType;
|
|
122
125
|
accessibilityOptions?: AccessibilityOptionsType;
|
|
123
|
-
dismissible?: WithDefault<boolean, true>;
|
|
124
|
-
draggable?: WithDefault<boolean, true>;
|
|
125
|
-
dimmed?: WithDefault<boolean, true>;
|
|
126
|
-
initialDetentAnimated?: WithDefault<boolean, true>;
|
|
126
|
+
dismissible?: CodegenTypes.WithDefault<boolean, true>;
|
|
127
|
+
draggable?: CodegenTypes.WithDefault<boolean, true>;
|
|
128
|
+
dimmed?: CodegenTypes.WithDefault<boolean, true>;
|
|
129
|
+
initialDetentAnimated?: CodegenTypes.WithDefault<boolean, true>;
|
|
127
130
|
// React tag of the scrollable component within the content (see scrollableRef)
|
|
128
|
-
scrollableHandle?: WithDefault<Int32, -1>;
|
|
131
|
+
scrollableHandle?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
|
|
129
132
|
scrollableOptions?: ScrollableOptionsType;
|
|
130
133
|
headerOptions?: HeaderOptionsType;
|
|
131
134
|
footerOptions?: FooterOptionsType;
|
|
132
|
-
presentation?: WithDefault<'page' | 'form', 'page'>;
|
|
135
|
+
presentation?: CodegenTypes.WithDefault<'page' | 'form', 'page'>;
|
|
133
136
|
|
|
134
137
|
// Event handlers
|
|
135
|
-
onMount?: DirectEventHandler<null>;
|
|
136
|
-
onWillPresent?: DirectEventHandler<DetentInfoEventPayload>;
|
|
137
|
-
onDidPresent?: DirectEventHandler<DetentInfoEventPayload>;
|
|
138
|
-
onWillDismiss?: DirectEventHandler<null>;
|
|
139
|
-
onDidDismiss?: DirectEventHandler<null>;
|
|
140
|
-
onDismissAttempt?: DirectEventHandler<null>;
|
|
141
|
-
onDetentChange?: DirectEventHandler<DetentInfoEventPayload>;
|
|
142
|
-
onDragBegin?: DirectEventHandler<DetentInfoEventPayload>;
|
|
143
|
-
onDragChange?: DirectEventHandler<DetentInfoEventPayload>;
|
|
144
|
-
onDragEnd?: DirectEventHandler<DetentInfoEventPayload>;
|
|
145
|
-
onPositionChange?: DirectEventHandler<PositionChangeEventPayload>;
|
|
146
|
-
onWillFocus?: DirectEventHandler<null>;
|
|
147
|
-
onDidFocus?: DirectEventHandler<null>;
|
|
148
|
-
onWillBlur?: DirectEventHandler<null>;
|
|
149
|
-
onDidBlur?: DirectEventHandler<null>;
|
|
150
|
-
onVisibilityChange?: DirectEventHandler<Readonly<{ visible: boolean }>>;
|
|
138
|
+
onMount?: CodegenTypes.DirectEventHandler<null>;
|
|
139
|
+
onWillPresent?: CodegenTypes.DirectEventHandler<DetentInfoEventPayload>;
|
|
140
|
+
onDidPresent?: CodegenTypes.DirectEventHandler<DetentInfoEventPayload>;
|
|
141
|
+
onWillDismiss?: CodegenTypes.DirectEventHandler<null>;
|
|
142
|
+
onDidDismiss?: CodegenTypes.DirectEventHandler<null>;
|
|
143
|
+
onDismissAttempt?: CodegenTypes.DirectEventHandler<null>;
|
|
144
|
+
onDetentChange?: CodegenTypes.DirectEventHandler<DetentInfoEventPayload>;
|
|
145
|
+
onDragBegin?: CodegenTypes.DirectEventHandler<DetentInfoEventPayload>;
|
|
146
|
+
onDragChange?: CodegenTypes.DirectEventHandler<DetentInfoEventPayload>;
|
|
147
|
+
onDragEnd?: CodegenTypes.DirectEventHandler<DetentInfoEventPayload>;
|
|
148
|
+
onPositionChange?: CodegenTypes.DirectEventHandler<PositionChangeEventPayload>;
|
|
149
|
+
onWillFocus?: CodegenTypes.DirectEventHandler<null>;
|
|
150
|
+
onDidFocus?: CodegenTypes.DirectEventHandler<null>;
|
|
151
|
+
onWillBlur?: CodegenTypes.DirectEventHandler<null>;
|
|
152
|
+
onDidBlur?: CodegenTypes.DirectEventHandler<null>;
|
|
153
|
+
onVisibilityChange?: CodegenTypes.DirectEventHandler<Readonly<{ visible: boolean }>>;
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
export default codegenNativeComponent<NativeProps>('TrueSheetView', {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TrueSheetActions } from './actions';
|
|
1
|
+
import { TrueSheetActions, type TrueSheetActionType } from './actions';
|
|
2
2
|
import type { TrueSheetRouter, TrueSheetRouterFactory, TrueSheetRouterOptions } from './types';
|
|
3
3
|
|
|
4
4
|
const uid = () => Math.random().toString(36).slice(2, 10);
|
|
@@ -31,6 +31,151 @@ const ensureBaseRoute = <T extends { routes: { name: string }[] }>(
|
|
|
31
31
|
return state as T & { index: number; routes: T['routes'] };
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
type SheetRoute = {
|
|
35
|
+
key: string;
|
|
36
|
+
name: string;
|
|
37
|
+
closing?: boolean;
|
|
38
|
+
dismissing?: boolean;
|
|
39
|
+
resizeIndex?: number;
|
|
40
|
+
resizeKey?: number;
|
|
41
|
+
};
|
|
42
|
+
type SheetState = { key: string; index: number; routes: SheetRoute[] };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Index of the route a `RESIZE` targets: the dispatching screen, else the focused route.
|
|
46
|
+
*/
|
|
47
|
+
export const getResizeRouteIndex = (
|
|
48
|
+
state: SheetState,
|
|
49
|
+
action: { source?: string; target?: string }
|
|
50
|
+
): number =>
|
|
51
|
+
action.target === state.key && action.source
|
|
52
|
+
? state.routes.findIndex((r) => r.key === action.source)
|
|
53
|
+
: state.index;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Reduces the sheet-specific actions shared by every router flavour.
|
|
57
|
+
* Returns `undefined` for actions the base `StackRouter` should handle.
|
|
58
|
+
*/
|
|
59
|
+
export const getTrueSheetStateForAction = <State extends SheetState>(
|
|
60
|
+
state: State,
|
|
61
|
+
action: TrueSheetActionType
|
|
62
|
+
): State | null | undefined => {
|
|
63
|
+
switch (action.type) {
|
|
64
|
+
case 'RESIZE': {
|
|
65
|
+
const routeIndex = getResizeRouteIndex(state, action);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
...state,
|
|
69
|
+
routes: state.routes.map((route, i) =>
|
|
70
|
+
i === routeIndex
|
|
71
|
+
? {
|
|
72
|
+
...route,
|
|
73
|
+
resizeIndex: action.index,
|
|
74
|
+
resizeKey: (route.resizeKey ?? 0) + 1,
|
|
75
|
+
}
|
|
76
|
+
: route
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
case 'GO_BACK':
|
|
82
|
+
case 'DISMISS': {
|
|
83
|
+
return getTrueSheetStateForAction(state, TrueSheetActions.pop(1));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
case 'POP': {
|
|
87
|
+
// Only base screen remains - let parent navigator handle it
|
|
88
|
+
if (state.routes.length <= 1) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const count =
|
|
93
|
+
'payload' in action && typeof action.payload?.count === 'number' ? action.payload.count : 1;
|
|
94
|
+
|
|
95
|
+
// Calculate how many routes we can actually pop (don't pop base screen)
|
|
96
|
+
const maxPopCount = state.routes.length - 1;
|
|
97
|
+
const actualCount = Math.min(count, maxPopCount);
|
|
98
|
+
|
|
99
|
+
// Base screen - let parent navigator handle it
|
|
100
|
+
if (actualCount <= 0) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Target index is the route we want to stay on (land on after pop)
|
|
105
|
+
// closingIndex is the first route to be dismissed (the one after target)
|
|
106
|
+
const targetIndex = state.routes.length - 1 - actualCount;
|
|
107
|
+
const closingIndex = targetIndex + 1;
|
|
108
|
+
|
|
109
|
+
// Mark only the bottom-most route to pop as closing
|
|
110
|
+
// The sheet's dismiss() will handle dismissing sheets above it first
|
|
111
|
+
return {
|
|
112
|
+
...state,
|
|
113
|
+
index: closingIndex,
|
|
114
|
+
routes: state.routes.map((route, i) => {
|
|
115
|
+
if (i === closingIndex) return { ...route, closing: true };
|
|
116
|
+
if (i > closingIndex) return { ...route, dismissing: true };
|
|
117
|
+
return route;
|
|
118
|
+
}),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
case 'POP_TO_TOP': {
|
|
123
|
+
const popCount = state.routes.length - 1;
|
|
124
|
+
return getTrueSheetStateForAction(state, TrueSheetActions.pop(popCount));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
case 'POP_TO': {
|
|
128
|
+
const targetName =
|
|
129
|
+
'payload' in action && typeof action.payload?.name === 'string'
|
|
130
|
+
? action.payload.name
|
|
131
|
+
: null;
|
|
132
|
+
|
|
133
|
+
if (!targetName) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const targetIndex = state.routes.findIndex((r) => r.name === targetName);
|
|
138
|
+
|
|
139
|
+
// Target not found or is the current route
|
|
140
|
+
if (targetIndex === -1 || targetIndex >= state.index) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const popCount = state.routes.length - 1 - targetIndex;
|
|
145
|
+
return getTrueSheetStateForAction(state, TrueSheetActions.pop(popCount));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
case 'REMOVE': {
|
|
149
|
+
// Actually remove the closing route and all routes above it
|
|
150
|
+
const routeKey = action.source;
|
|
151
|
+
const routeIndex = routeKey
|
|
152
|
+
? state.routes.findIndex((r) => r.key === routeKey)
|
|
153
|
+
: state.routes.findIndex((r) => r.closing);
|
|
154
|
+
|
|
155
|
+
if (routeIndex === -1) {
|
|
156
|
+
return state;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Remove the route and the routes dismissed with it. A popped route keeps the
|
|
160
|
+
// routes pushed after the pop started: they aren't stacked on it natively.
|
|
161
|
+
const removed = state.routes[routeIndex]!;
|
|
162
|
+
const isPopped = removed.closing || removed.dismissing;
|
|
163
|
+
const routes = state.routes.filter(
|
|
164
|
+
(route, i) => i < routeIndex || (i > routeIndex && isPopped && !route.dismissing)
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
...state,
|
|
169
|
+
index: Math.min(state.index, routes.length - 1),
|
|
170
|
+
routes,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
default:
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
34
179
|
export const createTrueSheetRouter =
|
|
35
180
|
(stackRouter: TrueSheetRouterFactory) =>
|
|
36
181
|
(routerOptions: TrueSheetRouterOptions): TrueSheetRouter => {
|
|
@@ -54,118 +199,9 @@ export const createTrueSheetRouter =
|
|
|
54
199
|
},
|
|
55
200
|
|
|
56
201
|
getStateForAction(state, action, options) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
action.target === state.key && action.source
|
|
61
|
-
? state.routes.findIndex((r) => r.key === action.source)
|
|
62
|
-
: state.index;
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
...state,
|
|
66
|
-
routes: state.routes.map((route, i) =>
|
|
67
|
-
i === routeIndex
|
|
68
|
-
? {
|
|
69
|
-
...route,
|
|
70
|
-
resizeIndex: action.index,
|
|
71
|
-
resizeKey: (route.resizeKey ?? 0) + 1,
|
|
72
|
-
}
|
|
73
|
-
: route
|
|
74
|
-
),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
case 'GO_BACK':
|
|
79
|
-
case 'DISMISS': {
|
|
80
|
-
return this.getStateForAction(state, TrueSheetActions.pop(1), options);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
case 'POP': {
|
|
84
|
-
// Only base screen remains - let parent navigator handle it
|
|
85
|
-
if (state.routes.length <= 1) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const count =
|
|
90
|
-
'payload' in action && typeof action.payload?.count === 'number'
|
|
91
|
-
? action.payload.count
|
|
92
|
-
: 1;
|
|
93
|
-
|
|
94
|
-
// Calculate how many routes we can actually pop (don't pop base screen)
|
|
95
|
-
const maxPopCount = state.routes.length - 1;
|
|
96
|
-
const actualCount = Math.min(count, maxPopCount);
|
|
97
|
-
|
|
98
|
-
// Base screen - let parent navigator handle it
|
|
99
|
-
if (actualCount <= 0) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Target index is the route we want to stay on (land on after pop)
|
|
104
|
-
// closingIndex is the first route to be dismissed (the one after target)
|
|
105
|
-
const targetIndex = state.routes.length - 1 - actualCount;
|
|
106
|
-
const closingIndex = targetIndex + 1;
|
|
107
|
-
|
|
108
|
-
// Mark only the bottom-most route to pop as closing
|
|
109
|
-
// The sheet's dismiss() will handle dismissing sheets above it first
|
|
110
|
-
return {
|
|
111
|
-
...state,
|
|
112
|
-
index: closingIndex,
|
|
113
|
-
routes: state.routes.map((route, i) =>
|
|
114
|
-
i === closingIndex ? { ...route, closing: true } : route
|
|
115
|
-
),
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
case 'POP_TO_TOP': {
|
|
120
|
-
const popCount = state.routes.length - 1;
|
|
121
|
-
return this.getStateForAction(state, TrueSheetActions.pop(popCount), options);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
case 'POP_TO': {
|
|
125
|
-
const targetName =
|
|
126
|
-
'payload' in action && typeof action.payload?.name === 'string'
|
|
127
|
-
? action.payload.name
|
|
128
|
-
: null;
|
|
129
|
-
|
|
130
|
-
if (!targetName) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const targetIndex = state.routes.findIndex((r) => r.name === targetName);
|
|
135
|
-
|
|
136
|
-
// Target not found or is the current route
|
|
137
|
-
if (targetIndex === -1 || targetIndex >= state.index) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const popCount = state.routes.length - 1 - targetIndex;
|
|
142
|
-
return this.getStateForAction(state, TrueSheetActions.pop(popCount), options);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
case 'REMOVE': {
|
|
146
|
-
// Actually remove the closing route and all routes above it
|
|
147
|
-
const routeKey = action.source;
|
|
148
|
-
const routeIndex = routeKey
|
|
149
|
-
? state.routes.findIndex((r) => r.key === routeKey)
|
|
150
|
-
: state.routes.findIndex((r) => r.closing);
|
|
151
|
-
|
|
152
|
-
if (routeIndex === -1) {
|
|
153
|
-
return state;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Remove the route and all routes above it (they were dismissed together)
|
|
157
|
-
const routes = state.routes.filter((_, i) => i < routeIndex);
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
...state,
|
|
161
|
-
index: Math.min(state.index, routes.length - 1),
|
|
162
|
-
routes,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
default:
|
|
167
|
-
return baseRouter.getStateForAction(state, action, options);
|
|
168
|
-
}
|
|
202
|
+
const result = getTrueSheetStateForAction(state, action);
|
|
203
|
+
|
|
204
|
+
return result === undefined ? baseRouter.getStateForAction(state, action, options) : result;
|
|
169
205
|
},
|
|
170
206
|
|
|
171
207
|
getRehydratedState(partialState, { routeNames, routeParamList, routeGetIdList }) {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { TrueSheetActions, type TrueSheetActionType } from '../actions';
|
|
2
|
+
import { getResizeRouteIndex, getTrueSheetStateForAction } from '../createTrueSheetRouter';
|
|
3
|
+
import type { StackRouterFactory, TrueSheetRouterFactory, TrueSheetRouterState } from './types';
|
|
4
|
+
|
|
5
|
+
type ActionResult = { state: TrueSheetRouterState; affectedRouteKey?: string };
|
|
6
|
+
|
|
7
|
+
type RouterExtension = (context: {
|
|
8
|
+
baseRouter: {
|
|
9
|
+
getStateForAction(
|
|
10
|
+
state: TrueSheetRouterState,
|
|
11
|
+
action: TrueSheetActionType,
|
|
12
|
+
options: object
|
|
13
|
+
): ActionResult | null;
|
|
14
|
+
};
|
|
15
|
+
options: { initialRouteName?: string };
|
|
16
|
+
}) => object;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `extendRouter` from Expo Router 58+. Declared locally because the
|
|
20
|
+
* Expo Router types this package builds against predate it.
|
|
21
|
+
*/
|
|
22
|
+
export type ExtendRouter = (
|
|
23
|
+
base: StackRouterFactory,
|
|
24
|
+
extension: RouterExtension,
|
|
25
|
+
options: { type: string }
|
|
26
|
+
) => TrueSheetRouterFactory;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Router for Expo Router 58+, where navigator state is seeded by Expo Router
|
|
30
|
+
* (no `getInitialState`/`getRehydratedState`) and `getStateForAction` returns
|
|
31
|
+
* `{ state, affectedRouteKey }`.
|
|
32
|
+
*/
|
|
33
|
+
export const extendTrueSheetRouter = (
|
|
34
|
+
extendRouter: ExtendRouter,
|
|
35
|
+
stackRouter: StackRouterFactory
|
|
36
|
+
): TrueSheetRouterFactory =>
|
|
37
|
+
extendRouter(
|
|
38
|
+
stackRouter,
|
|
39
|
+
({ baseRouter, options }) => {
|
|
40
|
+
if (__DEV__ && options.initialRouteName === undefined) {
|
|
41
|
+
console.warn(
|
|
42
|
+
"TrueSheet: this Sheet layout has no `unstable_settings.anchor`. On Expo Router 58+, a sheet route opened directly (deep link or push from another navigator) renders without its base screen. Export `unstable_settings = { anchor: '<base route>' }` from the layout."
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
getStateForAction(
|
|
48
|
+
state: TrueSheetRouterState,
|
|
49
|
+
action: TrueSheetActionType,
|
|
50
|
+
config: object
|
|
51
|
+
): ActionResult | null {
|
|
52
|
+
const result = getTrueSheetStateForAction(state, action);
|
|
53
|
+
|
|
54
|
+
if (result === undefined) {
|
|
55
|
+
return baseRouter.getStateForAction(state, action, config);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (result === null) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const affectedIndex =
|
|
63
|
+
action.type === 'RESIZE' ? getResizeRouteIndex(state, action) : result.index;
|
|
64
|
+
|
|
65
|
+
return { state: result, affectedRouteKey: result.routes[affectedIndex]?.key };
|
|
66
|
+
},
|
|
67
|
+
actionCreators: TrueSheetActions,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
{ type: 'true-sheet' }
|
|
71
|
+
);
|