Skip to content

Commit

Permalink
fix: update typescript definitions. closes #6276
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Sep 9, 2019
1 parent 4e7f9f0 commit 2744c53
Showing 1 changed file with 65 additions and 47 deletions.
112 changes: 65 additions & 47 deletions typescript/react-navigation.d.ts
Expand Up @@ -33,7 +33,6 @@

declare module 'react-navigation' {
import * as React from 'react';
import { PanGestureHandler } from 'react-native-gesture-handler';

import {
Animated,
Expand All @@ -50,14 +49,10 @@ declare module 'react-navigation' {
// @todo: should we re-export from RNGH? not currently exposed through it
export { FlatList, SectionList, ScrollView } from 'react-native';

export type ScreenProps = {
[key: string]: any;
};

// @todo - any..
export function getActiveChildNavigationOptions<S>(
navigation: NavigationProp<S>,
screenProps?: ScreenProps,
screenProps?: unknown,
theme?: SupportedThemes
): NavigationParams;

Expand Down Expand Up @@ -138,7 +133,7 @@ declare module 'react-navigation' {

export type NavigationScreenOptionsGetter<Options> = (
navigation: NavigationScreenProp<NavigationRoute<any>>,
screenProps: ScreenProps | null,
screenProps: unknown | null,
theme: SupportedThemes
) => Options;

Expand Down Expand Up @@ -173,6 +168,13 @@ declare module 'react-navigation' {

getComponentForState: (state: State) => NavigationComponent;

getActionCreators: (
route: NavigationRoute,
key: string
) => {
[key: string]: () => NavigationAction;
};

/**
* Gets the screen navigation options for a given screen.
*
Expand All @@ -194,13 +196,9 @@ declare module 'react-navigation' {
navigation: NavigationScreenProp<NavigationRoute>;
}

export type NavigationScreenOptions = NavigationStackScreenOptions &
NavigationTabScreenOptions &
NavigationDrawerScreenOptions;

export interface NavigationScreenConfigProps {
navigation: NavigationScreenProp<NavigationRoute>;
screenProps: ScreenProps;
screenProps: unknown;
theme: SupportedThemes;
}

Expand All @@ -221,7 +219,7 @@ declare module 'react-navigation' {
Params = NavigationParams,
Options = {},
Props = {}
> = React.ComponentType<NavigationScreenProps<Params, Options> & Props> & {
> = React.ComponentType<Navigationunknown<Params, Options> & Props> & {
navigationOptions?: NavigationScreenConfig<Options>;
};

Expand Down Expand Up @@ -255,6 +253,7 @@ declare module 'react-navigation' {

export interface NavigationBackActionPayload {
key?: string | null;
immediate?: boolean;
}

export interface NavigationBackAction extends NavigationBackActionPayload {
Expand All @@ -280,6 +279,7 @@ declare module 'react-navigation' {

export interface NavigationInitAction extends NavigationInitActionPayload {
type: 'Navigation/INIT';
key?: string;
}

export interface NavigationReplaceActionPayload {
Expand All @@ -300,6 +300,7 @@ declare module 'react-navigation' {

export interface NavigationCompleteTransitionActionPayload {
key?: string;
toChildKey?: string;
}

export interface NavigationCompleteTransitionAction {
Expand Down Expand Up @@ -333,6 +334,7 @@ declare module 'react-navigation' {

export interface NavigationPopAction extends NavigationPopActionPayload {
type: 'Navigation/POP';
key?: string;
}

export interface NavigationPopToTopActionPayload {
Expand Down Expand Up @@ -374,6 +376,16 @@ declare module 'react-navigation' {
params?: NavigationParams;
}

export interface NavigationDrawerOpenedAction {
key?: string;
type: 'Navigation/DRAWER_OPENED';
}

export interface NavigationDrawerClosedAction {
key?: string;
type: 'Navigation/DRAWER_CLOSED';
}

export interface NavigationOpenDrawerAction {
key?: string;
type: 'Navigation/OPEN_DRAWER';
Expand All @@ -392,19 +404,19 @@ declare module 'react-navigation' {
/**
* Switch Navigator
*/

export interface SwitchRouter extends NavigationRouter {}

export interface NavigationSwitchRouterConfig {
initialRouteName?: string;
initialRouteParams?: NavigationParams;
paths?: NavigationPathsConfig;
defaultNavigationOptions?: NavigationScreenConfig<NavigationScreenOptions>;
order?: string[];
backBehavior: 'none' | 'initialRoute' | 'history' | 'order'; // defaults to 'none'
backBehavior?: 'none' | 'initialRoute' | 'history' | 'order'; // defaults to 'none'
resetOnBlur?: boolean; // defaults to `true`
}

export function SwitchRouter(
routeConfigs: NavigationRouteConfigMap,
config?: NavigationSwitchRouterConfig
): NavigationRouter<any, any>;

export type NavigationStackAction =
| NavigationInitAction
Expand All @@ -424,6 +436,8 @@ declare module 'react-navigation' {
| NavigationBackAction;

export type NavigationDrawerAction =
| NavigationDrawerOpenedAction
| NavigationDrawerClosedAction
| NavigationOpenDrawerAction
| NavigationCloseDrawerAction
| NavigationToggleDrawerAction;
Expand All @@ -435,7 +449,8 @@ declare module 'react-navigation' {
| NavigationStackAction
| NavigationTabAction
| NavigationDrawerAction
| NavigationSwitchAction;
| NavigationSwitchAction
| { type: 'CHILD_ACTION'; key?: string };

export type NavigationRouteConfig =
| NavigationComponent
Expand All @@ -458,26 +473,14 @@ declare module 'react-navigation' {
}

// tslint:disable-next-line:strict-export-declare-modifiers
interface NavigationTabRouterConfigBase {
interface NavigationTabRouterConfig {
initialRouteName?: string;
initialRouteParams?: NavigationParams;
paths?: NavigationPathsConfig;
order?: string[]; // todo: type these as the real route names rather than 'string'
backBehavior?: 'none' | 'initialRoute' | 'history' | 'order'; // defaults to 'initialRoute'
resetOnBlur?: boolean;
}
export interface NavigationTabRouterConfig
extends NavigationTabRouterConfigBase {
defaultNavigationOptions?: NavigationScreenConfig<NavigationScreenOptions>;
navigationOptions?: NavigationScreenConfig<any>;
}
export interface NavigationBottomTabRouterConfig
extends NavigationTabRouterConfigBase {
defaultNavigationOptions?: NavigationScreenConfig<
NavigationBottomTabScreenOptions
>;
navigationOptions?: NavigationScreenConfig<any>;
}

export interface NavigationRouteConfigMap {
[routeName: string]: NavigationRouteConfig;
Expand Down Expand Up @@ -581,7 +584,7 @@ declare module 'react-navigation' {
theme?: SupportedThemes | 'no-preference';
detached?: boolean;
navigation?: NavigationProp<S>;
screenProps?: ScreenProps;
screenProps?: unknown;
navigationOptions?: O;
}

Expand Down Expand Up @@ -614,7 +617,7 @@ declare module 'react-navigation' {
persistNavigationState?: (state: NavigationState) => Promise<any>;

renderLoadingExperimental?: React.ComponentType;
screenProps?: ScreenProps;
screenProps?: unknown;
navigationOptions?: O;
style?: StyleProp<ViewStyle>;
}
Expand All @@ -636,7 +639,7 @@ declare module 'react-navigation' {
): NavigationContainerComponent;

router: NavigationRouter<any, any>;
screenProps: ScreenProps;
screenProps: unknown;
navigationOptions: any;
state: { nav: NavigationState | null };
}
Expand Down Expand Up @@ -714,7 +717,7 @@ declare module 'react-navigation' {
): NavigationReplaceAction;

function completeTransition(
payload: NavigationCompleteTransitionActionPayload
payload?: NavigationCompleteTransitionActionPayload
): NavigationCompleteTransitionAction;
}

Expand Down Expand Up @@ -746,15 +749,13 @@ declare module 'react-navigation' {
*/
export function StackRouter(
routeConfigs: NavigationRouteConfigMap,
config: NavigationTabRouterConfig
config?: NavigationTabRouterConfig
): NavigationRouter<any, any>;

export interface NavigationStackRouterConfig {
initialRouteName?: string;
initialRouteParams?: NavigationParams;
paths?: NavigationPathsConfig;
defaultNavigationOptions?: NavigationScreenConfig<NavigationScreenOptions>;
navigationOptions?: NavigationScreenConfig<NavigationScreenOptions>;
initialRouteKey?: string;
}

Expand All @@ -763,19 +764,22 @@ declare module 'react-navigation' {
*
* @see https://github.com/react-navigation/react-navigation/blob/master/src/navigators/createNavigator.js
*/
export interface NavigationDescriptor<Params = NavigationParams> {
export interface NavigationDescriptor<
Params = NavigationParams,
Options = {}
> {
key: string;
state: NavigationLeafRoute<Params> | NavigationStateRoute<Params>;
navigation: NavigationScreenProp<any>;
options: NavigationScreenOptions;
options: Options;
getComponent: () => React.ComponentType;
}

export type NavigationView<O, S> = React.ComponentType<
{
descriptors: { [key: string]: NavigationDescriptor };
navigationConfig: O;
screenProps?: ScreenProps;
screenProps?: unknown;
} & NavigationInjectedProps
>;

Expand Down Expand Up @@ -815,12 +819,12 @@ declare module 'react-navigation' {
* BEGIN CUSTOM CONVENIENCE INTERFACES
*/

export interface NavigationScreenProps<

This comment has been minimized.

Copy link
@mikehardy

mikehardy Sep 9, 2019

Contributor

Hey @satya164 - I don't understand this change, is it intended to be breaking? I was relying on the NavigationScreenProps type in my project 🤔

This comment has been minimized.

Copy link
@satya164

satya164 Sep 9, 2019

Author Member

sorry, typo. fixed and released

This comment has been minimized.

Copy link
@mikehardy

mikehardy Sep 9, 2019

Contributor

Fantastic thank you!

export interface Navigationunknown<
Params = NavigationParams,
Options = any
> {
navigation: NavigationScreenProp<NavigationRoute<Params>, Params>;
screenProps?: ScreenProps;
screenProps?: unknown;
navigationOptions?: NavigationScreenConfig<Options>;
}

Expand All @@ -838,6 +842,11 @@ declare module 'react-navigation' {
isLandscape: boolean;
}

export function createKeyboardAwareNavigator<Props>(
Comp: React.ComponentType<Props>,
stackConfig: object
): React.ComponentType<Props>;

export function withOrientation<P extends NavigationOrientationInjectedProps>(
Component: React.ComponentType<P>
): React.ComponentType<Omit<P, keyof NavigationOrientationInjectedProps>>;
Expand Down Expand Up @@ -869,6 +878,10 @@ declare module 'react-navigation' {
T & { onRef?: React.Ref<React.Component<T & NavigationInjectedProps<P>>> }
>;

export const NavigationProvider: React.ComponentType<{
value: NavigationProp<any>;
}>;

export interface NavigationFocusInjectedProps<P = NavigationParams>
extends NavigationInjectedProps<P> {
isFocused: boolean;
Expand Down Expand Up @@ -921,17 +934,22 @@ declare module 'react-navigation' {
NavigationScreenProp<NavigationRoute>
>;

export function createKeyboardAwareNavigator<Props>(
Comp: React.ComponentType<Props>,
stackConfig: object
): React.ComponentType<Props>;

/**
* SceneView
*/

export interface SceneViewProps {
component: React.ComponentType;
screenProps: ScreenProps;
navigation: NavigationScreenProp<NavigationRoute>;
screenProps: unknown;
navigation: NavigationProp<any>;
}

export class SceneView extends React.Component {}
export const SceneView: React.ComponentType<SceneViewProps>;

/**
* Themes
Expand Down

0 comments on commit 2744c53

Please sign in to comment.