This repository has been archived by the owner on Feb 8, 2020. It is now read-only.
generated from satya164/typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly infer route type in screen elements
- Loading branch information
Showing
2 changed files
with
10 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import * as React from 'react'; | ||
import Screen from './Screen'; | ||
import { ParamListBase, RouteConfig, TypedNavigator } from './types'; | ||
import { ParamListBase, TypedNavigator } from './types'; | ||
|
||
/** | ||
* Higher order component to create a `Navigator` and `Screen` pair. | ||
* Custom navigators should wrap the navigator component in `createNavigator` before exporting. | ||
* | ||
* @param NavigatorComponent The navigtor component to wrap. | ||
* @param Navigator The navigtor component to wrap. | ||
* @returns Factory method to create a `Navigator` and `Screen` pair. | ||
*/ | ||
export default function createNavigator< | ||
ScreenOptions extends object, | ||
N extends React.ComponentType<any> | ||
>(NavigatorComponent: N) { | ||
NavigatorComponent extends React.ComponentType<any> | ||
>(Navigator: NavigatorComponent) { | ||
return <ParamList extends ParamListBase>(): TypedNavigator< | ||
ParamList, | ||
ScreenOptions, | ||
typeof NavigatorComponent | ||
typeof Navigator | ||
> => { | ||
return { | ||
Navigator: NavigatorComponent, | ||
Screen: Screen as React.ComponentType< | ||
RouteConfig<ParamList, keyof ParamList, ScreenOptions> | ||
>, | ||
Navigator, | ||
Screen, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters