@lodev09/react-native-true-sheet 3.1.0-beta.9 → 3.1.1
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/TrueSheetModule.kt +8 -2
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +18 -2
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +103 -121
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +7 -2
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDialogObserver.kt +2 -2
- package/android/src/main/java/com/lodev09/truesheet/utils/ScreenUtils.kt +64 -81
- package/android/src/main/res/values/styles.xml +1 -0
- package/ios/TrueSheetModule.mm +17 -2
- package/ios/TrueSheetView.h +2 -0
- package/ios/TrueSheetView.mm +32 -3
- package/ios/TrueSheetViewController.h +2 -0
- package/ios/TrueSheetViewController.mm +45 -18
- package/lib/module/TrueSheet.js +3 -1
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/fabric/TrueSheetViewNativeComponent.ts +5 -2
- package/lib/module/navigation/TrueSheetRouter.js +119 -0
- package/lib/module/navigation/TrueSheetRouter.js.map +1 -0
- package/lib/module/navigation/TrueSheetView.js +169 -0
- package/lib/module/navigation/TrueSheetView.js.map +1 -0
- package/lib/module/navigation/createTrueSheetNavigator.js +59 -0
- package/lib/module/navigation/createTrueSheetNavigator.js.map +1 -0
- package/lib/module/navigation/index.js +6 -0
- package/lib/module/navigation/index.js.map +1 -0
- package/lib/module/navigation/types.js +4 -0
- package/lib/module/navigation/types.js.map +1 -0
- package/lib/module/navigation/useTrueSheetNavigation.js +26 -0
- package/lib/module/navigation/useTrueSheetNavigation.js.map +1 -0
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.types.d.ts +24 -0
- package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +3 -2
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/navigation/TrueSheetRouter.d.ts +57 -0
- package/lib/typescript/src/navigation/TrueSheetRouter.d.ts.map +1 -0
- package/lib/typescript/src/navigation/TrueSheetView.d.ts +10 -0
- package/lib/typescript/src/navigation/TrueSheetView.d.ts.map +1 -0
- package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts +35 -0
- package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts.map +1 -0
- package/lib/typescript/src/navigation/index.d.ts +6 -0
- package/lib/typescript/src/navigation/index.d.ts.map +1 -0
- package/lib/typescript/src/navigation/types.d.ts +125 -0
- package/lib/typescript/src/navigation/types.d.ts.map +1 -0
- package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts +23 -0
- package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts.map +1 -0
- package/package.json +12 -1
- package/src/TrueSheet.tsx +3 -1
- package/src/TrueSheet.types.ts +26 -0
- package/src/fabric/TrueSheetViewNativeComponent.ts +5 -2
- package/src/navigation/TrueSheetRouter.ts +172 -0
- package/src/navigation/TrueSheetView.tsx +271 -0
- package/src/navigation/createTrueSheetNavigator.tsx +89 -0
- package/src/navigation/index.ts +14 -0
- package/src/navigation/types.ts +176 -0
- package/src/navigation/useTrueSheetNavigation.ts +28 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import type { ParamListBase } from '@react-navigation/native';
|
|
2
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { TrueSheet } from '../TrueSheet';
|
|
5
|
+
import type {
|
|
6
|
+
DetentChangeEvent,
|
|
7
|
+
DetentInfoEventPayload,
|
|
8
|
+
DidBlurEvent,
|
|
9
|
+
DidFocusEvent,
|
|
10
|
+
DidPresentEvent,
|
|
11
|
+
DragBeginEvent,
|
|
12
|
+
DragChangeEvent,
|
|
13
|
+
DragEndEvent,
|
|
14
|
+
PositionChangeEvent,
|
|
15
|
+
PositionChangeEventPayload,
|
|
16
|
+
WillBlurEvent,
|
|
17
|
+
WillDismissEvent,
|
|
18
|
+
WillFocusEvent,
|
|
19
|
+
WillPresentEvent,
|
|
20
|
+
} from '../TrueSheet.types';
|
|
21
|
+
import type {
|
|
22
|
+
TrueSheetDescriptorMap,
|
|
23
|
+
TrueSheetNavigationEventMap,
|
|
24
|
+
TrueSheetNavigationHelpers,
|
|
25
|
+
TrueSheetNavigationOptions,
|
|
26
|
+
TrueSheetNavigationProp,
|
|
27
|
+
TrueSheetNavigationState,
|
|
28
|
+
} from './types';
|
|
29
|
+
import { TrueSheetActions } from './TrueSheetRouter';
|
|
30
|
+
|
|
31
|
+
type EmitFn = TrueSheetNavigationHelpers['emit'];
|
|
32
|
+
|
|
33
|
+
type TrueSheetScreenProps = Omit<TrueSheetNavigationOptions, 'detentIndex'> & {
|
|
34
|
+
detentIndex: number;
|
|
35
|
+
resizeKey?: number;
|
|
36
|
+
navigation: TrueSheetNavigationProp<ParamListBase>;
|
|
37
|
+
emit: EmitFn;
|
|
38
|
+
routeKey: string;
|
|
39
|
+
closing?: boolean;
|
|
40
|
+
children: React.ReactNode;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function TrueSheetScreen({
|
|
44
|
+
detentIndex,
|
|
45
|
+
resizeKey,
|
|
46
|
+
navigation,
|
|
47
|
+
emit,
|
|
48
|
+
routeKey,
|
|
49
|
+
closing,
|
|
50
|
+
detents,
|
|
51
|
+
children,
|
|
52
|
+
...sheetProps
|
|
53
|
+
}: TrueSheetScreenProps) {
|
|
54
|
+
const ref = useRef<TrueSheet>(null);
|
|
55
|
+
const isDismissedRef = useRef(false);
|
|
56
|
+
const isFirstRenderRef = useRef(true);
|
|
57
|
+
// Capture initial detent index only once
|
|
58
|
+
const initialDetentIndexRef = useRef(detentIndex);
|
|
59
|
+
|
|
60
|
+
// Handle closing state change - dismiss the sheet and wait for animation
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (closing && !isDismissedRef.current) {
|
|
63
|
+
isDismissedRef.current = true;
|
|
64
|
+
(async () => {
|
|
65
|
+
await ref.current?.dismiss();
|
|
66
|
+
navigation.dispatch({ ...TrueSheetActions.remove(), source: routeKey });
|
|
67
|
+
})();
|
|
68
|
+
} else if (closing && isDismissedRef.current) {
|
|
69
|
+
// Sheet was already dismissed by user swipe, just remove
|
|
70
|
+
navigation.dispatch({ ...TrueSheetActions.remove(), source: routeKey });
|
|
71
|
+
}
|
|
72
|
+
}, [closing, navigation, routeKey]);
|
|
73
|
+
|
|
74
|
+
// Handle resize - resizeKey ensures effect runs even when resizing to same index
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
// Skip first render - initialDetentIndex handles initial presentation
|
|
77
|
+
if (isFirstRenderRef.current) {
|
|
78
|
+
isFirstRenderRef.current = false;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
ref.current?.resize(detentIndex);
|
|
83
|
+
}, [detentIndex, resizeKey]);
|
|
84
|
+
|
|
85
|
+
const emitEvent = useCallback(
|
|
86
|
+
(
|
|
87
|
+
type: keyof TrueSheetNavigationEventMap,
|
|
88
|
+
data: DetentInfoEventPayload | PositionChangeEventPayload | undefined
|
|
89
|
+
) => {
|
|
90
|
+
emit({
|
|
91
|
+
type,
|
|
92
|
+
target: routeKey,
|
|
93
|
+
data,
|
|
94
|
+
} as Parameters<EmitFn>[0]);
|
|
95
|
+
},
|
|
96
|
+
[emit, routeKey]
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const onWillPresent = useCallback(
|
|
100
|
+
(e: WillPresentEvent) => {
|
|
101
|
+
emitEvent('sheetWillPresent', e.nativeEvent);
|
|
102
|
+
},
|
|
103
|
+
[emitEvent]
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const onDidPresent = useCallback(
|
|
107
|
+
(e: DidPresentEvent) => {
|
|
108
|
+
emitEvent('sheetDidPresent', e.nativeEvent);
|
|
109
|
+
},
|
|
110
|
+
[emitEvent]
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const onWillDismiss = useCallback(
|
|
114
|
+
(_e: WillDismissEvent) => {
|
|
115
|
+
emitEvent('sheetWillDismiss', undefined);
|
|
116
|
+
},
|
|
117
|
+
[emitEvent]
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const onDidDismiss = useCallback(() => {
|
|
121
|
+
emitEvent('sheetDidDismiss', undefined);
|
|
122
|
+
// User dismissed the sheet by swiping down
|
|
123
|
+
if (!isDismissedRef.current) {
|
|
124
|
+
isDismissedRef.current = true;
|
|
125
|
+
navigation.goBack();
|
|
126
|
+
}
|
|
127
|
+
}, [emitEvent, navigation]);
|
|
128
|
+
|
|
129
|
+
const onDetentChange = useCallback(
|
|
130
|
+
(e: DetentChangeEvent) => {
|
|
131
|
+
emitEvent('sheetDetentChange', e.nativeEvent);
|
|
132
|
+
},
|
|
133
|
+
[emitEvent]
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const onDragBegin = useCallback(
|
|
137
|
+
(e: DragBeginEvent) => {
|
|
138
|
+
emitEvent('sheetDragBegin', e.nativeEvent);
|
|
139
|
+
},
|
|
140
|
+
[emitEvent]
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const onDragChange = useCallback(
|
|
144
|
+
(e: DragChangeEvent) => {
|
|
145
|
+
emitEvent('sheetDragChange', e.nativeEvent);
|
|
146
|
+
},
|
|
147
|
+
[emitEvent]
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const onDragEnd = useCallback(
|
|
151
|
+
(e: DragEndEvent) => {
|
|
152
|
+
emitEvent('sheetDragEnd', e.nativeEvent);
|
|
153
|
+
},
|
|
154
|
+
[emitEvent]
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const onPositionChange = useCallback(
|
|
158
|
+
(e: PositionChangeEvent) => {
|
|
159
|
+
emitEvent('sheetPositionChange', e.nativeEvent);
|
|
160
|
+
},
|
|
161
|
+
[emitEvent]
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const onWillFocus = useCallback(
|
|
165
|
+
(_e: WillFocusEvent) => {
|
|
166
|
+
emitEvent('sheetWillFocus', undefined);
|
|
167
|
+
},
|
|
168
|
+
[emitEvent]
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const onDidFocus = useCallback(
|
|
172
|
+
(_e: DidFocusEvent) => {
|
|
173
|
+
emitEvent('sheetDidFocus', undefined);
|
|
174
|
+
},
|
|
175
|
+
[emitEvent]
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const onWillBlur = useCallback(
|
|
179
|
+
(_e: WillBlurEvent) => {
|
|
180
|
+
emitEvent('sheetWillBlur', undefined);
|
|
181
|
+
},
|
|
182
|
+
[emitEvent]
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const onDidBlur = useCallback(
|
|
186
|
+
(_e: DidBlurEvent) => {
|
|
187
|
+
emitEvent('sheetDidBlur', undefined);
|
|
188
|
+
},
|
|
189
|
+
[emitEvent]
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<TrueSheet
|
|
194
|
+
ref={ref}
|
|
195
|
+
name={`navigation-sheet-${routeKey}`}
|
|
196
|
+
initialDetentIndex={initialDetentIndexRef.current}
|
|
197
|
+
detents={detents}
|
|
198
|
+
onWillPresent={onWillPresent}
|
|
199
|
+
onDidPresent={onDidPresent}
|
|
200
|
+
onWillDismiss={onWillDismiss}
|
|
201
|
+
onDidDismiss={onDidDismiss}
|
|
202
|
+
onDetentChange={onDetentChange}
|
|
203
|
+
onDragBegin={onDragBegin}
|
|
204
|
+
onDragChange={onDragChange}
|
|
205
|
+
onDragEnd={onDragEnd}
|
|
206
|
+
onPositionChange={onPositionChange}
|
|
207
|
+
onWillFocus={onWillFocus}
|
|
208
|
+
onDidFocus={onDidFocus}
|
|
209
|
+
onWillBlur={onWillBlur}
|
|
210
|
+
onDidBlur={onDidBlur}
|
|
211
|
+
{...sheetProps}
|
|
212
|
+
>
|
|
213
|
+
{children}
|
|
214
|
+
</TrueSheet>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const DEFAULT_DETENTS: ('auto' | number)[] = ['auto'];
|
|
219
|
+
|
|
220
|
+
function clampDetentIndex(index: number, detentsLength: number): number {
|
|
221
|
+
return Math.min(index, Math.max(detentsLength - 1, 0));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
interface TrueSheetViewProps {
|
|
225
|
+
state: TrueSheetNavigationState<ParamListBase>;
|
|
226
|
+
navigation: TrueSheetNavigationHelpers;
|
|
227
|
+
descriptors: TrueSheetDescriptorMap;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function TrueSheetView({ state, navigation, descriptors }: TrueSheetViewProps) {
|
|
231
|
+
// First route is the base screen, rest are sheets
|
|
232
|
+
const [baseRoute, ...sheetRoutes] = state.routes;
|
|
233
|
+
|
|
234
|
+
const baseDescriptor = baseRoute ? descriptors[baseRoute.key] : null;
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<>
|
|
238
|
+
{/* Render base screen */}
|
|
239
|
+
{baseDescriptor?.render()}
|
|
240
|
+
|
|
241
|
+
{/* Render sheet screens */}
|
|
242
|
+
{sheetRoutes.map((route) => {
|
|
243
|
+
const descriptor = descriptors[route.key];
|
|
244
|
+
|
|
245
|
+
if (!descriptor) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const { options, navigation: screenNavigation, render } = descriptor;
|
|
250
|
+
const { detentIndex = 0, detents = DEFAULT_DETENTS, ...sheetProps } = options;
|
|
251
|
+
const resolvedIndex = clampDetentIndex(route.resizeIndex ?? detentIndex, detents.length);
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<TrueSheetScreen
|
|
255
|
+
key={route.key}
|
|
256
|
+
routeKey={route.key}
|
|
257
|
+
closing={route.closing}
|
|
258
|
+
detentIndex={resolvedIndex}
|
|
259
|
+
resizeKey={route.resizeKey}
|
|
260
|
+
detents={detents}
|
|
261
|
+
navigation={screenNavigation}
|
|
262
|
+
emit={navigation.emit}
|
|
263
|
+
{...sheetProps}
|
|
264
|
+
>
|
|
265
|
+
{render()}
|
|
266
|
+
</TrueSheetScreen>
|
|
267
|
+
);
|
|
268
|
+
})}
|
|
269
|
+
</>
|
|
270
|
+
);
|
|
271
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createNavigatorFactory,
|
|
3
|
+
type NavigatorTypeBagBase,
|
|
4
|
+
type ParamListBase,
|
|
5
|
+
type StaticConfig,
|
|
6
|
+
type TypedNavigator,
|
|
7
|
+
useNavigationBuilder,
|
|
8
|
+
} from '@react-navigation/native';
|
|
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
|
+
function TrueSheetNavigator({
|
|
22
|
+
id,
|
|
23
|
+
initialRouteName,
|
|
24
|
+
children,
|
|
25
|
+
screenListeners,
|
|
26
|
+
screenOptions,
|
|
27
|
+
}: TrueSheetNavigatorProps) {
|
|
28
|
+
const { state, descriptors, navigation, NavigationContent } = useNavigationBuilder<
|
|
29
|
+
TrueSheetNavigationState<ParamListBase>,
|
|
30
|
+
TrueSheetRouterOptions,
|
|
31
|
+
TrueSheetActionHelpers<ParamListBase>,
|
|
32
|
+
TrueSheetNavigationOptions,
|
|
33
|
+
TrueSheetNavigationEventMap
|
|
34
|
+
>(TrueSheetRouter, {
|
|
35
|
+
id,
|
|
36
|
+
initialRouteName,
|
|
37
|
+
children,
|
|
38
|
+
screenListeners,
|
|
39
|
+
screenOptions,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<NavigationContent>
|
|
44
|
+
<TrueSheetView state={state} navigation={navigation} descriptors={descriptors} />
|
|
45
|
+
</NavigationContent>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a TrueSheet navigator.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* const Sheet = createTrueSheetNavigator();
|
|
55
|
+
*
|
|
56
|
+
* function App() {
|
|
57
|
+
* return (
|
|
58
|
+
* <Sheet.Navigator>
|
|
59
|
+
* <Sheet.Screen name="Home" component={HomeScreen} />
|
|
60
|
+
* <Sheet.Screen
|
|
61
|
+
* name="Details"
|
|
62
|
+
* component={DetailsSheet}
|
|
63
|
+
* options={{ detents: [0.5, 1] }}
|
|
64
|
+
* />
|
|
65
|
+
* </Sheet.Navigator>
|
|
66
|
+
* );
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export const createTrueSheetNavigator = <
|
|
71
|
+
const ParamList extends ParamListBase,
|
|
72
|
+
const NavigatorID extends string | undefined = undefined,
|
|
73
|
+
const TypeBag extends NavigatorTypeBagBase = {
|
|
74
|
+
ParamList: ParamList;
|
|
75
|
+
NavigatorID: NavigatorID;
|
|
76
|
+
State: TrueSheetNavigationState<ParamList>;
|
|
77
|
+
ScreenOptions: TrueSheetNavigationOptions;
|
|
78
|
+
EventMap: TrueSheetNavigationEventMap;
|
|
79
|
+
NavigationList: {
|
|
80
|
+
[RouteName in keyof ParamList]: TrueSheetNavigationProp<ParamList, RouteName, NavigatorID>;
|
|
81
|
+
};
|
|
82
|
+
Navigator: typeof TrueSheetNavigator;
|
|
83
|
+
},
|
|
84
|
+
const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
|
|
85
|
+
>(
|
|
86
|
+
config?: Config
|
|
87
|
+
): TypedNavigator<TypeBag, Config> => {
|
|
88
|
+
return createNavigatorFactory(TrueSheetNavigator)(config);
|
|
89
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createTrueSheetNavigator } from './createTrueSheetNavigator';
|
|
2
|
+
export { TrueSheetActions, type TrueSheetActionType } from './TrueSheetRouter';
|
|
3
|
+
export { useTrueSheetNavigation } from './useTrueSheetNavigation';
|
|
4
|
+
|
|
5
|
+
export type { DetentInfoEventPayload, PositionChangeEventPayload } from '../TrueSheet.types';
|
|
6
|
+
|
|
7
|
+
export type {
|
|
8
|
+
TrueSheetNavigationEventMap,
|
|
9
|
+
TrueSheetNavigationHelpers,
|
|
10
|
+
TrueSheetNavigationOptions,
|
|
11
|
+
TrueSheetNavigationProp,
|
|
12
|
+
TrueSheetNavigationState,
|
|
13
|
+
TrueSheetScreenProps,
|
|
14
|
+
} from './types';
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DefaultNavigatorOptions,
|
|
3
|
+
Descriptor,
|
|
4
|
+
NavigationHelpers,
|
|
5
|
+
NavigationProp,
|
|
6
|
+
NavigationState,
|
|
7
|
+
ParamListBase,
|
|
8
|
+
RouteProp,
|
|
9
|
+
StackActionHelpers,
|
|
10
|
+
} from '@react-navigation/native';
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
DetentInfoEventPayload,
|
|
14
|
+
PositionChangeEventPayload,
|
|
15
|
+
TrueSheetProps,
|
|
16
|
+
} from '../TrueSheet.types';
|
|
17
|
+
|
|
18
|
+
export type TrueSheetNavigationEventMap = {
|
|
19
|
+
/**
|
|
20
|
+
* Event fired when the sheet is about to be presented.
|
|
21
|
+
*/
|
|
22
|
+
sheetWillPresent: { data: DetentInfoEventPayload };
|
|
23
|
+
/**
|
|
24
|
+
* Event fired when the sheet has been presented.
|
|
25
|
+
*/
|
|
26
|
+
sheetDidPresent: { data: DetentInfoEventPayload };
|
|
27
|
+
/**
|
|
28
|
+
* Event fired when the sheet is about to be dismissed.
|
|
29
|
+
*/
|
|
30
|
+
sheetWillDismiss: { data: undefined };
|
|
31
|
+
/**
|
|
32
|
+
* Event fired when the sheet has been dismissed.
|
|
33
|
+
*/
|
|
34
|
+
sheetDidDismiss: { data: undefined };
|
|
35
|
+
/**
|
|
36
|
+
* Event fired when the sheet's detent changes.
|
|
37
|
+
*/
|
|
38
|
+
sheetDetentChange: { data: DetentInfoEventPayload };
|
|
39
|
+
/**
|
|
40
|
+
* Event fired when the user starts dragging the sheet.
|
|
41
|
+
*/
|
|
42
|
+
sheetDragBegin: { data: DetentInfoEventPayload };
|
|
43
|
+
/**
|
|
44
|
+
* Event fired while the user is dragging the sheet.
|
|
45
|
+
*/
|
|
46
|
+
sheetDragChange: { data: DetentInfoEventPayload };
|
|
47
|
+
/**
|
|
48
|
+
* Event fired when the user stops dragging the sheet.
|
|
49
|
+
*/
|
|
50
|
+
sheetDragEnd: { data: DetentInfoEventPayload };
|
|
51
|
+
/**
|
|
52
|
+
* Event fired when the sheet's position changes.
|
|
53
|
+
*/
|
|
54
|
+
sheetPositionChange: { data: PositionChangeEventPayload };
|
|
55
|
+
/**
|
|
56
|
+
* Event fired when the sheet is about to regain focus.
|
|
57
|
+
*/
|
|
58
|
+
sheetWillFocus: { data: undefined };
|
|
59
|
+
/**
|
|
60
|
+
* Event fired when the sheet regains focus.
|
|
61
|
+
*/
|
|
62
|
+
sheetDidFocus: { data: undefined };
|
|
63
|
+
/**
|
|
64
|
+
* Event fired when the sheet is about to lose focus.
|
|
65
|
+
*/
|
|
66
|
+
sheetWillBlur: { data: undefined };
|
|
67
|
+
/**
|
|
68
|
+
* Event fired when the sheet loses focus.
|
|
69
|
+
*/
|
|
70
|
+
sheetDidBlur: { data: undefined };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type TrueSheetNavigationState<ParamList extends ParamListBase> = Omit<
|
|
74
|
+
NavigationState<ParamList>,
|
|
75
|
+
'routes'
|
|
76
|
+
> & {
|
|
77
|
+
type: 'true-sheet';
|
|
78
|
+
routes: (NavigationState<ParamList>['routes'][number] & {
|
|
79
|
+
resizeIndex?: number;
|
|
80
|
+
resizeKey?: number;
|
|
81
|
+
closing?: boolean;
|
|
82
|
+
})[];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type TrueSheetActionHelpers<ParamList extends ParamListBase> =
|
|
86
|
+
StackActionHelpers<ParamList> & {
|
|
87
|
+
/**
|
|
88
|
+
* Resize the sheet to a specific detent index.
|
|
89
|
+
*/
|
|
90
|
+
resize(index?: number): void;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export type TrueSheetNavigationProp<
|
|
94
|
+
ParamList extends ParamListBase,
|
|
95
|
+
RouteName extends keyof ParamList = string,
|
|
96
|
+
NavigatorID extends string | undefined = undefined,
|
|
97
|
+
> = NavigationProp<
|
|
98
|
+
ParamList,
|
|
99
|
+
RouteName,
|
|
100
|
+
NavigatorID,
|
|
101
|
+
TrueSheetNavigationState<ParamList>,
|
|
102
|
+
TrueSheetNavigationOptions,
|
|
103
|
+
TrueSheetNavigationEventMap
|
|
104
|
+
> &
|
|
105
|
+
TrueSheetActionHelpers<ParamList>;
|
|
106
|
+
|
|
107
|
+
export type TrueSheetScreenProps<
|
|
108
|
+
ParamList extends ParamListBase,
|
|
109
|
+
RouteName extends keyof ParamList = string,
|
|
110
|
+
NavigatorID extends string | undefined = undefined,
|
|
111
|
+
> = {
|
|
112
|
+
navigation: TrueSheetNavigationProp<ParamList, RouteName, NavigatorID>;
|
|
113
|
+
route: RouteProp<ParamList, RouteName>;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type TrueSheetNavigationHelpers = NavigationHelpers<
|
|
117
|
+
ParamListBase,
|
|
118
|
+
TrueSheetNavigationEventMap
|
|
119
|
+
>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Screen options for TrueSheet navigator screens.
|
|
123
|
+
*/
|
|
124
|
+
export type TrueSheetNavigationOptions = Pick<
|
|
125
|
+
TrueSheetProps,
|
|
126
|
+
| 'detents'
|
|
127
|
+
| 'backgroundColor'
|
|
128
|
+
| 'cornerRadius'
|
|
129
|
+
| 'dismissible'
|
|
130
|
+
| 'draggable'
|
|
131
|
+
| 'grabber'
|
|
132
|
+
| 'grabberOptions'
|
|
133
|
+
| 'dimmed'
|
|
134
|
+
| 'dimmedDetentIndex'
|
|
135
|
+
| 'blurTint'
|
|
136
|
+
| 'blurOptions'
|
|
137
|
+
| 'maxHeight'
|
|
138
|
+
| 'edgeToEdgeFullScreen'
|
|
139
|
+
| 'scrollable'
|
|
140
|
+
| 'keyboardMode'
|
|
141
|
+
| 'pageSizing'
|
|
142
|
+
| 'header'
|
|
143
|
+
| 'footer'
|
|
144
|
+
> & {
|
|
145
|
+
/**
|
|
146
|
+
* The detent index to present at.
|
|
147
|
+
* @default 0
|
|
148
|
+
*/
|
|
149
|
+
detentIndex?: number;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export type TrueSheetNavigatorProps = DefaultNavigatorOptions<
|
|
153
|
+
ParamListBase,
|
|
154
|
+
string | undefined,
|
|
155
|
+
TrueSheetNavigationState<ParamListBase>,
|
|
156
|
+
TrueSheetNavigationOptions,
|
|
157
|
+
TrueSheetNavigationEventMap,
|
|
158
|
+
unknown
|
|
159
|
+
> & {
|
|
160
|
+
/**
|
|
161
|
+
* The name of the route to use as the base screen.
|
|
162
|
+
* This screen will be rendered as a regular screen, while other screens are presented as sheets.
|
|
163
|
+
* Defaults to the first screen defined in the navigator.
|
|
164
|
+
*/
|
|
165
|
+
initialRouteName?: string;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export type TrueSheetDescriptor = Descriptor<
|
|
169
|
+
TrueSheetNavigationOptions,
|
|
170
|
+
TrueSheetNavigationProp<ParamListBase>,
|
|
171
|
+
RouteProp<ParamListBase>
|
|
172
|
+
>;
|
|
173
|
+
|
|
174
|
+
export type TrueSheetDescriptorMap = {
|
|
175
|
+
[key: string]: TrueSheetDescriptor;
|
|
176
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useNavigation, type ParamListBase } from '@react-navigation/native';
|
|
2
|
+
|
|
3
|
+
import type { TrueSheetNavigationProp } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to access TrueSheet navigation with the resize helper.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function MySheet() {
|
|
11
|
+
* const navigation = useTrueSheetNavigation();
|
|
12
|
+
*
|
|
13
|
+
* // Resize to a specific detent
|
|
14
|
+
* const handleExpand = () => {
|
|
15
|
+
* navigation.resize(1); // Resize to second detent
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <Button title="Expand" onPress={handleExpand} />
|
|
20
|
+
* );
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function useTrueSheetNavigation<
|
|
25
|
+
T extends ParamListBase = ParamListBase,
|
|
26
|
+
>(): TrueSheetNavigationProp<T> {
|
|
27
|
+
return useNavigation<TrueSheetNavigationProp<T>>();
|
|
28
|
+
}
|