From 4bfdd6f05331f4f9fcd1e6825716c0eb551d1153 Mon Sep 17 00:00:00 2001 From: Jacob Froman Date: Mon, 9 Oct 2017 16:56:03 -0500 Subject: [PATCH] [react-native-linear-gradient] Add Typings (#20377) * Add LinearGradient typings * Fix typo in props type * Enable strictFunctionTypes and fix lint errors --- types/react-native-linear-gradient/index.d.ts | 47 +++++++++++++++++++ .../react-native-linear-gradient-tests.tsx | 35 ++++++++++++++ .../tsconfig.json | 25 ++++++++++ .../react-native-linear-gradient/tslint.json | 1 + 4 files changed, 108 insertions(+) create mode 100644 types/react-native-linear-gradient/index.d.ts create mode 100644 types/react-native-linear-gradient/react-native-linear-gradient-tests.tsx create mode 100644 types/react-native-linear-gradient/tsconfig.json create mode 100644 types/react-native-linear-gradient/tslint.json diff --git a/types/react-native-linear-gradient/index.d.ts b/types/react-native-linear-gradient/index.d.ts new file mode 100644 index 0000000000..9c7bfbc1fd --- /dev/null +++ b/types/react-native-linear-gradient/index.d.ts @@ -0,0 +1,47 @@ +// Type definitions for react-native-linear-gradient 2.3 +// Project: https://github.com/brentvatne/react-native-linear-gradient#readme +// Definitions by: Jacob Froman +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import * as React from 'react'; +import { ViewProperties } from 'react-native'; + +interface LinearGradientProps extends ViewProperties { + children?: React.ReactNode; + + /** + * Colors that will be used for the gradient + */ + colors?: ReadonlyArray; + + /** + * Coordinates of the position that the gradient starts at, as a fraction + * of the overall size of the gradient, starting from the top left corner. + * { x: 0.1, y: 0.1 } means that the gradient will start 10% from the top + * and 10% from the left. + */ + start?: { x: number; y: number }; + + /** + * Coordinates of the position that the gradient ends at, as a fraction + * of the overall size of the gradient, starting from the top left corner. + * { x: 0.9, y: 0.9 } means that the gradient will end 90% from the top + * and 90% from the left. + */ + end?: { x: number; y: number }; + + /** + * An optional array of numbers defining the location of each gradient + * color stop, mapping to the color with the same index in colors prop. + * [0.1, 0.75, 1] means that first color will take 0% - 10%, second color + * will take 10% - 75% and finally third color will occupy 75% - 100%. + */ + locations?: ReadonlyArray; +} + +declare class LinearGradient extends React.Component { + constructor(props: LinearGradientProps); +} + +export default LinearGradient; diff --git a/types/react-native-linear-gradient/react-native-linear-gradient-tests.tsx b/types/react-native-linear-gradient/react-native-linear-gradient-tests.tsx new file mode 100644 index 0000000000..00172818b1 --- /dev/null +++ b/types/react-native-linear-gradient/react-native-linear-gradient-tests.tsx @@ -0,0 +1,35 @@ +import * as React from 'react'; +import LinearGradient from 'react-native-linear-gradient'; +import { Text, StyleSheet } from 'react-native'; + +export default class MyLinearGradient extends React.Component { + render() { + return ( + + Sign in with Facebook + + ); + } +} + +const styles = StyleSheet.create({ + linearGradient: { + flex: 1, + paddingLeft: 15, + paddingRight: 15, + borderRadius: 5 + }, + buttonText: { + fontSize: 18, + textAlign: 'center', + margin: 10, + color: '#ffffff', + backgroundColor: 'transparent' + } +}); diff --git a/types/react-native-linear-gradient/tsconfig.json b/types/react-native-linear-gradient/tsconfig.json new file mode 100644 index 0000000000..11c04115c3 --- /dev/null +++ b/types/react-native-linear-gradient/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react-native" + }, + "files": [ + "index.d.ts", + "react-native-linear-gradient-tests.tsx" + ] +} diff --git a/types/react-native-linear-gradient/tslint.json b/types/react-native-linear-gradient/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-linear-gradient/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }