Documentation Index
Fetch the complete documentation index at: https://mintlify.com/facebook/react-native/llms.txt
Use this file to discover all available pages before exploring further.
The Share API allows you to share text content and URLs using the native share dialog on both iOS and Android.
Methods
share()
static share(
content: ShareContent,
options?: ShareOptions
): Promise<ShareAction>
Opens a dialog to share text content.
Content Parameter:
The content object must contain at least one of url or message:
url (string, required on iOS): A URL to share
message (string, required on Android): A message to share (often includes a URL)
title (string, Android only): Title of the message
Options Parameter:
-
iOS:
subject (string): Subject to share via email
excludedActivityTypes (string[]): Activities to exclude from the share sheet
tintColor (ColorValue): Tint color of the share sheet
anchor (number): iPad only - anchor point for the popover
-
Android:
dialogTitle (string): Title of the share dialog
Returns:
A Promise that resolves to an object with:
action (string): Either Share.sharedAction or Share.dismissedAction (iOS only)
activityType (string | null): The activity type that was used to share (iOS only)
Example:
import { Share } from 'react-native';
const shareContent = async () => {
try {
const result = await Share.share({
message: 'Check out this awesome app!',
url: 'https://example.com',
title: 'Amazing App'
});
if (result.action === Share.sharedAction) {
if (result.activityType) {
console.log('Shared with activity type:', result.activityType);
} else {
console.log('Content was shared');
}
} else if (result.action === Share.dismissedAction) {
console.log('Share dialog was dismissed');
}
} catch (error) {
console.error('Error sharing:', error.message);
}
};
iOS Example with Options:
import { Share } from 'react-native';
const shareWithOptions = async () => {
try {
await Share.share(
{
message: 'Great content to share',
url: 'https://example.com'
},
{
subject: 'Email Subject',
excludedActivityTypes: [
'com.apple.UIKit.activity.PostToFacebook'
],
tintColor: '#0000ff'
}
);
} catch (error) {
console.error(error);
}
};
Android Example:
import { Share } from 'react-native';
const shareOnAndroid = async () => {
try {
await Share.share(
{
message: 'Check this out: https://example.com',
title: 'Awesome Content'
},
{
dialogTitle: 'Share this content'
}
);
} catch (error) {
console.error(error);
}
};
Constants
Share.sharedAction
The content was successfully shared.
if (result.action === Share.sharedAction) {
// User shared the content
}
Share.dismissedAction
iOS only - The share dialog was dismissed without sharing.
if (result.action === Share.dismissedAction) {
// User dismissed the share dialog
}
iOS
- Returns a Promise that resolves with
action and activityType
- If dismissed, the Promise still resolves with
action being Share.dismissedAction
- At least one of
url or message is required
- The
subject option is used for email sharing
Android
- Returns a Promise that always resolves with
action being Share.sharedAction
activityType is always null
- The
message field is required and often includes the URL
- Uses Android’s native share intent
Type Definitions
type ShareContent = {
title?: string;
url?: string;
message: string;
} | {
title?: string;
url: string;
message?: string;
}
type ShareOptions = {
dialogTitle?: string; // Android
excludedActivityTypes?: string[]; // iOS
tintColor?: ColorValue; // iOS
subject?: string; // iOS
anchor?: number; // iOS (iPad)
}
type ShareAction = {
action: 'sharedAction' | 'dismissedAction';
activityType?: string | null;
}