From ead05a22eb89d1a00082c4eb62e8f6393c58399c Mon Sep 17 00:00:00 2001 From: Esteban Ibarra Date: Mon, 19 Nov 2018 08:19:12 -0500 Subject: [PATCH 1/3] Fix children type for react-native-dialog (#1) * Fix children type for react-native-dialog --- types/react-native-dialog/index.d.ts | 4 +++- .../react-native-dialog-tests.tsx | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/types/react-native-dialog/index.d.ts b/types/react-native-dialog/index.d.ts index 10e977f420..14d7458140 100644 --- a/types/react-native-dialog/index.d.ts +++ b/types/react-native-dialog/index.d.ts @@ -1,6 +1,8 @@ // Type definitions for react-native-dialog 4.0 // Project: https://github.com/mmazzarolo/react-native-dialog // Definitions by: MrLuje +// Stack Builders +// Esteban Ibarra // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -32,7 +34,7 @@ interface ButtonProps { interface ContainerProps { blurComponentIOS?: ReactNode; - children: JSX.Element[]; + children: React.ReactNode[]; /** * default: false */ diff --git a/types/react-native-dialog/react-native-dialog-tests.tsx b/types/react-native-dialog/react-native-dialog-tests.tsx index 151ee14af5..544025051c 100644 --- a/types/react-native-dialog/react-native-dialog-tests.tsx +++ b/types/react-native-dialog/react-native-dialog-tests.tsx @@ -2,6 +2,24 @@ import Dialog from "react-native-dialog"; import { createRef, Component } from "react"; class Example extends Component { + dynamicButtons() { + const buttonFunc = () => console.log('click'); + const buttons = [ + { label: 'Button 1', action: buttonFunc }, + { label: 'Button 2', action: buttonFunc }, + ]; + return buttons.map(({ label , action }) => + + ); + } + + singleButton() { + return ( null} />); + } + render() { const ref = createRef(); @@ -23,6 +41,8 @@ class Example extends Component { label="Validate" onPress={() => console.log("test")} /> + {this.dynamicButtons()} + {this.singleButton()} ); } From 845918b6a86a6190c23da22b4d8def7ac9adeffb Mon Sep 17 00:00:00 2001 From: Esteban Ibarra Date: Tue, 20 Nov 2018 12:15:15 -0500 Subject: [PATCH 2/3] Add types for react-native-draggable-flatlist --- .../index.d.ts | 59 +++++++++++++++++++ .../react-native-draggable-flatlist-tests.tsx | 44 ++++++++++++++ .../tsconfig.json | 24 ++++++++ .../tslint.json | 1 + 4 files changed, 128 insertions(+) create mode 100644 types/react-native-draggable-flatlist/index.d.ts create mode 100644 types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx create mode 100644 types/react-native-draggable-flatlist/tsconfig.json create mode 100644 types/react-native-draggable-flatlist/tslint.json diff --git a/types/react-native-draggable-flatlist/index.d.ts b/types/react-native-draggable-flatlist/index.d.ts new file mode 100644 index 0000000000..0b96f0b3cd --- /dev/null +++ b/types/react-native-draggable-flatlist/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for react-native-draggable-flatlist 1.1 +// Project: https://github.com/computerjazz/react-native-draggable-flatlist#readme +// Definitions by: Stack Builders +// Esteban Ibarra +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { VirtualizedListWithoutRenderItemProps } from "react-native"; +import { Component } from "react"; + +export interface RenderItemInfo { + item: ItemR; + index: number; + move: () => void; + moveEnd: () => void; + isActive: boolean; +} + +export interface OnMoveEndInfo { + data: ReadonlyArray | null; + to: number; + from: number; + row: ItemM; +} + +interface DraggableFlatListProps extends VirtualizedListWithoutRenderItemProps { + /** + * Items to be rendered. + */ + data: ReadonlyArray | null; + + /** + * Function that returns updated ordering of data + */ + onMoveEnd?: (info: OnMoveEndInfo) => void; + + /** + * Function that is called when row becomes active. + */ + onMoveBegin?: (index: number) => void; + + /** + * Sets where scrolling begins. + * + * Default is 5 + */ + scrollPercent?: number; + + /** + * Function that calls move when the row should become active (in an onPress, onLongPress, etc). Calls moveEnd when the gesture is complete (in onPressOut). + */ + renderItem: (info: RenderItemInfo) => React.ReactElement | null; +} + +declare class DraggableFlatList extends Component> { + constructor(props: DraggableFlatListProps); +} + +export default DraggableFlatList; diff --git a/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx b/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx new file mode 100644 index 0000000000..40d613e4ea --- /dev/null +++ b/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx @@ -0,0 +1,44 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import DraggableFlatList, { RenderItemInfo } from 'react-native-draggable-flatlist'; + +interface Item { + name: string; + mail: string; +} + +class Example extends React.Component { + state = { + data: [ + { name: 'Esteban', mail: 'foo@foo.com' }, + { name: 'Xavier', mail: 'foo2@foo.com' }, + ] + }; + + renderItem({ item, index, move, moveEnd, isActive }: RenderItemInfo) { + return ( + + {index} + {item.name} + {item.mail} + + ); + } + + render() { + const { data } = this.state; + return ( + `draggable-item-${index}`} + scrollPercent={10} + onMoveEnd={({ data }) => this.setState({ data })} + ListFooterComponent={{'Hello'}} + /> + ); + } +} diff --git a/types/react-native-draggable-flatlist/tsconfig.json b/types/react-native-draggable-flatlist/tsconfig.json new file mode 100644 index 0000000000..b3c009feac --- /dev/null +++ b/types/react-native-draggable-flatlist/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react-native" + }, + "files": [ + "index.d.ts", + "react-native-draggable-flatlist-tests.tsx" + ] +} diff --git a/types/react-native-draggable-flatlist/tslint.json b/types/react-native-draggable-flatlist/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-draggable-flatlist/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From ca53c065a52c288b7d8d3fb3bde5709c6d496f7c Mon Sep 17 00:00:00 2001 From: Esteban Ibarra Date: Tue, 20 Nov 2018 15:18:30 -0500 Subject: [PATCH 3/3] Revert changes of react-native-draggable-flatlist --- .../index.d.ts | 59 ------------------- .../react-native-draggable-flatlist-tests.tsx | 44 -------------- .../tsconfig.json | 24 -------- .../tslint.json | 1 - 4 files changed, 128 deletions(-) delete mode 100644 types/react-native-draggable-flatlist/index.d.ts delete mode 100644 types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx delete mode 100644 types/react-native-draggable-flatlist/tsconfig.json delete mode 100644 types/react-native-draggable-flatlist/tslint.json diff --git a/types/react-native-draggable-flatlist/index.d.ts b/types/react-native-draggable-flatlist/index.d.ts deleted file mode 100644 index 0b96f0b3cd..0000000000 --- a/types/react-native-draggable-flatlist/index.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -// Type definitions for react-native-draggable-flatlist 1.1 -// Project: https://github.com/computerjazz/react-native-draggable-flatlist#readme -// Definitions by: Stack Builders -// Esteban Ibarra -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 - -import { VirtualizedListWithoutRenderItemProps } from "react-native"; -import { Component } from "react"; - -export interface RenderItemInfo { - item: ItemR; - index: number; - move: () => void; - moveEnd: () => void; - isActive: boolean; -} - -export interface OnMoveEndInfo { - data: ReadonlyArray | null; - to: number; - from: number; - row: ItemM; -} - -interface DraggableFlatListProps extends VirtualizedListWithoutRenderItemProps { - /** - * Items to be rendered. - */ - data: ReadonlyArray | null; - - /** - * Function that returns updated ordering of data - */ - onMoveEnd?: (info: OnMoveEndInfo) => void; - - /** - * Function that is called when row becomes active. - */ - onMoveBegin?: (index: number) => void; - - /** - * Sets where scrolling begins. - * - * Default is 5 - */ - scrollPercent?: number; - - /** - * Function that calls move when the row should become active (in an onPress, onLongPress, etc). Calls moveEnd when the gesture is complete (in onPressOut). - */ - renderItem: (info: RenderItemInfo) => React.ReactElement | null; -} - -declare class DraggableFlatList extends Component> { - constructor(props: DraggableFlatListProps); -} - -export default DraggableFlatList; diff --git a/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx b/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx deleted file mode 100644 index 40d613e4ea..0000000000 --- a/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import * as React from 'react'; -import { TouchableOpacity, Text } from 'react-native'; -import DraggableFlatList, { RenderItemInfo } from 'react-native-draggable-flatlist'; - -interface Item { - name: string; - mail: string; -} - -class Example extends React.Component { - state = { - data: [ - { name: 'Esteban', mail: 'foo@foo.com' }, - { name: 'Xavier', mail: 'foo2@foo.com' }, - ] - }; - - renderItem({ item, index, move, moveEnd, isActive }: RenderItemInfo) { - return ( - - {index} - {item.name} - {item.mail} - - ); - } - - render() { - const { data } = this.state; - return ( - `draggable-item-${index}`} - scrollPercent={10} - onMoveEnd={({ data }) => this.setState({ data })} - ListFooterComponent={{'Hello'}} - /> - ); - } -} diff --git a/types/react-native-draggable-flatlist/tsconfig.json b/types/react-native-draggable-flatlist/tsconfig.json deleted file mode 100644 index b3c009feac..0000000000 --- a/types/react-native-draggable-flatlist/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true, - "jsx": "react-native" - }, - "files": [ - "index.d.ts", - "react-native-draggable-flatlist-tests.tsx" - ] -} diff --git a/types/react-native-draggable-flatlist/tslint.json b/types/react-native-draggable-flatlist/tslint.json deleted file mode 100644 index 3db14f85ea..0000000000 --- a/types/react-native-draggable-flatlist/tslint.json +++ /dev/null @@ -1 +0,0 @@ -{ "extends": "dtslint/dt.json" }