Expo Sharing iconExpo Sharing

A library that provides implementing sharing files.

Android
iOS
Web
Included in Expo Go
Bundled version:
~14.0.8

expo-sharing allows you to share files directly with other compatible applications.

Sharing limitations on web

  • expo-sharing for web is built on top of the Web Share API, which still has very limited browser support. Be sure to check that the API can be used before calling it by using Sharing.isAvailableAsync().
  • HTTPS required on web: The Web Share API is only available on web when the page is served over https. Run your app with npx expo start --tunnel to enable it.
  • No local file sharing on web: Sharing local files by URI works on Android and iOS, but not on web. You cannot share local files on web by URI — you will need to upload them somewhere and share that URI.

Sharing to your app from other apps

Currently expo-sharing only supports sharing from your app to other apps and you cannot register to your app to have content shared to it through the native share dialog on native platforms. You can read more in the related feature request. You can setup this functionality manually in Xcode and Android Studio and create an Expo Config Plugin to continue using Expo Prebuild.

Installation

Terminal
npx expo install expo-sharing

If you are installing this in an existing React Native app, make sure to install expo in your project.

API

import * as Sharing from 'expo-sharing';

Hooks

useIncomingShare()

Android
iOS
Web

Hook, which returns the data shared with the application and updates the data if the shared payload has changed.

Methods

Sharing.clearSharedPayloads()

Android
iOS
Web

Clears the data shared with the app.

Returns:
void

Sharing.getResolvedSharedPayloadsAsync()

Experimental
 • 
Android
iOS

Returns resolved data shared with the app. Compared to data returned from getSharedPayloads contains additional information useful for reading and displaying the data. For example, when a web URL is shared with the app, a resolved payload will contain additional information about the URL contents.

Depending on what has been shared, this method may require a network connection to resolve content details.

Returns:
Promise<ResolvedSharePayload[]>

Sharing.getSharedPayloads()

Experimental
 • 
Android
iOS

Returns raw data shared with the app. Returns an empty array if no data has been shared with the app.

Returns:
SharePayload[]

Sharing.isAvailableAsync()

Android
iOS
Web

Determine if the sharing API can be used in this app.

Returns:
Promise<boolean>

A promise that fulfills with true if the sharing API can be used, and false otherwise.

Sharing.shareAsync(url, options)

Android
iOS
Web
ParameterTypeDescription
urlstring

Local file URL to share.

options(optional)SharingOptions

A map of share options.

Default:{}

Opens action sheet to share file to different applications which can handle this type of file.

Returns:
Promise<void>

Types

ActivationRuleOptions

iOS

Describes a configuration for data types that are possible to share in the application on iOS.

PropertyTypeDescription
supportsAttachmentsWithMaxCount(optional)number

Determines a maximum number of attachments that can be shared with the app. When 0 the app will not accept attachment shares.

Default:0
supportsFileWithMaxCount(optional)number

Determines a maximum number of files that can be shared with the app. When 0 the app will not accept file shares.

Default:0
supportsImageWithMaxCount(optional)number

Determines a maximum number of images that can be shared with the app. When 0 the app will not accept shared images.

Default:0
supportsMovieWithMaxCount(optional)number

Determines a maximum number of videos that can be shared with the app. When 0 the app will not accept video shares.

Default:0
supportsText(optional)boolean

Whether the app should accept shared text.

Default:false
supportsWebPageWithMaxCount(optional)number

Determines a maximum number of webpages that can be shared with the app. When 0 the app will not accept webpage shares.

Default:0
supportsWebUrlWithMaxCount(optional)number

Determines a maximum number of web URLs that can be shared with the app. When 0 the app will not accept web URL shares.

Default:0

BaseResolvedSharePayload

Android
iOS
Web

Type: SharePayload extended by:

PropertyTypeDescription
contentMimeTypestring | null

Mime type of the content accessible via the contentUri.

contentSizenumber | null

Size of the content accessible via the contentUri.

contentTypeContentType | null

Type of the content accessible via the contentUri.

contentUristring | null

URI which can be used to access the shared content. When resolving contents of a URL with redirects, contains the redirect target URI. Null when resolving a SharePayload with a text ShareType.

originalNamestring | null

If applicable, value of the suggestedFilename HTTP header field, otherwise the last path component of the contentUri field.

ContentType

Experimental
 • 
Android
iOS

Literal Type: string

Describes the resolved content type.

Acceptable values are: 'text' | 'audio' | 'image' | 'video' | 'file' | 'website'

ResolvedSharePayload

Experimental
 • 
Android
iOS

Literal Type: union

Represents a payload shared with the app, with additional information about the shared contents.

Acceptable values are: UriBasedResolvedSharePayload | TextBasedResolvedSharePayload

SharePayload

Experimental
 • 
Android
iOS

Represents raw data shared with the app.

PropertyTypeDescription
mimeType(optional)string

The MIME type of the contents of thevalue field.

Default:'text/plain'
shareType(optional)ShareType

The type of the shared content.

Default:'text'
value(optional)string

The primary value of the content.

  • For text, this is the message body.
  • For url, this is the URL string.
  • For file, image, video, or audio, this is typically the file URI.
Default:""

ShareType

Experimental
 • 
Android
iOS

Literal Type: string

Determines the type of content being shared.

  • text: Plain text content.
  • url: A specific URL.
  • audio: An audio file.
  • image: An image file.
  • video: A video file.
  • file: A generic file.

Acceptable values are: 'text' | 'url' | 'audio' | 'image' | 'video' | 'file'

SharingOptions

Android
iOS
Web
PropertyTypeDescription
anchor(optional){ height: number, width: number, x: number, y: number }
Only for:
iOS

Sets the anchor point for iPad

dialogTitle(optional)string
Only for:
Android
Web

Sets share dialog title.

mimeType(optional)string
Only for:
Android

Sets mimeType for Intent.

UTI(optional)string
Only for:
iOS

Uniform Type Identifier

  • the type of the target file.

TextBasedResolvedSharePayload

Experimental
 • 
Android
iOS

Represents a resolved payload, where a text was shared with the app.

Type: BaseResolvedSharePayload extended by:

PropertyTypeDescription
contentType(optional)'text'
-

UriBasedResolvedSharePayload

Experimental
 • 
Android
iOS

Represents a resolved payload, for which the data can be accessed through a URI.

Type: BaseResolvedSharePayload extended by:

PropertyTypeDescription
contentType'audio' | 'file' | 'video' | 'image' | 'website'
-
contentUristring
-

UseIncomingShareResult

Experimental
 • 
Android
iOS

Object returned by useIncomingShare hook containing information about data shared with the app.

PropertyTypeDescription
clearSharedPayloads() => void

Clears payloads shared with the app.

errorError | null

Contains an error encountered while resolving the shared payload. Null on success.

isResolvingboolean

Boolean indicating whether the current shared payloads are being resolved.

refreshSharePayloads() => void

Forces a refresh of the shared payloads.

resolvedSharedPayloadsResolvedSharePayload[]

Contains an array of resolved payloads shared with the app. Returns an empty array if the shared payloads are being resolved or if the resolving has failed.

sharedPayloadsSharePayload[]

Returns unresolved payloads shared with the app. Synchronous and available immediately after creating the hook.