dancormier / react-native-swipeout

iOS-style swipeout buttons behind component
MIT License
2.62k stars 649 forks source link

Types for TypeScript 2.0 Support #207

Closed adrianhall closed 7 years ago

adrianhall commented 7 years ago

I've added two elements to support usage of this component in TypeScript:

1) An index.d.ts that provides the types for the props and the component to be used in a TypeScript environment. 2) Update to the package.json that brings the types into TypeScript.

You will need to keep the types file (index.d.ts) updated going forward if you update the props.

An example situation is as follows (from one of my own components):

    renderItem(item: Note, index: number): JSX.Element {
        const onDeleteItem = this.props.onDeleteItem ? this.props.onDeleteItem : () => { /* Do Nothing */ };
        const swipeSettings = {
            autoClose: true,
            close: item.noteId !== this.state.activeRow,
            onClose: (secId, rowId, dir) => this.onSwipeClose(item, rowId, dir),
            onOpen: (secId, rowId, dir) => this.onSwipeOpen(item, rowId, dir),
            right: [
                { onPress: () => onDeleteItem, text: 'Delete', type: 'delete' }
            ] as SwipeoutButtonProperties[],
            rowId: index,
            sectionId: 1
        } as SwipeoutProperties;

        return (
            <Swipeout {...swipeSettings}>
                <NoteListItem item={item} onPress={() => this.onSelectItem(item)}/>
            </Swipeout>
        );
    }

Thanks for the component!