react-native-share-image
v1.1.1
Published
Grab and share screenshots, as well as share images using their content uri
Downloads
9
Maintainers
Readme
react-native-share-image
Table of Contents
Installation
$ npm install react-native-share-image --save
Android
- Create
filepaths.xml
atandroid/app/src/main/res/xml/filepaths.xml
(if it does not already exist) - Add below to filepaths.xml:
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="myexternalimages" path="Download/" /> <root-path name="root" path="." /> <external-path name="external_files" path="."/> <external-files-path name="external_files" path="." /> </paths>
- Navigate to your app
AndroidManifest.xml
(checkandroid/app/src/main/AndroidManifest.xml
) and add<provider>
like below:<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/AppTheme"> <provider android:name="androidx.core.content.FileProvider" android:authorities="com.yourAppID.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths"/> </provider>
- If React Native version >= 0.60 you're good to go! react-native-share-image is auto-linked and set up!
If package is not auto-linked
$ react-native link react-native-share-image
If linking does not work still
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.toluthomas.RNShareImagePackage;
to the imports at the top of the file - Add
new RNShareImagePackage()
to the list returned by thegetPackages()
method - Append the following lines to
android/settings.gradle
:include ':react-native-share-image' project(':react-native-share-image').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share-image/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-share-image')
iOS
Will be updated when iOS is supported ...
API
| Method | Return Type | iOS | Android |
| ----------------------------------------------------------------- | ------------- | :--: | :-----: |
| shareScreenshot() | void
| ❌ | ✅ |
| shareImageFromUri() | void
| ❌ | ✅ |
shareScreenshot()
import {shareScreenshot} from 'react-native-share-image';
// To take screenshot and share
shareScreenshot(); // Shares whole screen
shareScreenshot('nativeID'); // Shares view with nativeID
shareScreenshot(null, 'customMessage'); // Shares screenshot with a message that shows when user shares image
shareScreenshot(null, null, 'filename'); // Shares screenshot with a specific filename
shareScreenshot(null, null, null, 'customTitle'); // Shares screenshot with a specific title
shareImageFromUri()
import {shareImageFromUri} from 'react-native-share-image';
// To share image URI
shareImageFromUri('imageURI'); // Shares image of specified imageURI
shareImageFromUri('imageURI', 'customMessage'); // Shares image with a message that shows when user shares image
shareImageFromUri('imageURI', null, 'customTitle'); // Shares image with a specific title