id | title |
---|---|
install |
Installing |
If you are using react-native >= 0.60
you just need to do a simple:
yarn add react-native-share
Or if are using npm:
npm i react-native-share --save
After that, we need to install the dependencies to use the project on iOS(you can skip this part, if you are using this on Android).
Now run a simple: npx pod-install
or cd ios && pod install
. After that, you should be able to use the library on both Platforms, iOS and Android.
Also, to use this library on iOS you will need:
- XCode 11 or higher
- iOS 13 SDK or higher
After that, you will see that the library is now available at your node_modules
.
If the auto-linking doesn't work for any reason, you can still run a:
react-native link react-native-share
yarn add react-native-share
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-share
➜ios
and addRNShare.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNShare.a
to your project'sBuild Phases
➜Link Binary With Libraries
- In XCode, in the project navigator, select your project. Add
Social.framework
andMessageUI.framework
to your project'sGeneral
➜Linked Frameworks and Libraries
- Run your project (
Cmd+R
)
-
yarn add react-native-share
-
Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import cl.json.RNSharePackage;
andimport cl.json.ShareApplication;
to the imports at the top of the file - Add
new RNSharePackage()
to the list returned by thegetPackages()
method
- Add
-
Append the following lines to
android/settings.gradle
:include ':react-native-share' project(':react-native-share').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share/android')
-
Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-share')
-
(Optional) Follow this for implementing Provider
yarn add react-native-share
- In Visual Studio add the
RNShare.sln
innode_modules/react-native-share/windows/RNShare.sln
folder to their solution, reference from their app. - Open up your
MainPage.cs
app
- Add
using Cl.Json.RNShare;
to the usings at the top of the file - Add
new RNSharePackage()
to theList<IReactPackage>
returned by thePackages
method
Follow this to implement your FileProvider
. If you have any doubt please you found more about that here
-
applicationId
should be defined in thedefaultConfig
section in yourandroid/app/build.gradle
: -
File:
android/app/build.gradle
defaultConfig { applicationId "com.yourcompany.yourappname" ... }
-
Add this
<provider>
section to yourAndroidManifest.xml
File:
AndroidManifest.xml
<application> <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:grantUriPermissions="true" android:exported="false"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths" /> </provider> </application>
-
Create a
filepaths.xml
under this directory:android/app/src/main/res/xml
.In this file, add the following contents:
File:
android/app/src/main/res/xml/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/" /> </paths>
-
Edit your
MainApplication.java
class to addimplements ShareApplication
andgetFileProviderAuthority
-
The
getFileProviderAuthority
function returns theandroid:authorities
value added in theAndroidManifest.xml
file -
applicationId
is defined in thedefaultConfig
section of yourandroid/app/build.gradle
and referenced usingBuildConfig.APPLICATION_ID
import cl.json.ShareApplication public class MainApplication extends Application implements ShareApplication, ReactApplication { @Override public String getFileProviderAuthority() { return BuildConfig.APPLICATION_ID + ".provider"; } // ...Your own code }
If you need to use a older version of react-native < 0.60
, then you will need to run a:
yarn add react-native-share@version
Or with npm:
npm i react-native-share@version --save
You can look at all versions, that we published here.
If you can't update your project to the most recent version of both react-native and react-native-share, please use 1.2.1
. Alternatively you can use jetifier running a npx jetify -r
.