Cross-platform sharing functionality for React-Native.
This results in a single interface for sharing across the supported platforms:
- Android, with sharing functionality provided via a native module.
- iOS, with sharing functionality provided by ActionSheetIOS (part of react-native).
- There is no official support for cross platform sharing
- There is no official support for Android sharing
- iOS has official support in the form of ActionSheetIOS
- Other GitHub librares make you conform to different interfaces for different platforms, or reinvent functionality already given to you by ActionSheetIOS
It provides two different ways to trigger sharing functionality:
-
Calling the
sharefunction directly -
Wrapping the views you want to trigger sharing on touch with
<ShareLink>. This will automatically trigger the sharing functionality when any of it's child views are touched.
Both ways of using this library have the same parameters:
-
Subject (required) - Shown above the sharing options and used in emails as the subject.
-
Message (required) - The message that will be shared.
-
URL (optional) - A link that will be added to the end of the message and used to help display more relevant sharing options.
-
Import the
sharefunction:import { share } from 'react-native-sharing'; -
Then call the
sharefunction and pass in the parameters:share(subject, message, url)
-
Import the
ShareLinkview component:import { ShareLink } from 'react-native-sharing'; -
Wrap the views you want to trigger sharing in a
ShareLinkand add the parameters:<ShareLink subject="Do you know 3SC?" message="Check out 3SC" url="https://3sidedcube.com/"> <Text>Tell your friends about 3 Sided Cube</Text> </ShareLink>
-
Ensure your launch activity extends from
ReactActivitylike so:public class MainActivity extends ReactActivity { -
Import
SharerPackagein your launch activity.import com.reactnativesharing.SharerPackage; -
Implement
getPackages()in your launch activity so thatSharerPackageis returned in your list of packages:@Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new SharerPackage() ); } -
Include
react-native-sharingin yourandroid/settings.gradlefile:include ':react-native-sharing' -
Reference the
react-native-sharingproject in yourandroid/settings.gradlefile:project(':react-native-sharing').projectDir = new File(rootProject.projectDir, '../ node_modules/react-native-sharing/android/app') -
Tell gradle to compile
react-native-sharinginandroid/app/build.gradlecompile project(":react-native-sharing")
- No setup needed, it just works (because we're using ActionSheetIOS).