Documentation

Hey friend! We are co-hosting a conference with Software Mansion, learn more.

Share


Reference


static share(content, options)

Open a dialog to share text content.
In iOS, Returns a Promise which will be invoked an object containing action, 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.
In Android, Returns a Promise which always be resolved with action being Share.sharedAction.

  • message - a message to share
  • title - title of the message

  • url - an URL to share
At least one of URL and message is required.

  • subject - a subject to share via email
  • excludedActivityTypes
  • tintColor

  • dialogTitle


static sharedAction()

The content was successfully shared.


static dismissedAction()

iOS Only. The dialog has been dismissed.


import React, {Component} from 'react'
import {Share, Button} from 'react-native'

class ShareExample extends Component {

  async onShare = () => {
    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);
    }
  };

  render() {
    return (
      <Button onPress={this.onShare}>Share</Button>
    );
  }

}