Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 805ebb7

Browse files
committed
Import from react-navigation instead of @react-navigation/core
Our users are more likely to already have the `react-navigation` libdef installed
1 parent bdb4876 commit 805ebb7

6 files changed

Lines changed: 71 additions & 40 deletions

File tree

flow-typed/npm/@react-navigation/core_v3.x.x.js renamed to flow-typed/npm/react-navigation_v4.x.x.js

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
declare module '@react-navigation/core' {
3+
declare module 'react-navigation' {
44

55
//---------------------------------------------------------------------------
66
// SECTION 1: IDENTICAL TYPE DEFINITIONS
@@ -212,9 +212,11 @@ declare module '@react-navigation/core' {
212212
* Router
213213
*/
214214

215+
declare export type NavigationScreenProps = { [key: string]: mixed, ... };
216+
215217
declare export type NavigationScreenOptionsGetter<Options: {...}> = (
216218
navigation: NavigationScreenProp<NavigationRoute>,
217-
screenProps: ?{...},
219+
ncreenProps: ?NavigationScreenProps,
218220
theme: SupportedThemes,
219221
) => Options;
220222

@@ -260,7 +262,7 @@ declare module '@react-navigation/core' {
260262

261263
declare export type NavigationScreenConfigProps = $Shape<{|
262264
navigation: NavigationScreenProp<NavigationRoute>,
263-
screenProps: {...},
265+
screenProps: NavigationScreenProps,
264266
theme: SupportedThemes,
265267
|}>;
266268

@@ -298,17 +300,15 @@ declare module '@react-navigation/core' {
298300
withRouter<State, Options> &
299301
withOptionalNavigationOptions<Options>;
300302

303+
declare type _NavigationRouteConfigCore = {|
304+
navigationOptions?: NavigationScreenConfig<*>,
305+
params?: NavigationParams,
306+
path?: string,
307+
|};
301308
declare export type NavigationRouteConfig =
302309
| NavigationComponent
303-
| ({
304-
navigationOptions?: NavigationScreenConfig<*>,
305-
path?: string,
306-
...
307-
} & NavigationScreenRouteConfig);
308-
309-
declare export type NavigationScreenRouteConfig =
310-
| { screen: NavigationComponent, ... }
311-
| { getScreen: () => NavigationComponent, ... };
310+
| {| ..._NavigationRouteConfigCore, screen: NavigationComponent |}
311+
| {| ..._NavigationRouteConfigCore, getScreen: () => NavigationComponent |};
312312

313313
declare export type NavigationRouteConfigMap = { [routeName: string]: NavigationRouteConfig, ... };
314314

@@ -392,7 +392,7 @@ declare module '@react-navigation/core' {
392392

393393
declare export type NavigationNavigatorProps<O: {...}, S: {...}> = $Shape<{
394394
navigation: NavigationScreenProp<S>,
395-
screenProps?: {...},
395+
screenProps?: NavigationScreenProps,
396396
navigationOptions?: O,
397397
theme?: SupportedThemes | 'no-preference',
398398
detached?: boolean,
@@ -421,7 +421,7 @@ declare module '@react-navigation/core' {
421421
navigation?: NavigationScreenProp<S>,
422422
persistenceKey?: ?string,
423423
renderLoadingExperimental?: React$ComponentType<{...}>,
424-
screenProps?: *,
424+
screenProps?: NavigationScreenProps,
425425
navigationOptions?: O,
426426
...
427427
}>;
@@ -556,8 +556,9 @@ declare module '@react-navigation/core' {
556556
cardOverlayEnabled?: boolean,
557557
|}>;
558558

559+
declare type _InterpolationResult = { [key: string]: mixed, ... };
559560
declare export type NavigationStackInterpolator =
560-
(props: NavigationStackInterpolatorProps) => {...};
561+
(props: NavigationStackInterpolatorProps) => _InterpolationResult;
561562

562563
/**
563564
* Header
@@ -764,14 +765,14 @@ declare module '@react-navigation/core' {
764765
getCurrentNavigation: () => ?NavigationScreenProp<State>
765766
): NavigationScreenProp<State>;
766767

767-
declare type _NavigationView<O, S> = React$ComponentType<{
768+
declare type _NavigationView<O, S, N: NavigationScreenProp<S>> = React$ComponentType<{
768769
descriptors: NavigationDescriptorMap,
769-
navigation: NavigationScreenProp<S>,
770+
navigation: N,
770771
navigationConfig: *,
771772
...
772773
}>;
773-
declare export function createNavigator<O: *, S: *, NavigatorConfig: *>(
774-
view: _NavigationView<O, S>,
774+
declare export function createNavigator<O: *, S: *, NavigatorConfig: *, N: NavigationScreenProp<S>>(
775+
view: _NavigationView<O, S, N>,
775776
router: NavigationRouter<S, O>,
776777
navigatorConfig?: NavigatorConfig
777778
): NavigationNavigator<S, O, *>;
@@ -877,17 +878,17 @@ declare module '@react-navigation/core' {
877878
Options: {...}
878879
>(
879880
navigation: NavigationScreenProp<State>,
880-
screenProps?: {...},
881+
screenProps?: NavigationScreenProps,
881882
theme?: SupportedThemes,
882883
): Options;
883884

884885
declare type _SceneViewProps = {
885886
component: React$ComponentType<{
886-
screenProps: ?{...},
887+
screenProps: ?NavigationScreenProps,
887888
navigation: NavigationScreenProp<NavigationRoute>,
888889
...
889890
}>,
890-
screenProps: ?{...},
891+
screenProps: ?NavigationScreenProps,
891892
navigation: NavigationScreenProp<NavigationRoute>,
892893
...
893894
};
@@ -917,4 +918,37 @@ declare module '@react-navigation/core' {
917918
Component: ComponentType
918919
): React$ComponentType<$Diff<React$ElementConfig<ComponentType>, {| isFocused: ?boolean |}>>;
919920

921+
declare export function createAppContainer<S: NavigationState, O: {...}>(
922+
Component: NavigationNavigator<S, O, *>
923+
): NavigationContainer<S, O, *>;
924+
925+
declare export function createKeyboardAwareNavigator<Props: {...}>(
926+
Comp: React$ComponentType<Props>,
927+
stackConfig: {...}
928+
): React$ComponentType<Props>;
929+
930+
declare export function withOrientation<Props: {...}, ComponentType: React$ComponentType<Props>>(
931+
Component: ComponentType
932+
): React$ComponentType<$Diff<React$ElementConfig<ComponentType>, {| isLandscape: boolean |}>>;
933+
934+
declare type _SafeAreaViewProps = {
935+
forceInset?: _SafeAreaViewInsets,
936+
children?: React$Node,
937+
style?: AnimatedViewStyleProp,
938+
...
939+
};
940+
declare export var SafeAreaView: React$ComponentType<_SafeAreaViewProps>;
941+
942+
// These components take the same props that their React Native primitives do
943+
// Typing them correctly would be extremely brittle
944+
// We await the day we can import types from libraries in flow-typed libdefs
945+
declare export var ScrollView: React$ComponentType<{...}>;
946+
declare export var FlatList: React$ComponentType<{...}>;
947+
declare export var SectionList: React$ComponentType<{...}>;
948+
declare export var Themed: {|
949+
StatusBar: React$ComponentType<{...}>,
950+
Text: React$ComponentType<{...}>,
951+
TextInput: React$ComponentType<{...}>,
952+
|};
953+
920954
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"index.d.ts"
2222
],
2323
"peerDependencies": {
24-
"@react-navigation/core": "*",
2524
"react": "*",
2625
"react-native-safe-area-context": "*",
26+
"react-navigation": "*",
2727
"redux": "*"
2828
}
2929
}

src/create-redux-container.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ import type {
77
NavigationScreenProp,
88
NavigationNavigatorProps,
99
SupportedThemes,
10-
} from '@react-navigation/core';
10+
} from 'react-navigation';
1111

1212
import * as React from 'react';
1313
import { SafeAreaProvider } from 'react-native-safe-area-context';
14-
import {
15-
ThemeProvider,
16-
NavigationProvider,
17-
} from '@react-navigation/core';
14+
import { ThemeProvider, NavigationProvider } from 'react-navigation';
1815

1916
import {
2017
initializeListeners,

src/middleware.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// @flow
22

3-
import {
4-
type NavigationEventCallback,
5-
type NavigationEventPayload,
6-
type NavigationState,
7-
type NavigationDispatch,
8-
type NavigationScreenProp,
9-
type NavigationRouter,
10-
getNavigation,
11-
} from '@react-navigation/core';
3+
import type {
4+
NavigationEventCallback,
5+
NavigationEventPayload,
6+
NavigationState,
7+
NavigationDispatch,
8+
NavigationScreenProp,
9+
NavigationRouter,
10+
} from 'react-navigation';
1211
import type { Middleware } from 'redux';
1312

1413
import invariant from 'invariant';
14+
import { getNavigation } from 'react-navigation';
1515

1616
import { initAction } from './reducer';
1717

src/reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @flow
22

3-
import type { NavigationAction, NavigationState } from '@react-navigation/core';
3+
import type { NavigationAction, NavigationState } from 'react-navigation';
44
import type { Reducer } from 'redux';
55
import type { Navigator, ReducerState } from './types'
66

7-
import { NavigationActions } from "@react-navigation/core";
7+
import { NavigationActions } from 'react-navigation';
88

99
const initAction = NavigationActions.init();
1010

src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import type { NavigationContainer, NavigationState } from '@react-navigation/core';
3+
import type { NavigationContainer, NavigationState } from 'react-navigation';
44

55
export type Navigator = NavigationContainer<*, *, *>;
66
export type ReducerState = ?NavigationState;

0 commit comments

Comments
 (0)