From 840d52474adbb0fbc7befb70d66eed52a79b98b7 Mon Sep 17 00:00:00 2001 From: Kyle Roach Date: Fri, 23 Jun 2017 11:48:03 -0400 Subject: [PATCH] Added definitions for react-native-modalbox --- types/react-native-modalbox/index.d.ts | 205 ++++++++++++++++++ .../react-native-modalbox-tests.tsx | 155 +++++++++++++ types/react-native-modalbox/tsconfig.json | 24 ++ types/react-native-modalbox/tslint.json | 1 + 4 files changed, 385 insertions(+) create mode 100644 types/react-native-modalbox/index.d.ts create mode 100644 types/react-native-modalbox/react-native-modalbox-tests.tsx create mode 100644 types/react-native-modalbox/tsconfig.json create mode 100644 types/react-native-modalbox/tslint.json diff --git a/types/react-native-modalbox/index.d.ts b/types/react-native-modalbox/index.d.ts new file mode 100644 index 0000000000..af99a04f4d --- /dev/null +++ b/types/react-native-modalbox/index.d.ts @@ -0,0 +1,205 @@ +// Type definitions for react-native-modalbox 1.3 +// Project: https://github.com/maxs15/react-native-modalbox#readme +// Definitions by: Kyle Roach +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Typescript Version: 2.3.3 + +import * as React from 'react' +import { ViewProperties } from 'react-native' + +interface ModalProps extends ViewProperties { + /** + * Checks if the modal is open + * + * Default is false + * + * @type {boolean} + * @memberof ModalProps + */ + isOpen?: boolean + + /** + * Checks if the modal is disabled + * + * Default is false + * + * @type {boolean} + * @memberof ModalProps + */ + isDisabled?: boolean + + /** + * If the modal can be closed by pressing on the backdrop + * + * Default is true + * + * @type {boolean} + * @memberof ModalProps + */ + backdropPressToClose?: boolean + + /** + * If the modal can be closed by swiping + * + * Default is true + * + * @type {boolean} + * @memberof ModalProps + */ + swipeToClose?: boolean + + /** + * The threshold to reach in pixels to close the modal + * + * Default is 50 + * + * @type {number} + * @memberof ModalProps + */ + swipeThreshold?: number + + /** + * The height in pixels of the swipeable area + * + * Default is the Window Height + * + * @type {number} + * @memberof ModalProps + */ + swipeArea?: number + + /** + * The final position of the modal. + * Accepts top, center or bottom + * + * Default is center + * + * @type {string} + * @memberof ModalProps + */ + position?: 'top' | 'center' | 'bottom' | string + + /** + * The direction modal enters from + * + * Default is bottom + * + * @type {('top' | 'bottom' | string)} + * @memberof ModalProps + */ + entry?: 'top' | 'bottom' | string + + /** + * If a backdrop is displayed behind the modal + * + * Default is true + * + * @type {boolean} + * @memberof ModalProps + */ + backdrop?: boolean + + /** + * Opacity of the backdrop + * + * Default is 0.5 + * + * @type {number} + * @memberof ModalProps + */ + backdropOpacity?: number + + /** + * Background color of the backdrop + * + * Default is black + * + * @type {string} + * @memberof ModalProps + */ + backdropColor?: string + + /** + * Add an element in the backdrop (a close button for example) + * + * Default is null + * + * @type {JSX.Element} + * @memberof ModalProps + */ + backdropContent?: JSX.Element + + /** + * Duration of the animation + * + * Default is 400ms + * + * @type {number} + * @memberof ModalProps + */ + animationDuration?: number + + /** + * (Android only) Close modal when receiving back button event + * + * Default is false + * + * @type {boolean} + * @memberof ModalProps + */ + backButtonClose?: boolean + + /** + * If the modal should appear open without animation upon first mount + * + * Default is false + * + * @type {boolean} + * @memberof ModalProps + */ + startOpen?: boolean + + /** + * Event fired when the modal is closed and the animation is complete + * + * @memberof ModalProps + */ + onClosed?(): void + + /** + * Event fired when the modal is opened and the animation is complete + * + * @memberof ModalProps + */ + onOpen?(): void + + /** + * When the state of the swipe to close feature has changed + * (useful to change the content of the modal, display a message for example) + * + * @param {boolean} state + * + * @memberof ModalProps + */ + onClosingState?(state: boolean): void +} + +export default class Modal extends React.Component { + /** + * Open the modal + * + * @static + * + * @memberof Modal + */ + static open(): void + + /** + * Close the modal + * + * @static + * + * @memberof Modal + */ + static close(): void +} diff --git a/types/react-native-modalbox/react-native-modalbox-tests.tsx b/types/react-native-modalbox/react-native-modalbox-tests.tsx new file mode 100644 index 0000000000..01a937aea7 --- /dev/null +++ b/types/react-native-modalbox/react-native-modalbox-tests.tsx @@ -0,0 +1,155 @@ +// Test taken from project repo https://github.com/maxs15/react-native-modalbox/blob/master/Example/index.ios.js + +import * as React from 'react'; +import Modal from 'react-native-modalbox'; +import Button from 'react-native-button'; +import Slider from 'react-native-slider'; + +import { + Text, + StyleSheet, + ScrollView, + View, + Dimensions +} from 'react-native'; + +interface State { + isOpen: boolean; + isDisabled: boolean; + swipeToClose: boolean; + slideValue: boolean; +} + +class Example extends React.Component<{}, State> { + constructor() { + super(); + + this.state = { + isOpen: false, + isDisabled: false, + swipeToClose: true, + sliderValue: 0.3 + }; + } + + onClose() { + console.log('Modal just closed'); + } + + onOpen() { + console.log('Modal just openned'); + } + + onClosingState(state) { + console.log('the open/close of the swipeToClose just changed'); + } + + renderList() { + const list = []; + + for (let i = 0; i < 50; i++) { + list.push(Elem {i}); + } + + return list; + } + + render() { + var BContent = ; + + return ( + + + + + + + + + + Basic modal + + + + + Modal on top + + + + Modal centered + + + + + Modal on bottom with backdrop + this.setState({ sliderValue: value })} /> + + + this.setState({ isOpen: false })} style={[styles.modal, styles.modal4]} position={"center"} backdropContent={BContent}> + Modal with backdrop content + + + + + + {this.renderList()} + + + + + ); + } +} + +const styles = StyleSheet.create({ + wrapper: { + paddingTop: 50, + flex: 1 + }, + + modal: { + justifyContent: 'center', + alignItems: 'center' + }, + + modal2: { + height: 230, + backgroundColor: "#3B5998" + }, + + modal3: { + height: 300, + width: 300 + }, + + modal4: { + height: 300 + }, + + btn: { + margin: 10, + backgroundColor: "#3B5998", + color: "white", + padding: 10 + }, + + btnModal: { + position: "absolute", + top: 0, + right: 0, + width: 50, + height: 50, + backgroundColor: "transparent" + }, + + text: { + color: "black", + fontSize: 22 + } +}); diff --git a/types/react-native-modalbox/tsconfig.json b/types/react-native-modalbox/tsconfig.json new file mode 100644 index 0000000000..d9e48e4d6a --- /dev/null +++ b/types/react-native-modalbox/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-native-drawer-tests.tsx" + ] +} diff --git a/types/react-native-modalbox/tslint.json b/types/react-native-modalbox/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-modalbox/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }