Added sharedAction example to Share API (#30333)

Summary:
* Added an example for `sharedAction` and `dismissedAction` in Share API examples

**Motivation** - Missing example for `sharedAction` in examples

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Added] - Added an example in ShareExample.js

Pull Request resolved: https://github.com/facebook/react-native/pull/30333

Test Plan:
* Tested on Android

![sharedAction](https://user-images.githubusercontent.com/26821140/98447958-ed758600-214e-11eb-8a50-67ad5dcebea5.png)

Reviewed By: cpojer

Differential Revision: D25246375

Pulled By: rickhanlonii

fbshipit-source-id: f0d25a04c77ba02c9bea07aceccbfb65b2aa67e9
This commit is contained in:
Kshitij Kotasthane 2021-01-08 12:39:23 -08:00 коммит произвёл Facebook GitHub Bot
Родитель a724c8d95e
Коммит 835117aba3
2 изменённых файлов: 47 добавлений и 1 удалений

Просмотреть файл

@ -177,7 +177,7 @@ class ScrollViewStickyHeader extends React.Component<Props, State> {
// Fabric Detection
// eslint-disable-next-line dot-notation
const isFabric = !!(
this._ref && this._ref['_internalInstanceHandle']?.stateNode?.canonical
this._ref && this._ref._internalInstanceHandle?.stateNode?.canonical
);
// Initially and in the case of updated props or layout, we

Просмотреть файл

@ -76,6 +76,46 @@ const ShareMessageWithTitle = () => {
);
};
const SharedAction = () => {
const [shared, setShared] = React.useState();
const sharedAction = async () => {
try {
const result = await Share.share(
{
title: 'Create native apps',
message: ('React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces.': string),
url: 'https://reactnative.dev/',
},
{
subject: 'MUST READ: Create native apps with React Native',
dialogTitle: 'Share React Native Home Page',
tintColor: 'blue',
},
);
if (result.action === Share.sharedAction) {
setShared(result.action);
} else if (result.action === Share.dismissedAction) {
//iOS only, if dialog was dismissed
setShared(null);
}
} catch (e) {
console.error(e);
}
};
return (
<View style={styles.container}>
<Text>action: {shared ? shared : 'null'}</Text>
<Text style={styles.title}>Create native apps</Text>
<Text>
React Native combines the best parts of native development with React, a
best-in-class JavaScript library for building user interfaces.
</Text>
<Button title="SHARE" onPress={sharedAction} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
@ -104,4 +144,10 @@ exports.examples = [
return <ShareMessageWithTitle />;
},
},
{
title: 'sharedAction: If the content was successfully shared',
render(): React.Node {
return <SharedAction />;
},
},
];