import React from 'react'; import { Share, View, Button } from 'react-native'; const ShareExample = () => { const onShare = async () => { try { const result = await Share.share({ message: 'React Native | A framework for building native apps using React', }); if (result.action === Share.sharedAction) { if (result.activityType) { // shared with activity type of result.activityType } else { // shared } } else if (result.action === Share.dismissedAction) { // dismissed } } catch (error) { alert(error.message); } }; return ( <View style={{ marginTop: 50 }}> <Button onPress={onShare} title="Share" /> </View> ); }; export default ShareExample;
static share(content, options)
action
and activityType
. If the user dismissed the dialog, the Promise will still be resolved with action being Share.dismissedAction
and all the other keys being undefined. Note that some share options will not appear or work on the iOS simulator.Share.sharedAction
.Name | Type | Description |
---|---|---|
content (Required) | object | message - a message to shareurl - a URL to share (iOS)title - title of the message (Android)At least one of url and message is required. |
options | object | dialogTitle (Android)excludedActivityTypes (iOS)subject - a subject to share via email (iOS)tintColor (iOS) |
static sharedAction
static dismissedAction