@lodev09/react-native-true-sheet 4.0.0-beta.1 → 4.0.0-beta.2
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/src/main/java/com/lodev09/truesheet/TrueSheetFooterView.kt +8 -2
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +9 -2
- package/android/src/main/java/com/lodev09/truesheet/utils/TouchEventDeduper.kt +31 -0
- package/ios/TrueSheetViewController.mm +1 -4
- package/lib/module/TrueSheet.js +12 -6
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/TrueSheet.web.js +11 -9
- package/lib/module/TrueSheet.web.js.map +1 -1
- package/lib/module/TrueSheetPeek.web.js +3 -3
- package/lib/module/TrueSheetPeek.web.js.map +1 -1
- package/lib/module/mocks/navigation.js +31 -21
- package/lib/module/mocks/navigation.js.map +1 -1
- package/lib/module/mocks/navigationExpoRouter.js +21 -0
- package/lib/module/mocks/navigationExpoRouter.js.map +1 -0
- package/lib/module/mocks/reanimated.js +1 -1
- package/lib/module/mocks/reanimated.js.map +1 -1
- package/lib/module/navigation/{TrueSheetView.js → TrueSheetNavigatorContent.js} +14 -12
- package/lib/module/navigation/TrueSheetNavigatorContent.js.map +1 -0
- package/lib/module/navigation/actions.js +50 -0
- package/lib/module/navigation/actions.js.map +1 -0
- package/lib/module/navigation/{TrueSheetRouter.js → createTrueSheetRouter.js} +20 -24
- package/lib/module/navigation/createTrueSheetRouter.js.map +1 -0
- package/lib/module/navigation/expo-router/index.js +48 -0
- package/lib/module/navigation/expo-router/index.js.map +1 -0
- package/lib/module/navigation/index.js +43 -2
- package/lib/module/navigation/index.js.map +1 -1
- package/lib/module/navigation/navigator.js +10 -0
- package/lib/module/navigation/navigator.js.map +1 -0
- package/lib/module/navigation/screen/ReanimatedTrueSheetScreen.js +2 -2
- package/lib/module/navigation/screen/ReanimatedTrueSheetScreen.js.map +1 -1
- package/lib/module/navigation/screen/TrueSheetScreen.js +2 -2
- package/lib/module/navigation/screen/TrueSheetScreen.js.map +1 -1
- package/lib/module/navigation/screen/useSheetScreenState.js +4 -4
- package/lib/module/navigation/screen/useSheetScreenState.js.map +1 -1
- package/lib/module/navigation/useTrueSheetNavigation.js +1 -1
- package/lib/module/navigation/useTrueSheetNavigation.js.map +1 -1
- package/lib/module/web/dom.js +10 -0
- package/lib/module/web/dom.js.map +1 -0
- package/lib/module/web/vaul/helpers.js +10 -4
- package/lib/module/web/vaul/helpers.js.map +1 -1
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.web.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheetPeek.web.d.ts.map +1 -1
- package/lib/typescript/src/mocks/navigation.d.ts +5 -1
- package/lib/typescript/src/mocks/navigation.d.ts.map +1 -1
- package/lib/typescript/src/mocks/navigationExpoRouter.d.ts +22 -0
- package/lib/typescript/src/mocks/navigationExpoRouter.d.ts.map +1 -0
- package/lib/typescript/src/mocks/reanimated.d.ts.map +1 -1
- package/lib/typescript/src/navigation/TrueSheetNavigatorContent.d.ts +5 -0
- package/lib/typescript/src/navigation/TrueSheetNavigatorContent.d.ts.map +1 -0
- package/lib/typescript/src/navigation/actions.d.ts +71 -0
- package/lib/typescript/src/navigation/actions.d.ts.map +1 -0
- package/lib/typescript/src/navigation/createTrueSheetRouter.d.ts +14 -0
- package/lib/typescript/src/navigation/createTrueSheetRouter.d.ts.map +1 -0
- package/lib/typescript/src/navigation/expo-router/index.d.ts +37 -0
- package/lib/typescript/src/navigation/expo-router/index.d.ts.map +1 -0
- package/lib/typescript/src/navigation/index.d.ts +42 -2
- package/lib/typescript/src/navigation/index.d.ts.map +1 -1
- package/lib/typescript/src/navigation/navigator.d.ts +7 -0
- package/lib/typescript/src/navigation/navigator.d.ts.map +1 -0
- package/lib/typescript/src/navigation/screen/ReanimatedTrueSheetScreen.d.ts +1 -1
- package/lib/typescript/src/navigation/screen/ReanimatedTrueSheetScreen.d.ts.map +1 -1
- package/lib/typescript/src/navigation/screen/TrueSheetScreen.d.ts +1 -1
- package/lib/typescript/src/navigation/screen/TrueSheetScreen.d.ts.map +1 -1
- package/lib/typescript/src/navigation/screen/types.d.ts +3 -4
- package/lib/typescript/src/navigation/screen/types.d.ts.map +1 -1
- package/lib/typescript/src/navigation/screen/useSheetScreenState.d.ts +3 -5
- package/lib/typescript/src/navigation/screen/useSheetScreenState.d.ts.map +1 -1
- package/lib/typescript/src/navigation/types.d.ts +24 -0
- package/lib/typescript/src/navigation/types.d.ts.map +1 -1
- package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts +1 -1
- package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts.map +1 -1
- package/lib/typescript/src/web/dom.d.ts +7 -0
- package/lib/typescript/src/web/dom.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/helpers.d.ts.map +1 -1
- package/package.json +23 -8
- package/src/TrueSheet.tsx +11 -8
- package/src/TrueSheet.web.tsx +14 -18
- package/src/TrueSheetPeek.web.tsx +4 -3
- package/src/mocks/navigation.ts +32 -25
- package/src/mocks/navigationExpoRouter.ts +40 -0
- package/src/mocks/reanimated.ts +8 -9
- package/src/navigation/{TrueSheetView.tsx → TrueSheetNavigatorContent.tsx} +24 -17
- package/src/navigation/actions.ts +78 -0
- package/src/navigation/createTrueSheetRouter.ts +222 -0
- package/src/navigation/expo-router/index.ts +89 -0
- package/src/navigation/index.ts +69 -2
- package/src/navigation/navigator.ts +18 -0
- package/src/navigation/screen/ReanimatedTrueSheetScreen.tsx +2 -2
- package/src/navigation/screen/TrueSheetScreen.tsx +2 -2
- package/src/navigation/screen/types.ts +4 -6
- package/src/navigation/screen/useSheetScreenState.ts +8 -15
- package/src/navigation/types.ts +32 -0
- package/src/navigation/useTrueSheetNavigation.ts +1 -1
- package/src/web/dom.ts +9 -0
- package/src/web/vaul/helpers.ts +13 -6
- package/lib/module/navigation/TrueSheetRouter.js.map +0 -1
- package/lib/module/navigation/TrueSheetView.js.map +0 -1
- package/lib/module/navigation/createTrueSheetNavigator.js +0 -63
- package/lib/module/navigation/createTrueSheetNavigator.js.map +0 -1
- package/lib/typescript/src/navigation/TrueSheetRouter.d.ts +0 -57
- package/lib/typescript/src/navigation/TrueSheetRouter.d.ts.map +0 -1
- package/lib/typescript/src/navigation/TrueSheetView.d.ts +0 -10
- package/lib/typescript/src/navigation/TrueSheetView.d.ts.map +0 -1
- package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts +0 -35
- package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts.map +0 -1
- package/src/navigation/TrueSheetRouter.ts +0 -234
- package/src/navigation/createTrueSheetNavigator.tsx +0 -93
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { nanoid } from 'nanoid/non-secure';
|
|
2
|
-
import {
|
|
3
|
-
type CommonActions,
|
|
4
|
-
type ParamListBase,
|
|
5
|
-
type Router,
|
|
6
|
-
StackRouter,
|
|
7
|
-
type StackActionType,
|
|
8
|
-
StackActions,
|
|
9
|
-
type StackRouterOptions,
|
|
10
|
-
} from '@react-navigation/core';
|
|
11
|
-
|
|
12
|
-
import type { TrueSheetNavigationState } from './types';
|
|
13
|
-
|
|
14
|
-
export type TrueSheetRouterOptions = StackRouterOptions;
|
|
15
|
-
|
|
16
|
-
export type TrueSheetActionType =
|
|
17
|
-
| StackActionType
|
|
18
|
-
| ReturnType<typeof CommonActions.goBack>
|
|
19
|
-
| {
|
|
20
|
-
type: 'RESIZE';
|
|
21
|
-
index: number;
|
|
22
|
-
source?: string;
|
|
23
|
-
target?: string;
|
|
24
|
-
}
|
|
25
|
-
| {
|
|
26
|
-
type: 'DISMISS';
|
|
27
|
-
source?: string;
|
|
28
|
-
target?: string;
|
|
29
|
-
}
|
|
30
|
-
| {
|
|
31
|
-
type: 'REMOVE';
|
|
32
|
-
source?: string;
|
|
33
|
-
target?: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const TrueSheetActions = {
|
|
37
|
-
...StackActions,
|
|
38
|
-
resize: (index: number): TrueSheetActionType => ({ type: 'RESIZE', index }),
|
|
39
|
-
dismiss: (): TrueSheetActionType => ({ type: 'DISMISS' }),
|
|
40
|
-
remove: (): TrueSheetActionType => ({ type: 'REMOVE' }),
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const ensureBaseRoute = <T extends { routes: { name: string }[] }>(
|
|
44
|
-
state: T,
|
|
45
|
-
baseRouteName: string | undefined,
|
|
46
|
-
routeParamList: Record<string, object | undefined> | undefined
|
|
47
|
-
): T & { index: number; routes: T['routes'] } => {
|
|
48
|
-
if (!baseRouteName) {
|
|
49
|
-
return state as T & { index: number; routes: T['routes'] };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const hasBaseRoute = state.routes.some((r) => r.name === baseRouteName);
|
|
53
|
-
|
|
54
|
-
if (!hasBaseRoute) {
|
|
55
|
-
const baseRoute = {
|
|
56
|
-
key: `${baseRouteName}-${nanoid()}`,
|
|
57
|
-
name: baseRouteName,
|
|
58
|
-
params: routeParamList?.[baseRouteName],
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
...state,
|
|
63
|
-
index: state.routes.length,
|
|
64
|
-
routes: [baseRoute, ...state.routes],
|
|
65
|
-
} as T & { index: number; routes: T['routes'] };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return state as T & { index: number; routes: T['routes'] };
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const TrueSheetRouter = (
|
|
72
|
-
routerOptions: StackRouterOptions
|
|
73
|
-
): Router<TrueSheetNavigationState<ParamListBase>, TrueSheetActionType> => {
|
|
74
|
-
const baseRouter = StackRouter(routerOptions) as unknown as Router<
|
|
75
|
-
TrueSheetNavigationState<ParamListBase>,
|
|
76
|
-
TrueSheetActionType
|
|
77
|
-
>;
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
...baseRouter,
|
|
81
|
-
type: 'true-sheet',
|
|
82
|
-
|
|
83
|
-
getInitialState(options) {
|
|
84
|
-
const state = baseRouter.getInitialState(options);
|
|
85
|
-
const baseRouteName = routerOptions.initialRouteName ?? options.routeNames[0];
|
|
86
|
-
const stateWithBaseRoute = ensureBaseRoute(state, baseRouteName, options.routeParamList);
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
...stateWithBaseRoute,
|
|
90
|
-
stale: false,
|
|
91
|
-
type: 'true-sheet',
|
|
92
|
-
key: `true-sheet-${nanoid()}`,
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
getStateForAction(state, action, options) {
|
|
97
|
-
switch (action.type) {
|
|
98
|
-
case 'RESIZE': {
|
|
99
|
-
const routeIndex =
|
|
100
|
-
action.target === state.key && action.source
|
|
101
|
-
? state.routes.findIndex((r) => r.key === action.source)
|
|
102
|
-
: state.index;
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
...state,
|
|
106
|
-
routes: state.routes.map((route, i) =>
|
|
107
|
-
i === routeIndex
|
|
108
|
-
? {
|
|
109
|
-
...route,
|
|
110
|
-
resizeIndex: action.index,
|
|
111
|
-
resizeKey: (route.resizeKey ?? 0) + 1,
|
|
112
|
-
}
|
|
113
|
-
: route
|
|
114
|
-
),
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
case 'GO_BACK':
|
|
119
|
-
case 'DISMISS': {
|
|
120
|
-
return this.getStateForAction(state, StackActions.pop(1), options);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
case 'POP': {
|
|
124
|
-
// Only base screen remains - let parent navigator handle it
|
|
125
|
-
if (state.routes.length <= 1) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const count =
|
|
130
|
-
'payload' in action && typeof action.payload?.count === 'number'
|
|
131
|
-
? action.payload.count
|
|
132
|
-
: 1;
|
|
133
|
-
|
|
134
|
-
// Calculate how many routes we can actually pop (don't pop base screen)
|
|
135
|
-
const maxPopCount = state.routes.length - 1;
|
|
136
|
-
const actualCount = Math.min(count, maxPopCount);
|
|
137
|
-
|
|
138
|
-
// Base screen - let parent navigator handle it
|
|
139
|
-
if (actualCount <= 0) {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Target index is the route we want to stay on (land on after pop)
|
|
144
|
-
// closingIndex is the first route to be dismissed (the one after target)
|
|
145
|
-
const targetIndex = state.routes.length - 1 - actualCount;
|
|
146
|
-
const closingIndex = targetIndex + 1;
|
|
147
|
-
|
|
148
|
-
// Mark only the bottom-most route to pop as closing
|
|
149
|
-
// The sheet's dismiss() will handle dismissing sheets above it first
|
|
150
|
-
return {
|
|
151
|
-
...state,
|
|
152
|
-
index: closingIndex,
|
|
153
|
-
routes: state.routes.map((route, i) =>
|
|
154
|
-
i === closingIndex ? { ...route, closing: true } : route
|
|
155
|
-
),
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
case 'POP_TO_TOP': {
|
|
160
|
-
const popCount = state.routes.length - 1;
|
|
161
|
-
return this.getStateForAction(state, StackActions.pop(popCount), options);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
case 'POP_TO': {
|
|
165
|
-
const targetName =
|
|
166
|
-
'payload' in action && typeof action.payload?.name === 'string'
|
|
167
|
-
? action.payload.name
|
|
168
|
-
: null;
|
|
169
|
-
|
|
170
|
-
if (!targetName) {
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const targetIndex = state.routes.findIndex((r) => r.name === targetName);
|
|
175
|
-
|
|
176
|
-
// Target not found or is the current route
|
|
177
|
-
if (targetIndex === -1 || targetIndex >= state.index) {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const popCount = state.routes.length - 1 - targetIndex;
|
|
182
|
-
return this.getStateForAction(state, StackActions.pop(popCount), options);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
case 'REMOVE': {
|
|
186
|
-
// Actually remove the closing route and all routes above it
|
|
187
|
-
const routeKey = action.source;
|
|
188
|
-
const routeIndex = routeKey
|
|
189
|
-
? state.routes.findIndex((r) => r.key === routeKey)
|
|
190
|
-
: state.routes.findIndex((r) => r.closing);
|
|
191
|
-
|
|
192
|
-
if (routeIndex === -1) {
|
|
193
|
-
return state;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Remove the route and all routes above it (they were dismissed together)
|
|
197
|
-
const routes = state.routes.filter((_, i) => i < routeIndex);
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
...state,
|
|
201
|
-
index: Math.min(state.index, routes.length - 1),
|
|
202
|
-
routes,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
default:
|
|
207
|
-
return baseRouter.getStateForAction(state, action, options);
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
getRehydratedState(partialState, { routeNames, routeParamList, routeGetIdList }) {
|
|
212
|
-
if (partialState.stale === false) {
|
|
213
|
-
return partialState;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const state = baseRouter.getRehydratedState(partialState, {
|
|
217
|
-
routeNames,
|
|
218
|
-
routeParamList,
|
|
219
|
-
routeGetIdList,
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
const baseRouteName = routerOptions.initialRouteName ?? routeNames[0];
|
|
223
|
-
const stateWithBaseRoute = ensureBaseRoute(state, baseRouteName, routeParamList);
|
|
224
|
-
|
|
225
|
-
return {
|
|
226
|
-
...stateWithBaseRoute,
|
|
227
|
-
type: 'true-sheet',
|
|
228
|
-
key: `true-sheet-${nanoid()}`,
|
|
229
|
-
};
|
|
230
|
-
},
|
|
231
|
-
|
|
232
|
-
actionCreators: TrueSheetActions,
|
|
233
|
-
};
|
|
234
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createNavigatorFactory,
|
|
3
|
-
type NavigatorTypeBagBase,
|
|
4
|
-
type ParamListBase,
|
|
5
|
-
type StaticConfig,
|
|
6
|
-
type TypedNavigator,
|
|
7
|
-
useNavigationBuilder,
|
|
8
|
-
} from '@react-navigation/core';
|
|
9
|
-
|
|
10
|
-
import { TrueSheetRouter, type TrueSheetRouterOptions } from './TrueSheetRouter';
|
|
11
|
-
import { TrueSheetView } from './TrueSheetView';
|
|
12
|
-
import type {
|
|
13
|
-
TrueSheetActionHelpers,
|
|
14
|
-
TrueSheetNavigationEventMap,
|
|
15
|
-
TrueSheetNavigationOptions,
|
|
16
|
-
TrueSheetNavigationProp,
|
|
17
|
-
TrueSheetNavigationState,
|
|
18
|
-
TrueSheetNavigatorProps,
|
|
19
|
-
} from './types';
|
|
20
|
-
|
|
21
|
-
const TrueSheetNavigator = ({
|
|
22
|
-
id,
|
|
23
|
-
initialRouteName,
|
|
24
|
-
children,
|
|
25
|
-
layout,
|
|
26
|
-
screenListeners,
|
|
27
|
-
screenOptions,
|
|
28
|
-
screenLayout,
|
|
29
|
-
}: TrueSheetNavigatorProps) => {
|
|
30
|
-
const { state, descriptors, navigation, NavigationContent } = useNavigationBuilder<
|
|
31
|
-
TrueSheetNavigationState<ParamListBase>,
|
|
32
|
-
TrueSheetRouterOptions,
|
|
33
|
-
TrueSheetActionHelpers<ParamListBase>,
|
|
34
|
-
TrueSheetNavigationOptions,
|
|
35
|
-
TrueSheetNavigationEventMap
|
|
36
|
-
>(TrueSheetRouter, {
|
|
37
|
-
id,
|
|
38
|
-
initialRouteName,
|
|
39
|
-
children,
|
|
40
|
-
layout,
|
|
41
|
-
screenListeners,
|
|
42
|
-
screenOptions,
|
|
43
|
-
screenLayout,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<NavigationContent>
|
|
48
|
-
<TrueSheetView state={state} navigation={navigation} descriptors={descriptors} />
|
|
49
|
-
</NavigationContent>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Creates a TrueSheet navigator.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```tsx
|
|
58
|
-
* const Sheet = createTrueSheetNavigator();
|
|
59
|
-
*
|
|
60
|
-
* function App() {
|
|
61
|
-
* return (
|
|
62
|
-
* <Sheet.Navigator>
|
|
63
|
-
* <Sheet.Screen name="Home" component={HomeScreen} />
|
|
64
|
-
* <Sheet.Screen
|
|
65
|
-
* name="Details"
|
|
66
|
-
* component={DetailsSheet}
|
|
67
|
-
* options={{ detents: [0.5, 1] }}
|
|
68
|
-
* />
|
|
69
|
-
* </Sheet.Navigator>
|
|
70
|
-
* );
|
|
71
|
-
* }
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export const createTrueSheetNavigator = <
|
|
75
|
-
const ParamList extends ParamListBase,
|
|
76
|
-
const NavigatorID extends string | undefined = undefined,
|
|
77
|
-
const TypeBag extends NavigatorTypeBagBase = {
|
|
78
|
-
ParamList: ParamList;
|
|
79
|
-
NavigatorID: NavigatorID;
|
|
80
|
-
State: TrueSheetNavigationState<ParamList>;
|
|
81
|
-
ScreenOptions: TrueSheetNavigationOptions;
|
|
82
|
-
EventMap: TrueSheetNavigationEventMap;
|
|
83
|
-
NavigationList: {
|
|
84
|
-
[RouteName in keyof ParamList]: TrueSheetNavigationProp<ParamList, RouteName, NavigatorID>;
|
|
85
|
-
};
|
|
86
|
-
Navigator: typeof TrueSheetNavigator;
|
|
87
|
-
},
|
|
88
|
-
const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
|
|
89
|
-
>(
|
|
90
|
-
config?: Config
|
|
91
|
-
): TypedNavigator<TypeBag, Config> => {
|
|
92
|
-
return createNavigatorFactory(TrueSheetNavigator)(config);
|
|
93
|
-
};
|