Skip to content

Commit eb8434a

Browse files
author
Adam Miskiewicz
committed
Clean up some flow types code-base wide, reorganize cardstack views
1 parent bbd82df commit eb8434a

19 files changed

+222
-195
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
2,
5555
"boolean"
5656
],
57-
"flowtype/no-weak-types": 1,
57+
"flowtype/no-weak-types": 0,
5858
"flowtype/require-parameter-type": 2,
5959
"flowtype/require-return-type": [
6060
0,

src/TypeDefinition.js

Lines changed: 138 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,72 @@ export type AnimatedTextStyleProp = $PropertyType<
2121
'style'
2222
>;
2323

24-
export type HeaderMode = 'float' | 'screen' | 'none';
24+
/**
25+
* Navigation State + Action
26+
*/
2527

26-
export type HeaderProps = {
27-
...$Exact<NavigationSceneRendererProps>,
28-
mode: HeaderMode,
29-
router: NavigationRouter<
30-
NavigationState,
31-
NavigationAction,
32-
NavigationStackScreenOptions
33-
>,
34-
getScreenDetails: NavigationScene => NavigationScreenDetails<
35-
NavigationStackScreenOptions
36-
>,
37-
style: ViewStyleProp,
28+
export type NavigationParams = {
29+
[key: string]: mixed,
30+
};
31+
32+
export type NavigationNavigateAction = {
33+
type: 'Navigation/NAVIGATE',
34+
routeName: string,
35+
params?: NavigationParams,
36+
37+
// The action to run inside the sub-router
38+
action?: NavigationNavigateAction,
39+
};
40+
41+
export type NavigationBackAction = {
42+
type: 'Navigation/BACK',
43+
key?: ?string,
44+
};
45+
46+
export type NavigationSetParamsAction = {
47+
type: 'Navigation/SET_PARAMS',
48+
49+
// The key of the route where the params should be set
50+
key: string,
51+
52+
// The new params to merge into the existing route params
53+
params?: NavigationParams,
54+
};
55+
56+
export type NavigationInitAction = {
57+
type: 'Navigation/INIT',
58+
params?: NavigationParams,
59+
};
60+
61+
export type NavigationResetAction = {
62+
type: 'Navigation/RESET',
63+
index: number,
64+
key?: ?string,
65+
actions: Array<NavigationNavigateAction>,
3866
};
3967

68+
export type NavigationUriAction = {
69+
type: 'Navigation/URI',
70+
uri: string,
71+
};
72+
73+
export type NavigationStackAction =
74+
| NavigationInitAction
75+
| NavigationNavigateAction
76+
| NavigationBackAction
77+
| NavigationSetParamsAction
78+
| NavigationResetAction;
79+
80+
export type NavigationTabAction =
81+
| NavigationInitAction
82+
| NavigationNavigateAction
83+
| NavigationBackAction;
84+
85+
export type NavigationAction =
86+
| NavigationInitAction
87+
| NavigationStackAction
88+
| NavigationTabAction;
89+
4090
/**
4191
* NavigationState is a tree of routes for a single navigator, where each child
4292
* route may either be a NavigationScreenRoute or a NavigationRouterRoute.
@@ -88,6 +138,10 @@ export type NavigationStateRoute = {
88138
routes: Array<NavigationRoute>,
89139
};
90140

141+
/**
142+
* Router
143+
*/
144+
91145
export type NavigationScreenOptionsGetter<Options, Action> = (
92146
navigation: NavigationScreenProp<NavigationRoute, Action>,
93147
screenProps?: {}
@@ -132,13 +186,6 @@ export type NavigationRouter<State, Action, Options> = {
132186
getScreenOptions: NavigationScreenOptionsGetter<Options, Action>,
133187
};
134188

135-
export type NavigationScreenOption<T> =
136-
| T
137-
| ((
138-
navigation: NavigationScreenProp<NavigationRoute, NavigationAction>,
139-
config: T
140-
) => T);
141-
142189
export type NavigationScreenDetails<T> = {
143190
options: T,
144191
state: NavigationRoute,
@@ -151,18 +198,18 @@ export type NavigationScreenOptions = {
151198

152199
export type NavigationScreenConfigProps = {
153200
navigation: NavigationScreenProp<NavigationRoute, NavigationAction>,
154-
screenProps: Object,
201+
screenProps: {},
155202
};
156203

157204
export type NavigationScreenConfig<Options> =
158205
| Options
159-
| (NavigationScreenConfigProps &
160-
(({
161-
navigationOptions: NavigationScreenProp<
162-
NavigationRoute,
163-
NavigationAction
164-
>,
165-
}) => Options));
206+
| (({
207+
...$Exact<NavigationScreenConfigProps>,
208+
navigationOptions: NavigationScreenProp<
209+
NavigationRoute,
210+
NavigationAction
211+
>,
212+
}) => Options);
166213

167214
export type NavigationComponent =
168215
| NavigationScreenComponent<*, *>
@@ -177,59 +224,51 @@ export type NavigationNavigator<T, State, Action, Options> = ReactClass<T> & {
177224
navigationOptions?: NavigationScreenConfig<Options>,
178225
};
179226

180-
export type NavigationParams = {
181-
[key: string]: mixed,
227+
export type NavigationRouteConfig<T: {}> = {
228+
...$Exact<T>,
229+
navigationOptions?: NavigationScreenConfig<*>,
230+
path?: string,
182231
};
183232

184-
export type NavigationNavigateAction = {
185-
type: 'Navigation/NAVIGATE',
186-
routeName: string,
187-
params?: NavigationParams,
188-
189-
// The action to run inside the sub-router
190-
action?: NavigationNavigateAction,
191-
};
233+
export type NavigationScreenRouteConfig =
234+
| {
235+
screen: NavigationComponent,
236+
}
237+
| {
238+
getScreen: () => NavigationComponent,
239+
};
192240

193-
export type NavigationBackAction = {
194-
type: 'Navigation/BACK',
195-
key?: ?string,
241+
export type NavigationPathsConfig = {
242+
[routeName: string]: string,
196243
};
197244

198-
export type NavigationSetParamsAction = {
199-
type: 'Navigation/SET_PARAMS',
200-
201-
// The key of the route where the params should be set
202-
key: string,
203-
204-
// The new params to merge into the existing route params
205-
params?: NavigationParams,
245+
export type NavigationRouteConfigMap = {
246+
[routeName: string]: NavigationRouteConfig<*>,
206247
};
207248

208-
export type NavigationInitAction = {
209-
type: 'Navigation/INIT',
210-
params?: NavigationParams,
211-
};
249+
/**
250+
* Header
251+
*/
212252

213-
export type NavigationResetAction = {
214-
type: 'Navigation/RESET',
215-
index: number,
216-
key?: ?string,
217-
actions: Array<NavigationNavigateAction>,
218-
};
253+
export type HeaderMode = 'float' | 'screen' | 'none';
219254

220-
export type NavigationUriAction = {
221-
type: 'Navigation/URI',
222-
uri: string,
255+
export type HeaderProps = {
256+
...$Exact<NavigationSceneRendererProps>,
257+
mode: HeaderMode,
258+
router: NavigationRouter<
259+
NavigationState,
260+
NavigationAction,
261+
NavigationStackScreenOptions
262+
>,
263+
getScreenDetails: NavigationScene => NavigationScreenDetails<
264+
NavigationStackScreenOptions
265+
>,
266+
style: ViewStyleProp,
223267
};
224268

225-
export type NavigationStackViewConfig = {
226-
mode?: 'card' | 'modal',
227-
headerMode?: HeaderMode,
228-
cardStyle?: ViewStyleProp,
229-
transitionConfig?: () => TransitionConfig,
230-
onTransitionStart?: () => void,
231-
onTransitionEnd?: () => void,
232-
};
269+
/**
270+
* Stack Navigator
271+
*/
233272

234273
export type NavigationStackScreenOptions = {
235274
...$Exact<NavigationScreenOptions>,
@@ -254,40 +293,24 @@ export type NavigationStackRouterConfig = {
254293
navigationOptions?: NavigationScreenConfig<NavigationStackScreenOptions>,
255294
};
256295

257-
export type NavigationStackAction =
258-
| NavigationInitAction
259-
| NavigationNavigateAction
260-
| NavigationBackAction
261-
| NavigationSetParamsAction
262-
| NavigationResetAction;
263-
264-
export type NavigationTabAction =
265-
| NavigationInitAction
266-
| NavigationNavigateAction
267-
| NavigationBackAction;
268-
269-
export type NavigationAction =
270-
| NavigationInitAction
271-
| NavigationStackAction
272-
| NavigationTabAction;
273-
274-
export type NavigationRouteConfig<T> = T & {
275-
navigationOptions?: NavigationScreenConfig<*>,
276-
path?: string,
296+
export type NavigationStackViewConfig = {
297+
mode?: 'card' | 'modal',
298+
headerMode?: HeaderMode,
299+
cardStyle?: ViewStyleProp,
300+
transitionConfig?: () => TransitionConfig,
301+
onTransitionStart?: () => void,
302+
onTransitionEnd?: () => void,
277303
};
278304

279-
export type NavigationScreenRouteConfig =
280-
| {
281-
screen: NavigationComponent,
282-
}
283-
| {
284-
getScreen: () => NavigationComponent,
285-
};
286-
287-
export type NavigationPathsConfig = {
288-
[routeName: string]: string,
305+
export type StackNavigatorConfig = {
306+
...$Exact<NavigationStackViewConfig>,
307+
...$Exact<NavigationStackRouterConfig>,
289308
};
290309

310+
/**
311+
* Tab Navigator
312+
*/
313+
291314
export type NavigationTabRouterConfig = {
292315
initialRouteName?: string,
293316
paths?: NavigationPathsConfig,
@@ -298,7 +321,8 @@ export type NavigationTabRouterConfig = {
298321
backBehavior?: 'none' | 'initialRoute', // defaults `initialRoute`
299322
};
300323

301-
export type NavigationTabScreenOptions = NavigationScreenOptions & {
324+
export type NavigationTabScreenOptions = {
325+
...$Exact<NavigationScreenOptions>,
302326
tabBarIcon?:
303327
| React.Element<*>
304328
| ((options: { tintColor: ?string, focused: boolean }) => ?React.Element<
@@ -313,7 +337,12 @@ export type NavigationTabScreenOptions = NavigationScreenOptions & {
313337
tabBarVisible?: boolean,
314338
};
315339

316-
export type NavigationDrawerScreenOptions = NavigationScreenOptions & {
340+
/**
341+
* Drawer
342+
*/
343+
344+
export type NavigationDrawerScreenOptions = {
345+
...$Exact<NavigationScreenOptions>,
317346
drawerIcon?:
318347
| React.Element<*>
319348
| ((options: { tintColor: ?string, focused: boolean }) => ?React.Element<
@@ -326,9 +355,9 @@ export type NavigationDrawerScreenOptions = NavigationScreenOptions & {
326355
>),
327356
};
328357

329-
export type NavigationRouteConfigMap = {
330-
[routeName: string]: NavigationRouteConfig<*>,
331-
};
358+
/**
359+
* Navigator Prop
360+
*/
332361

333362
export type NavigationDispatch<A> = (action: A) => boolean;
334363

@@ -349,10 +378,10 @@ export type NavigationScreenProp<S, A> = {
349378
setParams: (newParams: NavigationParams) => boolean,
350379
};
351380

352-
export type NavigationNavigatorProps<T> = {
353-
navigation: NavigationProp<T, NavigationAction>,
381+
export type NavigationNavigatorProps<O, S> = {
382+
navigation: NavigationProp<S, NavigationAction>,
354383
screenProps: *,
355-
navigationOptions: *,
384+
navigationOptions: O,
356385
};
357386

358387
/**
@@ -429,7 +458,7 @@ export type TransitionConfig = {
429458
transitionSpec?: NavigationTransitionSpec,
430459
// How to animate position and opacity of the screen
431460
// based on the value generated by the transitionSpec
432-
screenInterpolator?: (props: NavigationSceneRendererProps) => Object,
461+
screenInterpolator?: (props: NavigationSceneRendererProps) => {},
433462
// The style of the container. Useful when a scene doesn't have
434463
// 100% opacity and the underlying container is visible.
435464
containerStyle?: $PropertyType<ViewProps, 'style'>,

0 commit comments

Comments
 (0)