UNPKG

17 kBTypeScriptView Raw
1import type { HeaderBackButton, HeaderBackButtonProps, HeaderButtonProps, HeaderOptions, HeaderTitleProps } from '@react-navigation/elements';
2import type { Descriptor, NavigationHelpers, NavigationProp, ParamListBase, Route, RouteProp, StackActionHelpers, StackNavigationState } from '@react-navigation/native';
3import type * as React from 'react';
4import type { Animated, StyleProp, TextStyle, ViewStyle } from 'react-native';
5export declare type StackNavigationEventMap = {
6 /**
7 * Event which fires when a transition animation starts.
8 */
9 transitionStart: {
10 data: {
11 closing: boolean;
12 };
13 };
14 /**
15 * Event which fires when a transition animation ends.
16 */
17 transitionEnd: {
18 data: {
19 closing: boolean;
20 };
21 };
22 /**
23 * Event which fires when navigation gesture starts.
24 */
25 gestureStart: {
26 data: undefined;
27 };
28 /**
29 * Event which fires when navigation gesture is completed.
30 */
31 gestureEnd: {
32 data: undefined;
33 };
34 /**
35 * Event which fires when navigation gesture is canceled.
36 */
37 gestureCancel: {
38 data: undefined;
39 };
40};
41export declare type StackNavigationHelpers = NavigationHelpers<ParamListBase, StackNavigationEventMap> & StackActionHelpers<ParamListBase>;
42export declare type StackNavigationProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = keyof ParamList, NavigatorID extends string | undefined = undefined> = NavigationProp<ParamList, RouteName, NavigatorID, StackNavigationState<ParamList>, StackNavigationOptions, StackNavigationEventMap> & StackActionHelpers<ParamList>;
43export declare type StackScreenProps<ParamList extends ParamListBase, RouteName extends keyof ParamList = keyof ParamList, NavigatorID extends string | undefined = undefined> = {
44 navigation: StackNavigationProp<ParamList, RouteName, NavigatorID>;
45 route: RouteProp<ParamList, RouteName>;
46};
47export declare type Layout = {
48 width: number;
49 height: number;
50};
51export declare type GestureDirection = 'horizontal' | 'horizontal-inverted' | 'vertical' | 'vertical-inverted';
52declare type SceneOptionsDefaults = TransitionPreset & {
53 animationEnabled: boolean;
54 gestureEnabled: boolean;
55 cardOverlayEnabled: boolean;
56 headerMode: StackHeaderMode;
57};
58export declare type Scene = {
59 /**
60 * Route object for the current screen.
61 */
62 route: Route<string>;
63 /**
64 * Descriptor object for the screen.
65 */
66 descriptor: Omit<StackDescriptor, 'options'> & {
67 options: Omit<StackDescriptor['options'], keyof SceneOptionsDefaults> & SceneOptionsDefaults;
68 };
69 /**
70 * Animated nodes representing the progress of the animation.
71 */
72 progress: SceneProgress;
73};
74export declare type SceneProgress = {
75 /**
76 * Progress value of the current screen.
77 */
78 current: Animated.AnimatedInterpolation;
79 /**
80 * Progress value for the screen after this one in the stack.
81 * This can be `undefined` in case the screen animating is the last one.
82 */
83 next?: Animated.AnimatedInterpolation;
84 /**
85 * Progress value for the screen before this one in the stack.
86 * This can be `undefined` in case the screen animating is the first one.
87 */
88 previous?: Animated.AnimatedInterpolation;
89};
90export declare type StackHeaderMode = 'float' | 'screen';
91export declare type StackPresentationMode = 'card' | 'modal';
92export declare type StackHeaderOptions = Omit<HeaderOptions, 'headerLeft' | 'headerTitle' | 'headerRight'> & {
93 /**
94 * String or a function that returns a React Element to be used by the header.
95 * Defaults to screen `title` or route name.
96 *
97 * It receives `allowFontScaling`, `tintColor`, `style` and `children` in the options object as an argument.
98 * The title string is passed in `children`.
99 */
100 headerTitle?: string | ((props: HeaderTitleProps) => React.ReactNode);
101 /**
102 * Function which returns a React Element to display on the left side of the header.
103 */
104 headerLeft?: (props: HeaderBackButtonProps) => React.ReactNode;
105 /**
106 * Function which returns a React Element to display on the right side of the header.
107 */
108 headerRight?: (props: HeaderButtonProps) => React.ReactNode;
109 /**
110 * Whether back button title font should scale to respect Text Size accessibility settings. Defaults to `false`.
111 */
112 headerBackAllowFontScaling?: boolean;
113 /**
114 * Accessibility label for the header back button.
115 */
116 headerBackAccessibilityLabel?: string;
117 /**
118 * ID to locate this back button in tests.
119 */
120 headerBackTestID?: string;
121 /**
122 * Title string used by the back button on iOS.
123 * Defaults to the previous screen's title, or "Back" if there's not enough space.
124 * Use `headerBackTitleVisible: false` to hide it.
125 */
126 headerBackTitle?: string;
127 /**
128 * Whether the back button title should be visible or not.
129 *
130 * Defaults to `true` on iOS, `false on Android.
131 */
132 headerBackTitleVisible?: boolean;
133 /**
134 * Style object for the back title.
135 */
136 headerBackTitleStyle?: StyleProp<TextStyle>;
137 /**
138 * Title string used by the back button when `headerBackTitle` doesn't fit on the screen. `"Back"` by default.
139 */
140 headerTruncatedBackTitle?: string;
141 /**
142 * Function which returns a React Element to display custom image in header's back button.
143 * It receives the `tintColor` in in the options object as an argument. object.
144 * Defaults to Image component with a the default back icon image for the platform (a chevron on iOS and an arrow on Android).
145 */
146 headerBackImage?: React.ComponentProps<typeof HeaderBackButton>['backImage'];
147};
148export declare type StackHeaderProps = {
149 /**
150 * Layout of the screen.
151 */
152 layout: Layout;
153 /**
154 * Options for the back button.
155 */
156 back?: {
157 /**
158 * Title of the previous screen.
159 */
160 title: string;
161 };
162 /**
163 * Animated nodes representing the progress of the animation.
164 */
165 progress: SceneProgress;
166 /**
167 * Options for the current screen.
168 */
169 options: StackNavigationOptions;
170 /**
171 * Route object for the current screen.
172 */
173 route: Route<string>;
174 /**
175 * Navigation prop for the header.
176 */
177 navigation: StackNavigationProp<ParamListBase>;
178 /**
179 * Interpolated styles for various elements in the header.
180 */
181 styleInterpolator: StackHeaderStyleInterpolator;
182};
183export declare type StackDescriptor = Descriptor<StackNavigationOptions, StackNavigationProp<ParamListBase>, RouteProp<ParamListBase>>;
184export declare type StackDescriptorMap = Record<string, StackDescriptor>;
185export declare type StackNavigationOptions = StackHeaderOptions & Partial<TransitionPreset> & {
186 /**
187 * String that can be displayed in the header as a fallback for `headerTitle`.
188 */
189 title?: string;
190 /**
191 * Function that given `HeaderProps` returns a React Element to display as a header.
192 */
193 header?: (props: StackHeaderProps) => React.ReactNode;
194 /**
195 * Whether the header floats above the screen or part of the screen.
196 * Defaults to `float` on iOS for non-modals, and `screen` for the rest.
197 */
198 headerMode?: StackHeaderMode;
199 /**
200 * Whether to show the header. The header is shown by default.
201 * Setting this to `false` hides the header.
202 */
203 headerShown?: boolean;
204 /**
205 * Whether a shadow is visible for the card during transitions. Defaults to `true`.
206 */
207 cardShadowEnabled?: boolean;
208 /**
209 * Whether to have a semi-transparent dark overlay visible under the card during transitions.
210 * Defaults to `true` on Android and `false` on iOS.
211 */
212 cardOverlayEnabled?: boolean;
213 /**
214 * Function that returns a React Element to display as a overlay for the card.
215 */
216 cardOverlay?: (props: {
217 style: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
218 }) => React.ReactNode;
219 /**
220 * Style object for the card in stack.
221 * You can provide a custom background color to use instead of the default background here.
222 *
223 * You can also specify `{ backgroundColor: 'transparent' }` to make the previous screen visible underneath.
224 * This is useful to implement things like modal dialogs.
225 *
226 * You should also specify `detachPreviousScreen: false` in options when using a transparent background
227 * so that the previous screen isn't detached and stays below the current screen.
228 *
229 * You might also need to change the animation of the screen using `cardStyleInterpolator`
230 * so that the previous screen isn't transformed or invisible.
231 */
232 cardStyle?: StyleProp<ViewStyle>;
233 /**
234 * Whether this screen should be presented as a modal or a regular card.
235 *
236 * Specifying this will configure several options:
237 * - `card`: Use the default OS animations for iOS and Android screen transitions.
238 * - `modal`: Use Modal animations. This changes a few things:
239 * - Sets `headerMode` to `screen` for the screen unless specified otherwise.
240 * - Changes the screen animation to match the platform behavior for modals.
241 * - `transparentModal`: Similar to `modal`. This changes following things:
242 * - Sets `headerMode` to `screen` for the screen unless specified otherwise.
243 * - Sets background color of the screen to transparent, so previous screen is visible
244 * - Adjusts the `detachPreviousScreen` option so that the previous screen stays rendered.
245 * - Prevents the previous screen from animating from its last position.
246 * - Changes the screen animation to a vertical slide animation.
247 *
248 * Defaults to 'card'.
249 */
250 presentation?: 'card' | 'modal' | 'transparentModal';
251 /**
252 * Whether transition animation should be enabled the screen.
253 * If you set it to `false`, the screen won't animate when pushing or popping.
254 * Defaults to `true` on Android and iOS, `false` on Web.
255 */
256 animationEnabled?: boolean;
257 /**
258 * The type of animation to use when this screen replaces another screen. Defaults to `push`.
259 * When `pop` is used, the `pop` animation is applied to the screen being replaced.
260 */
261 animationTypeForReplace?: 'push' | 'pop';
262 /**
263 * Whether you can use gestures to dismiss this screen. Defaults to `true` on iOS, `false` on Android.
264 * Not supported on Web.
265 */
266 gestureEnabled?: boolean;
267 /**
268 * Distance of touch start from the edge of the screen to recognize gestures.
269 * Not supported on Web.
270 */
271 gestureResponseDistance?: number;
272 /**
273 * Number which determines the relevance of velocity for the gesture. Defaults to 0.3.
274 * Not supported on Web.
275 */
276 gestureVelocityImpact?: number;
277 /**
278 * Whether to detach the previous screen from the view hierarchy to save memory.
279 * Set it to `false` if you need the previous screen to be seen through the active screen.
280 * Only applicable if `detachInactiveScreens` isn't set to `false`.
281 * Defaults to `false` for the last screen for modals, otherwise `true`.
282 */
283 detachPreviousScreen?: boolean;
284 /**
285 * If `false`, the keyboard will NOT automatically dismiss when navigating to a new screen from this screen.
286 * Defaults to `true`.
287 */
288 keyboardHandlingEnabled?: boolean;
289};
290export declare type StackNavigationConfig = {
291 /**
292 * Whether inactive screens should be detached from the view hierarchy to save memory.
293 * This will have no effect if you disable `react-native-screens`.
294 *
295 * Defaults to `true`.
296 */
297 detachInactiveScreens?: boolean;
298};
299export declare type TransitionSpec = {
300 animation: 'spring';
301 config: Omit<Animated.SpringAnimationConfig, 'toValue' | keyof Animated.AnimationConfig>;
302} | {
303 animation: 'timing';
304 config: Omit<Animated.TimingAnimationConfig, 'toValue' | keyof Animated.AnimationConfig>;
305};
306export declare type StackCardInterpolationProps = {
307 /**
308 * Values for the current screen.
309 */
310 current: {
311 /**
312 * Animated node representing the progress value of the current screen.
313 */
314 progress: Animated.AnimatedInterpolation;
315 };
316 /**
317 * Values for the screen after this one in the stack.
318 * This can be `undefined` in case the screen animating is the last one.
319 */
320 next?: {
321 /**
322 * Animated node representing the progress value of the next screen.
323 */
324 progress: Animated.AnimatedInterpolation;
325 };
326 /**
327 * The index of the card with this interpolation in the stack.
328 */
329 index: number;
330 /**
331 * Animated node representing whether the card is closing (1 - closing, 0 - not closing).
332 */
333 closing: Animated.AnimatedInterpolation;
334 /**
335 * Animated node representing whether the card is being swiped (1 - swiping, 0 - not swiping).
336 */
337 swiping: Animated.AnimatedInterpolation;
338 /**
339 * Animated node representing multiplier when direction is inverted (-1 - inverted, 1 - normal).
340 */
341 inverted: Animated.AnimatedInterpolation;
342 /**
343 * Layout measurements for various items we use for animation.
344 */
345 layouts: {
346 /**
347 * Layout of the whole screen.
348 */
349 screen: Layout;
350 };
351 /**
352 * Safe area insets
353 */
354 insets: {
355 top: number;
356 right: number;
357 bottom: number;
358 left: number;
359 };
360};
361export declare type StackCardInterpolatedStyle = {
362 /**
363 * Interpolated style for the container view wrapping the card.
364 */
365 containerStyle?: any;
366 /**
367 * Interpolated style for the view representing the card.
368 */
369 cardStyle?: any;
370 /**
371 * Interpolated style for the view representing the semi-transparent overlay below the card.
372 */
373 overlayStyle?: any;
374 /**
375 * Interpolated style representing the card shadow.
376 */
377 shadowStyle?: any;
378};
379export declare type StackCardStyleInterpolator = (props: StackCardInterpolationProps) => StackCardInterpolatedStyle;
380export declare type StackHeaderInterpolationProps = {
381 /**
382 * Values for the current screen (the screen which owns this header).
383 */
384 current: {
385 /**
386 * Animated node representing the progress value of the current screen.
387 */
388 progress: Animated.AnimatedInterpolation;
389 };
390 /**
391 * Values for the screen after this one in the stack.
392 * This can be `undefined` in case the screen animating is the last one.
393 */
394 next?: {
395 /**
396 * Animated node representing the progress value of the next screen.
397 */
398 progress: Animated.AnimatedInterpolation;
399 };
400 /**
401 * Layout measurements for various items we use for animation.
402 */
403 layouts: {
404 /**
405 * Layout of the header
406 */
407 header: Layout;
408 /**
409 * Layout of the whole screen.
410 */
411 screen: Layout;
412 /**
413 * Layout of the title element.
414 */
415 title?: Layout;
416 /**
417 * Layout of the back button label.
418 */
419 leftLabel?: Layout;
420 };
421};
422export declare type StackHeaderInterpolatedStyle = {
423 /**
424 * Interpolated style for the label of the left button (back button label).
425 */
426 leftLabelStyle?: any;
427 /**
428 * Interpolated style for the left button (usually the back button).
429 */
430 leftButtonStyle?: any;
431 /**
432 * Interpolated style for the right button.
433 */
434 rightButtonStyle?: any;
435 /**
436 * Interpolated style for the header title text.
437 */
438 titleStyle?: any;
439 /**
440 * Interpolated style for the header background.
441 */
442 backgroundStyle?: any;
443};
444export declare type StackHeaderStyleInterpolator = (props: StackHeaderInterpolationProps) => StackHeaderInterpolatedStyle;
445export declare type TransitionPreset = {
446 /**
447 * The direction of swipe gestures, `horizontal` or `vertical`.
448 */
449 gestureDirection: GestureDirection;
450 /**
451 * Object which specifies the animation type (timing or spring) and their options (such as duration for timing).
452 */
453 transitionSpec: {
454 /**
455 * Transition configuration when adding a screen.
456 */
457 open: TransitionSpec;
458 /**
459 * Transition configuration when removing a screen.
460 */
461 close: TransitionSpec;
462 };
463 /**
464 * Function which specifies interpolated styles for various parts of the card, e.g. the overlay, shadow etc.
465 */
466 cardStyleInterpolator: StackCardStyleInterpolator;
467 /**
468 * Function which specifies interpolated styles for various parts of the header, e.g. the title, left button etc.
469 */
470 headerStyleInterpolator: StackHeaderStyleInterpolator;
471};
472export {};