From be007470b99d955f78a46062ad91e6f03343ad0f Mon Sep 17 00:00:00 2001 From: Eduard Zintz Date: Wed, 21 Jun 2017 18:29:25 +0200 Subject: [PATCH 1/3] Added react-router-native --- types/react-router-native/index.d.ts | 46 +++++++++++++++++++ .../react-router-native-tests.tsx | 15 ++++++ types/react-router-native/tsconfig.json | 19 ++++++++ types/react-router-native/tslint.json | 7 +++ 4 files changed, 87 insertions(+) create mode 100644 types/react-router-native/index.d.ts create mode 100644 types/react-router-native/react-router-native-tests.tsx create mode 100644 types/react-router-native/tsconfig.json create mode 100644 types/react-router-native/tslint.json diff --git a/types/react-router-native/index.d.ts b/types/react-router-native/index.d.ts new file mode 100644 index 0000000000..2238be18fb --- /dev/null +++ b/types/react-router-native/index.d.ts @@ -0,0 +1,46 @@ +// Type definitions for React Router Native 4.0 +// Project: https://github.com/ReactTraining/react-router-native +// Definitions by: Eduard Zintz +// 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>; +} + +export class AndroidBackButton extends React.Component {} + +export class DeepLinking extends React.Component<{}, {}> {} + +export interface LinkProps { + to: H.LocationDescriptor; + replace?: boolean; + component?: React.Component; +} + +export class Link extends React.Component {} + +export interface NativeRouterProps { + getUserConfirmation?: Function; + keyLength?: number; +} + +export class NativeRouter extends React.Component {} diff --git a/types/react-router-native/react-router-native-tests.tsx b/types/react-router-native/react-router-native-tests.tsx new file mode 100644 index 0000000000..9126858216 --- /dev/null +++ b/types/react-router-native/react-router-native-tests.tsx @@ -0,0 +1,15 @@ +import * as React from 'react'; +import {View} from 'react-native'; +import {NativeRouter as Router} from 'react-router-native'; + +export default class App extends React.Component<{}, {}> { + render() { + return ( + + + Welcome! + + + ); + } +} diff --git a/types/react-router-native/tsconfig.json b/types/react-router-native/tsconfig.json new file mode 100644 index 0000000000..6764b72818 --- /dev/null +++ b/types/react-router-native/tsconfig.json @@ -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" + ] +} diff --git a/types/react-router-native/tslint.json b/types/react-router-native/tslint.json new file mode 100644 index 0000000000..c9a409bbed --- /dev/null +++ b/types/react-router-native/tslint.json @@ -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 + } +} From 015c1df166a76a749578221a3299f3dfa27a4735 Mon Sep 17 00:00:00 2001 From: Eduard Zintz Date: Wed, 21 Jun 2017 22:45:06 +0200 Subject: [PATCH 2/3] Fixed LinkProps interface to extend a default anchor element --- types/react-router-native/index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/react-router-native/index.d.ts b/types/react-router-native/index.d.ts index 2238be18fb..214e81b0d3 100644 --- a/types/react-router-native/index.d.ts +++ b/types/react-router-native/index.d.ts @@ -31,9 +31,10 @@ export class AndroidBackButton extends React.Component {} export interface LinkProps { - to: H.LocationDescriptor; - replace?: boolean; component?: React.Component; + replace?: boolean; + style?: any; + to: H.LocationDescriptor; } export class Link extends React.Component {} From 4ce8ee33a95ae5d8ba613ebab6313d2376fda210 Mon Sep 17 00:00:00 2001 From: Eduard Zintz Date: Wed, 21 Jun 2017 23:15:37 +0200 Subject: [PATCH 3/3] Extended test --- .../react-router-native-tests.tsx | 73 ++++++++++++++++++- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/types/react-router-native/react-router-native-tests.tsx b/types/react-router-native/react-router-native-tests.tsx index 9126858216..40cd5b8532 100644 --- a/types/react-router-native/react-router-native-tests.tsx +++ b/types/react-router-native/react-router-native-tests.tsx @@ -1,15 +1,80 @@ import * as React from 'react'; -import {View} from 'react-native'; -import {NativeRouter as Router} from 'react-router-native'; +import {StyleSheet, Text, View} from 'react-native'; +import {NativeRouter as Router, Route, Link} from 'react-router-native'; + +const Home: React.SFC<{}> = () => { + return ( + + + Welcome to React Native! + + + Press Cmd+R to reload,{'\n'} + Cmd+D or shake for dev menu + + + ); +}; + +const About: React.SFC<{}> = () => { + return ( + + About + + ); +}; export default class App extends React.Component<{}, {}> { render() { return ( - - Welcome! + + + + Home + + + About + + + + ); } } + +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, + }, +});