Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sharedAction example to Share API #30333

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Libraries/Components/ScrollView/ScrollViewStickyHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we revert this?

);

// Initially and in the case of updated props or layout, we
Expand Down
46 changes: 46 additions & 0 deletions packages/rn-tester/js/examples/Share/ShareExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -104,4 +144,10 @@ exports.examples = [
return <ShareMessageWithTitle />;
},
},
{
title: 'sharedAction: If the content was successfully shared',
render(): React.Node {
return <SharedAction />;
},
},
];