UNPKG

22.1 kBTypeScriptView Raw
1import type * as React from 'react';
2import type { Animated, StyleProp, TextStyle, ViewStyle, LayoutChangeEvent } from 'react-native';
3import type { EdgeInsets } from 'react-native-safe-area-context';
4import type { NavigationRoute, NavigationState, NavigationScreenProp, NavigationProp, NavigationParams, NavigationNavigateAction, NavigationAction, NavigationEventCallback, NavigationEventSubscription, NavigationDescriptor } from 'react-navigation';
5export declare type Route<T extends string> = NavigationRoute;
6export declare type NavigationStackState = NavigationState;
7export declare type NavigationStackEventName = 'willFocus' | 'didFocus' | 'willBlur' | 'didBlur';
8export declare type StackNavigationEventMap = {
9 /**
10 * Event which fires when a transition animation starts.
11 */
12 transitionStart: {
13 data: {
14 closing: boolean;
15 };
16 };
17 /**
18 * Event which fires when a transition animation ends.
19 */
20 transitionEnd: {
21 data: {
22 closing: boolean;
23 };
24 };
25 /**
26 * Event which fires when navigation gesture starts.
27 */
28 gestureStart: {
29 data: undefined;
30 };
31 /**
32 * Event which fires when navigation gesture is completed.
33 */
34 gestureEnd: {
35 data: undefined;
36 };
37 /**
38 * Event which fires when navigation gesture is canceled.
39 */
40 gestureCancel: {
41 data: undefined;
42 };
43};
44export declare type StackNavigationHelpers = NavigationProp<NavigationStackState>;
45export declare type StackNavigationProp<State = NavigationRoute, Params = NavigationParams> = NavigationScreenProp<State, Params> & {
46 push: (routeName: string, params?: NavigationParams, action?: NavigationNavigateAction) => boolean;
47 replace: (routeName: string, params?: NavigationParams, action?: NavigationNavigateAction) => boolean;
48 reset: (actions: NavigationAction[], index: number) => boolean;
49 pop: (n?: number, params?: {
50 immediate?: boolean;
51 }) => boolean;
52 popToTop: (params?: {
53 immediate?: boolean;
54 }) => boolean;
55 addListener: (event: NavigationStackEventName, callback: NavigationEventCallback) => NavigationEventSubscription;
56};
57export declare type Layout = {
58 width: number;
59 height: number;
60};
61export declare type GestureDirection = 'horizontal' | 'horizontal-inverted' | 'vertical' | 'vertical-inverted';
62export declare type Scene<T> = {
63 /**
64 * Current route object,
65 */
66 route: T;
67 /**
68 * Descriptor object for the route containing options and navigation object.
69 */
70 descriptor: StackDescriptor;
71 /**
72 * Animated nodes representing the progress of the animation.
73 */
74 progress: {
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 };
90};
91export declare type StackHeaderMode = 'float' | 'screen' | 'none';
92export declare type StackCardMode = 'card' | 'modal';
93export declare type StackHeaderOptions = {
94 /**
95 * String or a function that returns a React Element to be used by the header.
96 * Defaults to scene `title`.
97 * It receives `allowFontScaling`, `onLayout`, `style` and `children` in the options object as an argument.
98 * The title string is passed in `children`.
99 */
100 headerTitle?: string | ((props: StackHeaderTitleProps) => React.ReactNode);
101 /**
102 * How to align the the header title.
103 * Defaults to `center` on iOS and `left` on Android.
104 */
105 headerTitleAlign?: 'left' | 'center';
106 /**
107 * Style object for the title component.
108 */
109 headerTitleStyle?: Animated.WithAnimatedValue<StyleProp<TextStyle>>;
110 /**
111 * Style object for the container of the `headerTitle` component, for example to add padding.
112 * By default, `headerTitleContainerStyle` is with an absolute position style and offsets both `left` and `right`.
113 * This may lead to white space or overlap between `headerLeft` and `headerTitle` if a customized `headerLeft` is used.
114 * It can be solved by adjusting `left` and `right` style in `headerTitleContainerStyle` and `marginHorizontal` in `headerTitleStyle`.
115 */
116 headerTitleContainerStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
117 /**
118 * Tint color for the header.
119 */
120 headerTintColor?: string;
121 /**
122 * Whether header title font should scale to respect Text Size accessibility settings. Defaults to `false`.
123 */
124 headerTitleAllowFontScaling?: boolean;
125 /**
126 * Whether back button title font should scale to respect Text Size accessibility settings. Defaults to `false`.
127 */
128 headerBackAllowFontScaling?: boolean;
129 /**
130 * Accessibility label for the header back button.
131 */
132 headerBackAccessibilityLabel?: string;
133 /**
134 * Title string used by the back button on iOS. Defaults to the previous scene's `headerTitle`.
135 * Use `headerBackTitleVisible: false` to hide it.
136 */
137 headerBackTitle?: string;
138 /**
139 * Style object for the back title.
140 */
141 headerBackTitleStyle?: StyleProp<TextStyle>;
142 /**
143 * A reasonable default is supplied for whether the back button title should be visible or not.
144 * But if you want to override that you can use `true` or `false` in this option.
145 */
146 headerBackTitleVisible?: boolean;
147 /**
148 * Title string used by the back button when `headerBackTitle` doesn't fit on the screen. `"Back"` by default.
149 */
150 headerTruncatedBackTitle?: string;
151 /**
152 * Function which returns a React Element to display on the left side of the header.
153 * It receives a number of arguments when rendered (`onPress`, `label`, `labelStyle` and more.
154 */
155 headerLeft?: (props: StackHeaderLeftButtonProps) => React.ReactNode;
156 /**
157 * Style object for the container of the `headerLeft` component, for example to add padding.
158 */
159 headerLeftContainerStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
160 /**
161 * Function which returns a React Element to display on the right side of the header.
162 */
163 headerRight?: (props: {
164 tintColor?: string;
165 }) => React.ReactNode;
166 /**
167 * Style object for the container of the `headerRight` component, for example to add padding.
168 */
169 headerRightContainerStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
170 /**
171 * Function which returns a React Element to display custom image in header's back button.
172 * It receives the `tintColor` in in the options object as an argument. object.
173 * Defaults to Image component with a the default back icon image for the platform (a chevron on iOS and an arrow on Android).
174 */
175 headerBackImage?: StackHeaderLeftButtonProps['backImage'];
176 /**
177 * Color for material ripple (Android >= 5.0 only).
178 */
179 headerPressColorAndroid?: string;
180 /**
181 * Function which returns a React Element to render as the background of the header.
182 * This is useful for using backgrounds such as an image or a gradient.
183 * You can use this with `headerTransparent` to render a blur view, for example, to create a translucent header.
184 */
185 headerBackground?: (props: {
186 style: StyleProp<ViewStyle>;
187 }) => React.ReactNode;
188 /**
189 * Style object for the header. You can specify a custom background color here, for example.
190 */
191 headerStyle?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
192 /**
193 * Defaults to `false`. If `true`, the header will not have a background unless you explicitly provide it with `headerBackground`.
194 * The header will also float over the screen so that it overlaps the content underneath.
195 * This is useful if you want to render a semi-transparent header or a blurred background.
196 */
197 headerTransparent?: boolean;
198 /**
199 * Extra padding to add at the top of header to account for translucent status bar.
200 * By default, it uses the top value from the safe area insets of the device.
201 * Pass 0 or a custom value to disable the default behaviour, and customize the height.
202 */
203 headerStatusBarHeight?: number;
204};
205export declare type StackHeaderProps = {
206 /**
207 * Mode of the header: `float` renders a single floating header across all screens,
208 * `screen` renders separate headers for each screen.
209 */
210 mode: 'float' | 'screen';
211 /**
212 * Layout of the screen.
213 */
214 layout: Layout;
215 /**
216 * Safe area insets to use in the header, e.g. to apply extra spacing for statusbar and notch.
217 */
218 insets: EdgeInsets;
219 /**
220 * Object representing the current scene, such as the route object and animation progress.
221 */
222 scene: Scene<Route<string>>;
223 /**
224 * Object representing the previous scene.
225 */
226 previous?: Scene<Route<string>>;
227 /**
228 * Navigation prop for the header.
229 */
230 navigation: StackNavigationProp;
231 /**
232 * Interpolated styles for various elements in the header.
233 */
234 styleInterpolator: StackHeaderStyleInterpolator;
235};
236export declare type StackDescriptor = NavigationDescriptor<NavigationParams, StackNavigationOptions, StackNavigationProp>;
237export declare type StackDescriptorMap = {
238 [key: string]: StackDescriptor;
239};
240export declare type TransitionCallbackProps = {
241 closing: boolean;
242};
243export declare type StackNavigationOptions = StackHeaderOptions & Partial<TransitionPreset> & {
244 /**
245 * String that can be displayed in the header as a fallback for `headerTitle`.
246 */
247 title?: string;
248 /**
249 * Function that given `HeaderProps` returns a React Element to display as a header.
250 */
251 header?: (props: StackHeaderProps) => React.ReactNode;
252 /**
253 * Whether to show the header. The header is shown by default unless `headerMode` was set to `none`.
254 * Setting this to `false` hides the header.
255 */
256 headerShown?: boolean;
257 /**
258 * Whether a shadow is visible for the card during transitions. Defaults to `true`.
259 */
260 cardShadowEnabled?: boolean;
261 /**
262 * Whether to have a semi-transparent dark overlay visible under the card during transitions.
263 * Defaults to `true` on Android and `false` on iOS.
264 */
265 cardOverlayEnabled?: boolean;
266 /**
267 * Function that returns a React Element to display as a overlay for the card.
268 */
269 cardOverlay?: (props: {
270 style: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
271 }) => React.ReactNode;
272 /**
273 * Style object for the card in stack.
274 * You can provide a custom background color to use instead of the default background here.
275 *
276 * You can also specify `{ backgroundColor: 'transparent' }` to make the previous screen visible underneath.
277 * This is useful to implement things like modal dialogs.
278 * If you use [`react-native-screens`](https://github.com/kmagiera/react-native-screens), you should also specify `mode: 'modal'`
279 * in the stack view config when using a transparent background so previous screens aren't detached.
280 */
281 cardStyle?: StyleProp<ViewStyle>;
282 /**
283 * Whether transition animation should be enabled the screen.
284 * If you set it to `false`, the screen won't animate when pushing or popping.
285 * Defaults to `true` on Android and iOS, `false` on Web.
286 */
287 animationEnabled?: boolean;
288 /**
289 * The type of animation to use when this screen replaces another screen. Defaults to `push`.
290 * When `pop` is used, the `pop` animation is applied to the screen being replaced.
291 */
292 animationTypeForReplace?: 'push' | 'pop';
293 /**
294 * Whether you can use gestures to dismiss this screen. Defaults to `true` on iOS, `false` on Android.
295 * Not supported on Web.
296 */
297 gestureEnabled?: boolean;
298 /**
299 * Object to override the distance of touch start from the edge of the screen to recognize gestures.
300 * Not supported on Web.
301 */
302 gestureResponseDistance?: {
303 /**
304 * Distance for vertical direction. Defaults to 135.
305 */
306 vertical?: number;
307 /**
308 * Distance for horizontal direction. Defaults to 25.
309 */
310 horizontal?: number;
311 };
312 /**
313 * Number which determines the relevance of velocity for the gesture. Defaults to 0.3.
314 * Not supported on Web.
315 */
316 gestureVelocityImpact?: number;
317 /**
318 * Safe area insets for the screen. This is used to avoid elements like notch and status bar.
319 * By default, the device's safe area insets are automatically detected. You can override the behavior with this option.
320 * For example, to remove the extra spacing for status bar, pass `safeAreaInsets: { top: 0 }`.
321 */
322 safeAreaInsets?: {
323 top?: number;
324 right?: number;
325 bottom?: number;
326 left?: number;
327 };
328 /**
329 * Whether to detach the previous screen from the view hierarchy to save memory.
330 * Set it to `false` if you need the previous screen to be seen through the active screen.
331 * Only applicable if `detachInactiveScreens` isn't set to `false`.
332 * Defaults to `false` for the last screen when mode='modal', otherwise `true`.
333 */
334 detachPreviousScreen?: boolean;
335 onTransitionStart?: (props: TransitionCallbackProps) => void;
336 onTransitionEnd?: (props: TransitionCallbackProps) => void;
337};
338export declare type StackNavigationConfig = {
339 mode?: StackCardMode;
340 headerMode?: StackHeaderMode;
341 /**
342 * If `false`, the keyboard will NOT automatically dismiss when navigating to a new screen.
343 * Defaults to `true`.
344 */
345 keyboardHandlingEnabled?: boolean;
346 /**
347 * Whether inactive screens should be detached from the view hierarchy to save memory.
348 * Make sure to call `enableScreens` from `react-native-screens` to make it work.
349 * Defaults to `true` on Android, depends on the version of `react-native-screens` on iOS.
350 */
351 detachInactiveScreens?: boolean;
352};
353export declare type StackHeaderLeftButtonProps = {
354 /**
355 * Whether the button is disabled.
356 */
357 disabled?: boolean;
358 /**
359 * Callback to call when the button is pressed.
360 * By default, this triggers `goBack`.
361 */
362 onPress?: () => void;
363 /**
364 * Color for material ripple (Android >= 5.0 only).
365 */
366 pressColorAndroid?: string;
367 /**
368 * Function which returns a React Element to display custom image in header's back button.
369 */
370 backImage?: (props: {
371 tintColor: string;
372 }) => React.ReactNode;
373 /**
374 * Tint color for the header.
375 */
376 tintColor?: string;
377 /**
378 * Label text for the button. Usually the title of the previous screen.
379 * By default, this is only shown on iOS.
380 */
381 label?: string;
382 /**
383 * Label text to show when there isn't enough space for the full label.
384 */
385 truncatedLabel?: string;
386 /**
387 * Whether the label text is visible.
388 * Defaults to `true` on iOS and `false` on Android.
389 */
390 labelVisible?: boolean;
391 /**
392 * Style object for the label.
393 */
394 labelStyle?: Animated.WithAnimatedValue<StyleProp<TextStyle>>;
395 /**
396 * Whether label font should scale to respect Text Size accessibility settings.
397 */
398 allowFontScaling?: boolean;
399 /**
400 * Callback to trigger when the size of the label changes.
401 */
402 onLabelLayout?: (e: LayoutChangeEvent) => void;
403 /**
404 * Layout of the screen.
405 */
406 screenLayout?: Layout;
407 /**
408 * Layout of the title element in the header.
409 */
410 titleLayout?: Layout;
411 /**
412 * Whether it's possible to navigate back in stack.
413 */
414 canGoBack?: boolean;
415 /**
416 * Accessibility label for the button for screen readers.
417 */
418 accessibilityLabel?: string;
419 /**
420 * Style object for the button.
421 */
422 style?: StyleProp<ViewStyle>;
423};
424export declare type StackHeaderTitleProps = {
425 /**
426 * Callback to trigger when the size of the title element changes.
427 */
428 onLayout: (e: LayoutChangeEvent) => void;
429 /**
430 * Whether title font should scale to respect Text Size accessibility settings.
431 */
432 allowFontScaling?: boolean;
433 /**
434 * Tint color for the header.
435 */
436 tintColor?: string;
437 /**
438 * Content of the title element. Usually the title string.
439 */
440 children?: string;
441 /**
442 * Style object for the title element.
443 */
444 style?: Animated.WithAnimatedValue<StyleProp<TextStyle>>;
445};
446export declare type TransitionSpec = {
447 animation: 'spring';
448 config: Omit<Animated.SpringAnimationConfig, 'toValue' | keyof Animated.AnimationConfig>;
449} | {
450 animation: 'timing';
451 config: Omit<Animated.TimingAnimationConfig, 'toValue' | keyof Animated.AnimationConfig>;
452};
453export declare type StackCardInterpolationProps = {
454 /**
455 * Values for the current screen.
456 */
457 current: {
458 /**
459 * Animated node representing the progress value of the current screen.
460 */
461 progress: Animated.AnimatedInterpolation;
462 };
463 /**
464 * Values for the current screen the screen after this one in the stack.
465 * This can be `undefined` in case the screen animating is the last one.
466 */
467 next?: {
468 /**
469 * Animated node representing the progress value of the next screen.
470 */
471 progress: Animated.AnimatedInterpolation;
472 };
473 /**
474 * The index of the card in the stack.
475 */
476 index: number;
477 /**
478 * Animated node representing whether the card is closing (1 - closing, 0 - not closing).
479 */
480 closing: Animated.AnimatedInterpolation;
481 /**
482 * Animated node representing whether the card is being swiped (1 - swiping, 0 - not swiping).
483 */
484 swiping: Animated.AnimatedInterpolation;
485 /**
486 * Animated node representing multiplier when direction is inverted (-1 - inverted, 1 - normal).
487 */
488 inverted: Animated.AnimatedInterpolation;
489 /**
490 * Layout measurements for various items we use for animation.
491 */
492 layouts: {
493 /**
494 * Layout of the whole screen.
495 */
496 screen: Layout;
497 };
498 /**
499 * Safe area insets
500 */
501 insets: {
502 top: number;
503 right: number;
504 bottom: number;
505 left: number;
506 };
507};
508export declare type StackCardInterpolatedStyle = {
509 /**
510 * Interpolated style for the container view wrapping the card.
511 */
512 containerStyle?: any;
513 /**
514 * Interpolated style for the view representing the card.
515 */
516 cardStyle?: any;
517 /**
518 * Interpolated style for the view representing the semi-transparent overlay below the card.
519 */
520 overlayStyle?: any;
521 /**
522 * Interpolated style representing the card shadow.
523 */
524 shadowStyle?: any;
525};
526export declare type StackCardStyleInterpolator = (props: StackCardInterpolationProps) => StackCardInterpolatedStyle;
527export declare type StackHeaderInterpolationProps = {
528 /**
529 * Values for the current screen (the screen which owns this header).
530 */
531 current: {
532 /**
533 * Animated node representing the progress value of the current screen.
534 */
535 progress: Animated.AnimatedInterpolation;
536 };
537 /**
538 * Values for the current screen the screen after this one in the stack.
539 * This can be `undefined` in case the screen animating is the last one.
540 */
541 next?: {
542 /**
543 * Animated node representing the progress value of the next screen.
544 */
545 progress: Animated.AnimatedInterpolation;
546 };
547 /**
548 * Layout measurements for various items we use for animation.
549 */
550 layouts: {
551 /**
552 * Layout of the header
553 */
554 header: Layout;
555 /**
556 * Layout of the whole screen.
557 */
558 screen: Layout;
559 /**
560 * Layout of the title element.
561 */
562 title?: Layout;
563 /**
564 * Layout of the back button label.
565 */
566 leftLabel?: Layout;
567 };
568};
569export declare type StackHeaderInterpolatedStyle = {
570 /**
571 * Interpolated style for the label of the left button (back button label).
572 */
573 leftLabelStyle?: any;
574 /**
575 * Interpolated style for the left button (usually the back button).
576 */
577 leftButtonStyle?: any;
578 /**
579 * Interpolated style for the right button.
580 */
581 rightButtonStyle?: any;
582 /**
583 * Interpolated style for the header title text.
584 */
585 titleStyle?: any;
586 /**
587 * Interpolated style for the header background.
588 */
589 backgroundStyle?: any;
590};
591export declare type StackHeaderStyleInterpolator = (props: StackHeaderInterpolationProps) => StackHeaderInterpolatedStyle;
592export declare type TransitionPreset = {
593 /**
594 * The direction of swipe gestures, `horizontal` or `vertical`.
595 */
596 gestureDirection: GestureDirection;
597 /**
598 * Object which specifies the animation type (timing or spring) and their options (such as duration for timing).
599 */
600 transitionSpec: {
601 /**
602 * Transition configuration when adding a screen.
603 */
604 open: TransitionSpec;
605 /**
606 * Transition configuration when removing a screen.
607 */
608 close: TransitionSpec;
609 };
610 /**
611 * Function which specifies interpolated styles for various parts of the card, e.g. the overlay, shadow etc.
612 */
613 cardStyleInterpolator: StackCardStyleInterpolator;
614 /**
615 * Function which specifies interpolated styles for various parts of the header, e.g. the title, left button etc.
616 */
617 headerStyleInterpolator: StackHeaderStyleInterpolator;
618};
619
\No newline at end of file