From 5eeffbdb8718aeb9e7ce66303d38ad3f17baefac Mon Sep 17 00:00:00 2001 From: Haseeb Majid Date: Thu, 2 Jan 2020 23:56:33 +0000 Subject: [PATCH] Added react-native-share-extension (#41306) * Added React Native Share Extension * Fixed Linting Issues Fixed linting issues, added tests. * Fixed other linting issues Data returns a promise. * Removed Public from state Removed public from state. --- types/react-native-share-extension/index.d.ts | 18 +++++++++ .../react-native-share-extension-tests.tsx | 39 +++++++++++++++++++ .../tsconfig.json | 24 ++++++++++++ .../react-native-share-extension/tslint.json | 1 + 4 files changed, 82 insertions(+) create mode 100644 types/react-native-share-extension/index.d.ts create mode 100644 types/react-native-share-extension/react-native-share-extension-tests.tsx create mode 100644 types/react-native-share-extension/tsconfig.json create mode 100644 types/react-native-share-extension/tslint.json 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" }