diff --git a/types/react-native-share-extension/index.d.ts b/types/react-native-share-extension/index.d.ts new file mode 100644 index 0000000000..004d477e9b --- /dev/null +++ b/types/react-native-share-extension/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for react-native-share-extension 2.0 +// Project: https://github.com/alinz/react-native-share-extension +// Definitions by: Haseeb Majid +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface ShareData { + value: string; + type: 'text/plain' | 'images/*'; +} + +interface ShareExtension { + close(): void; + data(): Promise; + openURL(uri: string): void; +} + +declare const RNShareExtension: ShareExtension; +export default RNShareExtension; diff --git a/types/react-native-share-extension/react-native-share-extension-tests.tsx b/types/react-native-share-extension/react-native-share-extension-tests.tsx new file mode 100644 index 0000000000..d1814d28ca --- /dev/null +++ b/types/react-native-share-extension/react-native-share-extension-tests.tsx @@ -0,0 +1,39 @@ +import * as React from 'react'; +import ShareExtension from 'react-native-share-extension'; + +import { Text, View } from 'react-native'; + +export default class Share extends React.Component { + state = { + type: '', + value: '', + }; + + async componentDidMount() { + try { + const { type, value } = await ShareExtension.data(); + await ShareExtension.data(); + ShareExtension.openURL('sample://example/url'); + ShareExtension.close(); + this.setState({ + type, + value, + }); + } catch (e) { + console.log('errrr', e); + } + } + + render() { + return ( + + + type: {this.state.type} + value: {this.state.value} + + + ); + } +} diff --git a/types/react-native-share-extension/tsconfig.json b/types/react-native-share-extension/tsconfig.json new file mode 100644 index 0000000000..96ae3aed46 --- /dev/null +++ b/types/react-native-share-extension/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react-native" + }, + "files": [ + "index.d.ts", + "react-native-share-extension-tests.tsx" + ] +} diff --git a/types/react-native-share-extension/tslint.json b/types/react-native-share-extension/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-share-extension/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }