Merge pull request #17366 from ezintz/master

Added react-router-native typings based on the ones from react-router-dom
This commit is contained in:
Nathan Shively-Sanders
2017-06-21 14:38:52 -07:00
committed by GitHub
4 changed files with 153 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
// Type definitions for React Router Native 4.0
// Project: https://github.com/ReactTraining/react-router-native
// Definitions by: Eduard Zintz <https://github.com/ezintz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export {
match,
matchPath,
MemoryRouter,
Prompt,
Redirect,
Route,
RouteComponentProps,
RouteProps,
Router,
RouterChildContext,
StaticRouter,
Switch,
withRouter
} from 'react-router';
import * as React from 'react';
import * as H from 'history';
export interface AndroidBackButtonProps {
children: Array<React.Component<void, void>>;
}
export class AndroidBackButton extends React.Component<AndroidBackButtonProps, void> {}
export class DeepLinking extends React.Component<{}, {}> {}
export interface LinkProps {
component?: React.Component<void, void>;
replace?: boolean;
style?: any;
to: H.LocationDescriptor;
}
export class Link extends React.Component<LinkProps, void> {}
export interface NativeRouterProps {
getUserConfirmation?: Function;
keyLength?: number;
}
export class NativeRouter extends React.Component<NativeRouterProps, void> {}
@@ -0,0 +1,80 @@
import * as React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {NativeRouter as Router, Route, Link} from 'react-router-native';
const Home: React.SFC<{}> = () => {
return (
<View>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
};
const About: React.SFC<{}> = () => {
return (
<Text style={styles.header}>
About
</Text>
);
};
export default class App extends React.Component<{}, {}> {
render() {
return (
<Router>
<View style={styles.container}>
<View style={styles.nav}>
<Link to="/" style={styles.navItem}>
<Text>Home</Text>
</Link>
<Link to="/about" style={styles.navItem}>
<Text>About</Text>
</Link>
</View>
<Route exact path="/" component={Home}/>
<Route path="/about" component={About}/>
</View>
</Router>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
header: {
fontSize: 20
},
nav: {
flexDirection: 'row',
justifyContent: 'space-around'
},
navItem: {
flex: 1,
alignItems: 'center',
padding: 10
},
subNavItem: {
padding: 5
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"module": "commonjs",
"lib": ["es6", "dom"],
"jsx": "react",
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitThis": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true
},
"files": [
"index.d.ts",
"react-router-native-tests.tsx"
]
}
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "dtslint/dt.json",
"rules": {
// This package uses the Function type, and it will take effort to fix.
"ban-types": false
}
}