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.
This commit is contained in:
Haseeb Majid
2020-01-02 23:56:33 +00:00
committed by Ryan Cavanaugh
parent bf8cc8a772
commit 5eeffbdb87
4 changed files with 82 additions and 0 deletions

View File

@@ -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 <https://github.com/hmajid230>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface ShareData {
value: string;
type: 'text/plain' | 'images/*';
}
interface ShareExtension {
close(): void;
data(): Promise<ShareData>;
openURL(uri: string): void;
}
declare const RNShareExtension: ShareExtension;
export default RNShareExtension;

View File

@@ -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 (
<View style={{ alignItems: 'center', justifyContent: 'center', flex: 1 }}>
<View
style={{ borderColor: 'green', borderWidth: 1, backgroundColor: 'white', height: 200, width: 300 }}
>
<Text>type: {this.state.type}</Text>
<Text>value: {this.state.value}</Text>
</View>
</View>
);
}
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }