forked from react-navigation/react-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeDefinition.js
494 lines (416 loc) · 12.6 KB
/
TypeDefinition.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
/* @flow */
import React from 'react';
import type { TabScene } from './views/TabView/TabView';
import {
Animated,
type ViewProps,
type TextProps,
type StyleDefinition,
type AnimatedViewStylePropTypes,
} from 'react-native';
export type ViewStyleProp = $PropertyType<ViewProps, 'style'>;
export type TextStyleProp = $PropertyType<TextProps, 'style'>;
export type AnimatedViewStyleProp = $PropertyType<
$PropertyType<Animated.View, 'props'>,
'style'
>;
export type AnimatedTextStyleProp = $PropertyType<
$PropertyType<Animated.Text, 'props'>,
'style'
>;
/**
* Navigation State + Action
*/
export type NavigationParams = {
[key: string]: mixed,
};
export type NavigationNavigateAction = {
type: 'Navigation/NAVIGATE',
routeName: string,
params?: NavigationParams,
// The action to run inside the sub-router
action?: NavigationNavigateAction,
};
export type NavigationBackAction = {
type: 'Navigation/BACK',
key?: ?string,
};
export type NavigationSetParamsAction = {
type: 'Navigation/SET_PARAMS',
// The key of the route where the params should be set
key: string,
// The new params to merge into the existing route params
params?: NavigationParams,
};
export type NavigationInitAction = {
type: 'Navigation/INIT',
params?: NavigationParams,
};
export type NavigationResetAction = {
type: 'Navigation/RESET',
index: number,
key?: ?string,
actions: Array<NavigationNavigateAction>,
};
export type NavigationUriAction = {
type: 'Navigation/URI',
uri: string,
};
export type NavigationStackAction =
| NavigationInitAction
| NavigationNavigateAction
| NavigationBackAction
| NavigationSetParamsAction
| NavigationResetAction;
export type NavigationTabAction =
| NavigationInitAction
| NavigationNavigateAction
| NavigationBackAction;
export type NavigationAction =
| NavigationInitAction
| NavigationStackAction
| NavigationTabAction;
/**
* NavigationState is a tree of routes for a single navigator, where each child
* route may either be a NavigationScreenRoute or a NavigationRouterRoute.
* NavigationScreenRoute represents a leaf screen, while the
* NavigationRouterRoute represents the state of a child navigator.
*
* NOTE: NavigationState is a state tree local to a single navigator and
* its child navigators (via the routes field).
* If we're in navigator nested deep inside the app, the state will only be the
* state for that navigator.
* The state for the root navigator of our app represents the whole navigation
* state for the whole app.
*/
export type NavigationState = {
/**
* Index refers to the active child route in the routes array.
*/
index: number,
routes: Array<NavigationRoute>,
};
export type NavigationRoute = NavigationLeafRoute | NavigationStateRoute;
export type NavigationLeafRoute = {
/**
* React's key used by some navigators. No need to specify these manually,
* they will be defined by the router.
*/
key: string,
/**
* For example 'Home'.
* This is used as a key in a route config when creating a navigator.
*/
routeName: string,
/**
* Path is an advanced feature used for deep linking and on the web.
*/
path?: string,
/**
* Params passed to this route when navigating to it,
* e.g. `{ car_id: 123 }` in a route that displays a car.
*/
params?: NavigationParams,
};
export type NavigationStateRoute = {
...$Exact<NavigationLeafRoute>,
index: number,
routes: Array<NavigationRoute>,
};
/**
* Router
*/
export type NavigationScreenOptionsGetter<Options, Action> = (
navigation: NavigationScreenProp<NavigationRoute, Action>,
screenProps?: {}
) => Options;
export type NavigationRouter<State, Action, Options> = {
/**
* The reducer that outputs the new navigation state for a given action, with
* an optional previous state. When the action is considered handled but the
* state is unchanged, the output state is null.
*/
getStateForAction: (action: Action, lastState: ?State) => ?State,
/**
* Maps a URI-like string to an action. This can be mapped to a state
* using `getStateForAction`.
*/
getActionForPathAndParams: (
path: string,
params?: NavigationParams
) => ?Action,
getPathAndParamsForState: (
state: State
) => {
path: string,
params?: NavigationParams,
},
getComponentForRouteName: (routeName: string) => NavigationComponent,
getComponentForState: (state: State) => NavigationComponent,
/**
* Gets the screen navigation options for a given screen.
*
* For example, we could get the config for the 'Foo' screen when the
* `navigation.state` is:
*
* {routeName: 'Foo', key: '123'}
*/
getScreenOptions: NavigationScreenOptionsGetter<Options, Action>,
};
export type NavigationScreenDetails<T> = {
options: T,
state: NavigationRoute,
navigation: NavigationScreenProp<NavigationRoute, NavigationAction>,
};
export type NavigationScreenOptions = {
title?: string,
};
export type NavigationScreenConfigProps = {
navigation: NavigationScreenProp<NavigationRoute, NavigationAction>,
screenProps: {},
};
export type NavigationScreenConfig<Options> =
| Options
| (({
...$Exact<NavigationScreenConfigProps>,
navigationOptions: NavigationScreenProp<
NavigationRoute,
NavigationAction
>,
}) => Options);
export type NavigationComponent =
| NavigationScreenComponent<*, *>
| NavigationNavigator<*, *, *, *>;
export type NavigationScreenComponent<T, Options> = ReactClass<T> & {
navigationOptions?: NavigationScreenConfig<Options>,
};
export type NavigationNavigator<T, State, Action, Options> = ReactClass<T> & {
router?: NavigationRouter<State, Action, Options>,
navigationOptions?: NavigationScreenConfig<Options>,
};
export type NavigationRouteConfig<T: {}> = {
...$Exact<T>,
navigationOptions?: NavigationScreenConfig<*>,
path?: string,
};
export type NavigationScreenRouteConfig =
| {
screen: NavigationComponent,
}
| {
getScreen: () => NavigationComponent,
};
export type NavigationPathsConfig = {
[routeName: string]: string,
};
export type NavigationRouteConfigMap = {
[routeName: string]: NavigationRouteConfig<*>,
};
/**
* Header
*/
export type HeaderMode = 'float' | 'screen' | 'none';
export type HeaderProps = {
...$Exact<NavigationSceneRendererProps>,
mode: HeaderMode,
router: NavigationRouter<
NavigationState,
NavigationAction,
NavigationStackScreenOptions
>,
getScreenDetails: NavigationScene => NavigationScreenDetails<
NavigationStackScreenOptions
>,
style: ViewStyleProp,
};
/**
* Stack Navigator
*/
export type NavigationStackScreenOptions = {
...$Exact<NavigationScreenOptions>,
header?: ?(React.Element<*> | (HeaderProps => React.Element<*>)),
headerTitle?: string | React.Element<*>,
headerTitleStyle?: AnimatedTextStyleProp,
headerTintColor?: string,
headerLeft?: React.Element<*>,
headerBackTitle?: string,
headerTruncatedBackTitle?: string,
headerBackTitleStyle?: TextStyleProp,
headerPressColorAndroid?: string,
headerRight?: React.Element<*>,
headerStyle?: ViewStyleProp,
gesturesEnabled?: boolean,
};
export type NavigationStackRouterConfig = {
initialRouteName?: string,
initialRouteParams?: NavigationParams,
paths?: NavigationPathsConfig,
navigationOptions?: NavigationScreenConfig<NavigationStackScreenOptions>,
};
export type NavigationStackViewConfig = {
mode?: 'card' | 'modal',
headerMode?: HeaderMode,
cardStyle?: ViewStyleProp,
transitionConfig?: () => TransitionConfig,
onTransitionStart?: () => void,
onTransitionEnd?: () => void,
};
export type StackNavigatorConfig = {
...$Exact<NavigationStackViewConfig>,
...$Exact<NavigationStackRouterConfig>,
};
/**
* Tab Navigator
*/
export type NavigationTabRouterConfig = {
initialRouteName?: string,
paths?: NavigationPathsConfig,
navigationOptions?: NavigationScreenConfig<NavigationTabScreenOptions>,
order?: Array<string>, // todo: type these as the real route names rather than 'string'
// Does the back button cause the router to switch to the initial tab
backBehavior?: 'none' | 'initialRoute', // defaults `initialRoute`
};
export type NavigationTabScreenOptions = {
...$Exact<NavigationScreenOptions>,
tabBarIcon?:
| React.Element<*>
| ((options: { tintColor: ?string, focused: boolean }) => ?React.Element<
*
>),
tabBarLabel?:
| string
| React.Element<*>
| ((options: { tintColor: ?string, focused: boolean }) => ?React.Element<
*
>),
tabBarVisible?: boolean,
tabBarOnPress?: (
scene: TabScene,
jumpToIndex: (index: number) => void
) => void,
};
/**
* Drawer
*/
export type NavigationDrawerScreenOptions = {
...$Exact<NavigationScreenOptions>,
drawerIcon?:
| React.Element<*>
| ((options: { tintColor: ?string, focused: boolean }) => ?React.Element<
*
>),
drawerLabel?:
| React.Element<*>
| ((options: { tintColor: ?string, focused: boolean }) => ?React.Element<
*
>),
};
/**
* Navigator Prop
*/
export type NavigationDispatch<A> = (action: A) => boolean;
export type NavigationProp<S, A> = {
state: S,
dispatch: NavigationDispatch<A>,
};
export type NavigationScreenProp<S, A> = {
state: S,
dispatch: NavigationDispatch<A>,
goBack: (routeKey?: ?string) => boolean,
navigate: (
routeName: string,
params?: NavigationParams,
action?: NavigationAction
) => boolean,
setParams: (newParams: NavigationParams) => boolean,
};
export type NavigationNavigatorProps<O, S> = {
navigation: NavigationProp<S, NavigationAction>,
screenProps: *,
navigationOptions: O,
};
/**
* Gestures, Animations, and Interpolators
*/
export type NavigationGestureDirection = 'horizontal' | 'vertical';
export type NavigationLayout = {
height: Animated.Value,
initHeight: number,
initWidth: number,
isMeasured: boolean,
width: Animated.Value,
};
export type NavigationScene = {
index: number,
isActive: boolean,
isStale: boolean,
key: string,
route: NavigationRoute,
};
export type NavigationTransitionProps = {
// The layout of the screen container
layout: NavigationLayout,
// The destination navigation state of the transition
navigation: NavigationScreenProp<NavigationState, NavigationAction>,
// The progressive index of the transitioner's navigation state.
position: Animated.Value,
// The value that represents the progress of the transition when navigation
// state changes from one to another. Its numberic value will range from 0
// to 1.
// progress.__getAnimatedValue() < 1 : transtion is happening.
// progress.__getAnimatedValue() == 1 : transtion completes.
progress: Animated.Value,
// All the scenes of the transitioner.
scenes: Array<NavigationScene>,
// The active scene, corresponding to the route at
// `navigation.state.routes[navigation.state.index]`. When rendering
// NavigationSceneRendererPropsIndex, the scene does not refer to the active
// scene, but instead the scene that is being rendered. The index always
// is the index of the scene
scene: NavigationScene,
index: number,
screenProps?: {},
};
// The scene renderer props are nearly identical to the props used for rendering
// a transition. The exception is that the passed scene is not the active scene
// but is instead the scene that the renderer should render content for.
export type NavigationSceneRendererProps = NavigationTransitionProps;
export type NavigationTransitionSpec = {
duration?: number,
// An easing function from `Easing`.
easing?: (t?: number) => number,
// A timing function such as `Animated.timing`.
timing?: (value: Animated.Value, config: any) => any,
};
/**
* Describes a visual transition from one screen to another.
*/
export type TransitionConfig = {
// The basics properties of the animation, such as duration and easing
transitionSpec?: NavigationTransitionSpec,
// How to animate position and opacity of the screen
// based on the value generated by the transitionSpec
screenInterpolator?: (props: NavigationSceneRendererProps) => {},
// The style of the container. Useful when a scene doesn't have
// 100% opacity and the underlying container is visible.
containerStyle?: $PropertyType<ViewProps, 'style'>,
};
export type NavigationAnimationSetter = (
position: Animated.Value,
newState: NavigationState,
lastState: NavigationState
) => void;
export type NavigationSceneRenderer = () => ?React.Element<*>;
export type NavigationStyleInterpolator = (
props: NavigationSceneRendererProps
) => AnimatedViewStylePropTypes;
export type LayoutEvent = {
nativeEvent: {
layout: {
x: number,
y: number,
width: number,
height: number,
},
},
};