Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-share

Package Overview
Dependencies
Maintainers
5
Versions
157
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-share - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

android/src/main/java/cl/json/RNShareFileProvider.java

2

changelog.js

@@ -11,3 +11,3 @@ #!/usr/bin/env node

const currentChangelog = fs.readFileSync('./CHANGELOG.md');
const matched = tags.latest != null ? tags.latest.match(/v\d+.\d+.\d+-(\d+)/) : 'v0.0.1-0';
const matched = tags.latest.match(/v\d+.\d+.\d+-(\d+)/);
const build = (idx(matched, _ => Number(_[1])) || 0) + 1;

@@ -14,0 +14,0 @@

@@ -0,1 +1,20 @@

### 1.2.0-4 (2019-05-26)
##### Build System / Dependencies
* fix all deprecation and lint in ShareFile(s) ([#374](https://github.com/react-native-community/react-native-share/pull/374)) ([67fb59e9](https://github.com/react-native-community/react-native-share/commit/67fb59e9dc7ec9f98ad76f6809dbc98d240c451e))
##### Chores
* **npmignore:**
* add .github folder to npmignore ([fc219481](https://github.com/react-native-community/react-native-share/commit/fc2194818c7dba4dd913dd5c65564113ef575a6a))
* add changelog.js ([8256431b](https://github.com/react-native-community/react-native-share/commit/8256431be2526a55b625b72f4727d8dd8af20aee))
* **changelog:** update changelog.js ([85a91b05](https://github.com/react-native-community/react-native-share/commit/85a91b05993eaaf5e897815029bf58d0944ed3cb))
* Adding instructions about how use the master branch ([c1c58b87](https://github.com/react-native-community/react-native-share/commit/c1c58b876b718bce033593ad52e7fc62fdb32065))
* update iOS target to 9.0 to match react-native min version ([f72dbe1a](https://github.com/react-native-community/react-native-share/commit/f72dbe1a44105a0d04f3af03a7556ea123024493))
##### New Features
* **deps:** update deps and prepare for release ([#501](https://github.com/react-native-community/react-native-share/pull/501)) ([05c2b6a1](https://github.com/react-native-community/react-native-share/commit/05c2b6a1aeb74853ef16265f690b3ba48cd0198f))
#### 1.1.3-3 (2018-10-23)

@@ -2,0 +21,0 @@

@@ -1,2 +0,7 @@

// @flow
/*
*
* @format
* @flow
*
*/

@@ -39,4 +44,8 @@ import * as React from 'react';

children: React.Node,
style?: {},
overlayStyle?: {},
};
const shareSheetStyle = {flex: 1};
class ShareSheet extends React.Component<Props> {

@@ -62,8 +71,14 @@ backButtonHandler: () => boolean;

render() {
const {style = {}, overlayStyle = {}, ...props} = this.props;
return (
<Overlay visible={this.props.visible} {...this.props}>
<View style={styles.actionSheetContainer}>
<TouchableOpacity style={{ flex: 1 }} onPress={this.props.onCancel} />
<Overlay visible={this.props.visible} {...props}>
<View style={[styles.actionSheetContainer, overlayStyle]}>
<TouchableOpacity
style={shareSheetStyle}
onPress={this.props.onCancel}
/>
<Sheet visible={this.props.visible}>
<View style={styles.buttonContainer}>{this.props.children}</View>
<View style={[styles.buttonContainer, style]}>
{this.props.children}
</View>
</Sheet>

@@ -99,6 +114,8 @@ </View>

type OpenReturn = { app?: string, dismissedAction?: boolean };
type ShareSingleReturn = { message: string };
type OpenReturn = {app?: string, dismissedAction?: boolean};
type ShareSingleReturn = {message: string};
const requireAndAskPermissions = async (options: Options | MultipleOptions): Promise<any> => {
const requireAndAskPermissions = async (
options: Options | MultipleOptions,
): Promise<any> => {
if ((options.url || options.urls) && Platform.OS === 'android') {

@@ -150,3 +167,3 @@ const urls: Array<string> = options.urls || [options.url];

static Button: any;
static ShareSheet: React.createElement;
static ShareSheet: React.Element<*>;
static Overlay: any;

@@ -160,2 +177,4 @@ static Sheet: any;

INSTAGRAM: NativeModules.RNShare.INSTAGRAM || 'instagram',
INSTAGRAM_STORIES:
NativeModules.RNShare.INSTAGRAM_STORIES || 'instagram-stories',
GOOGLEPLUS: NativeModules.RNShare.GOOGLEPLUS || 'googleplus',

@@ -166,2 +185,12 @@ EMAIL: NativeModules.RNShare.EMAIL || 'email',

static InstagramStories = {
SHARE_BACKGROUND_IMAGE:
NativeModules.RNShare.SHARE_BACKGROUND_IMAGE || 'shareBackgroundImage',
SHARE_STICKER_IMAGE:
NativeModules.RNShare.SHARE_STICKER_IMAGE || 'shareStickerImage',
SHARE_BACKGROUND_AND_STICKER_IMAGE:
NativeModules.RNShare.SHARE_BACKGROUND_AND_STICKER_IMAGE ||
'shareBackgroundAndStickerImage',
};
static open(options: Options | MultipleOptions): Promise<OpenReturn> {

@@ -171,46 +200,23 @@ return new Promise((resolve, reject) => {

.then(() => {
if (Platform.OS === 'ios') {
if (options.urls) {
// Handle for multiple file share
NativeModules.RNShare.open(
options,
error => {
return reject({ error: error });
},
(success, activityType) => {
if (success) {
return resolve({
app: activityType,
});
} else if (options.failOnCancel === false) {
return resolve({
dismissedAction: true,
});
} else {
reject({ error: 'User did not share' });
}
},
);
} else {
// Handle for single file share
ActionSheetIOS.showShareActionSheetWithOptions(
options,
error => {
return reject({ error: error });
},
(success, activityType) => {
if (success) {
return resolve({
app: activityType,
});
} else if (options.failOnCancel === false) {
return resolve({
dismissedAction: true,
});
} else {
reject({ error: 'User did not share' });
}
},
);
}
if (Platform.OS === 'ios' && !options.urls) {
// Handle for single file share
ActionSheetIOS.showShareActionSheetWithOptions(
options,
error => {
return reject({error: error});
},
(success, activityType) => {
if (success) {
return resolve({
app: activityType,
});
} else if (options.failOnCancel === false) {
return resolve({
dismissedAction: true,
});
} else {
reject(new Error('User did not share'));
}
},
);
} else {

@@ -220,8 +226,17 @@ NativeModules.RNShare.open(

e => {
return reject({ error: e });
return reject({error: e});
},
e => {
resolve({
message: e,
});
(success, activityType) => {
if (success) {
return resolve({
app: activityType,
message: activityType,
});
} else if (options.failOnCancel === false) {
return resolve({
dismissedAction: true,
});
} else {
reject(new Error('User did not share'));
}
},

@@ -243,7 +258,8 @@ );

e => {
return reject({ error: e });
return reject({error: e});
},
e => {
(e, activityType) => {
return resolve({
message: e,
app: activityType,
});

@@ -259,2 +275,23 @@ },

}
static isPackageInstalled(packageName: string): Promise<ShareSingleReturn> {
if (Platform.OS === 'android') {
return new Promise((resolve, reject) => {
NativeModules.RNShare.isPackageInstalled(
packageName,
e => {
return reject({error: e});
},
isInstalled => {
return resolve({
isInstalled: isInstalled,
message: 'Package is Installed',
});
},
);
});
} else {
throw new Error('Not implemented');
}
}
}

@@ -261,0 +298,0 @@

{
"name": "react-native-share",
"description": "Social share, sending simple data to other apps.",
"version": "1.1.3",
"version": "1.2.0",
"repository": {

@@ -10,20 +10,22 @@ "type": "git",

"devDependencies": {
"@commitlint/cli": "^6.1.0",
"@commitlint/config-conventional": "^6.1.0",
"babel-eslint": "^8.2.1",
"eslint": "^4.17.0",
"eslint-plugin-flowtype": "^2.46.2",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-react": "^7.6.1",
"eslint-plugin-react-native": "^3.2.0",
"flow-bin": "^0.77.0",
"generate-changelog": "1.7.0",
"husky": "^0.14.3",
"idx": "^2.4.0",
"lint-staged": "^7.0.0",
"@commitlint/cli": "6.2.0",
"@commitlint/config-conventional": "6.1.3",
"@react-native-community/eslint-config": "0.0.4",
"babel-eslint": "8.2.6",
"eslint": "4.19.1",
"eslint-plugin-flowtype": "2.50.3",
"eslint-plugin-import": "2.17.3",
"eslint-plugin-prettier": "2.6.2",
"eslint-plugin-react": "7.13.0",
"eslint-plugin-react-native": "3.7.0",
"flow-bin": "0.92.0",
"generate-changelog": "1.7.1",
"husky": "0.14.3",
"idx": "2.5.6",
"lint-staged": "7.3.0",
"minimist": "1.2.0",
"pre-commit": "^1.2.2",
"prettier": "^1.12.0",
"react": "16.3.1",
"react-native": "0.55.2",
"pre-commit": "1.2.2",
"prettier": "1.17.1",
"react": "16.8.3",
"react-native": "0.59.5",
"simple-git": "1.89.0"

@@ -45,3 +47,3 @@ },

},
"homepage": "https://github.com/react-native-community/react-native-share",
"homepage": "https://github.com/react-native-community/react-native-share#readme",
"license": "MIT",

@@ -59,3 +61,3 @@ "lint-staged": {

"commitmsg": "commitlint -e $GIT_PARAMS",
"lint": "eslint src --max-warnings=0",
"lint": "eslint index.js --max-warnings=0",
"lint:staged": "lint-staged",

@@ -62,0 +64,0 @@ "prettier": "prettier --write --single-quote true --trailing-comma all --print-width 100",

@@ -6,8 +6,23 @@ # react-native-share [![CircleCI](https://circleci.com/gh/react-native-community/react-native-share/tree/master.svg?style=svg&circle-token=0c6860240abba4e16bd07df0ea805a72b67b8d41)](https://circleci.com/gh/react-native-community/react-native-share/tree/master) [![npm version](https://badge.fury.io/js/react-native-share.svg)](http://badge.fury.io/js/react-native-share)

## Sponsors
If you use this library on your commercial/personal projects, you can help us by funding the work on specific issues that you choose by using IssueHunt.io!
This gives you the power to prioritize our work and support the project contributors. Moreover it'll guarantee the project will be updated and maintained in the long run.
[![issuehunt-image](https://issuehunt.io/static/embed/issuehunt-button-v1.svg)](https://issuehunt.io/repos/43406976)
## Getting started
### Mostly automatic install
1. `npm install react-native-share --save`
1. `yarn add react-native-share`
2. `react-native link react-native-share`
#### How to use master branch?
We recommend using the releases from npm, however you can use the master branch if you need any feature that is not available on NPM. By doing this you will be able to use unreleased features, but the module may be less stable.
**yarn**: `yarn add react-native-share@git+https://git@github.com/react-native-community/react-native-share.git`
**npm**: `npm install --save react-native-share@git+https://git@github.com/react-native-community/react-native-share.git`
### Manual install

@@ -31,3 +46,4 @@

5. In XCode, in the project navigator, select your project. Add `Social.framework` and `MessageUI.framework` to your project's `General` ➜ `Linked Frameworks and Libraries`
6. In file Info.plist, add
6. In iOS 9 or higher, You should add app list that you will share.
If you want to share Whatsapp and Mailto, you should write `LSApplicationQueriesSchemes` in info.plist
```xml

@@ -47,2 +63,21 @@ <key>LSApplicationQueriesSchemes</key>

#### iOS Install(using Pods)
If you wish, you can use [cocopoads](https://cocoapods.org/) to use react-native-share.
You just need to add to your Podfile the react-native-share dependency.
```ruby
# React-Native-Share pod
pod 'RNShare', :path => '../node_modules/react-native-share'
```
After that, just run a `pod install` or `pod udpate` to get up and running with react-native-share.
Then run a `react-native link react-native-share`, and doing the steps 6 and 7.
You can also see our example to see how you need to setup your podfile.
Btw, We also recommend reading this (amazing article)[https://shift.infinite.red/beginner-s-guide-to-using-cocoapods-with-react-native-46cb4d372995] about how pods and rn work together. =D
#### Android Install

@@ -52,5 +87,5 @@

2. Open up `android/app/src/main/java/[...]/MainApplication.java`
- Add `import cl.json.RNSharePackage;` and `import cl.json.ShareApplication;` to the imports at the top of the file
- Add `new RNSharePackage()` to the list returned by the `getPackages()`
method
- Add `import cl.json.RNSharePackage;` and `import cl.json.ShareApplication;` to the imports at the top of the file
- Add `new RNSharePackage()` to the list returned by the `getPackages()` method
3. Append the following lines to `android/settings.gradle`:

@@ -67,58 +102,4 @@ ```

```
5. Follow this
[guide](https://developer.android.com/training/secure-file-sharing/setup-sharing.html).
For example:
- Put this in `AndroidManifest.xml` where `applicationId` is something that
you have defined in `android/app/build.gradle`:
5. **(Optional)** [Follow this for implementing Provider](#adding-your-implementation-of-fileprovider)
```xml
<application>
<provider
android:name="android.support.v4.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:
```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>
```
6. Edit your `MainApplication` class to implement `ShareApplication`
- Also add the `getFileProviderAuthority` method to your MainApplication class,
and have it return the `android:authorities` that was added in
AndroidManifest file.
- For example: Replace the `com.example.yourappidhere` below with the
`applicationId` that is defined in your `android/app/build.gradle`. It must
be [hard-coded here to work
properly](https://github.com/EstebanFuentealba/react-native-share/issues/200#issuecomment-361938532).
```
import cl.json.ShareApplication
class MyApplication extends Application implements ShareApplication, ReactApplication {
{
//...
@Override
public String getFileProviderAuthority() {
return "com.example.yourappidhere.provider";
}
}
```
#### Windows Install

@@ -143,3 +124,3 @@

```javascript
```jsx
Share.open(options)

@@ -161,3 +142,3 @@ .then((res) => { console.log(res) })

| excludedActivityTypes | string | (optional) |
| failOnCancel | boolean | (defaults to true) On iOS, specifies whether promise should reject if user cancels share dialog (optional) |
| failOnCancel | boolean | (defaults to true) Specifies whether promise should reject if user cancels share dialog (optional) |
| showAppsToView | boolean | (optional) only android|

@@ -181,5 +162,19 @@

| social | string | supported social apps: [List](#static-values-for-social) |
| forceDialog | boolean | (optional) only android. Avoid showing dialog with buttons Just Once / Always. Useful for Instagram to always ask user if share as Story or Feed |
***NOTE: If both `message` and `url` are provided `url` will be concatenated to the end of `message` to form the body of the message. If only one is provided it will be used***
#### isPackageInstalled (in Android)
It's a method that checks if an app (package) is installed on Android.
It returns a promise with `isInstalled`. e.g.
Checking if Instagram is installed on Android.
```jsx
Share.isPackageInstalled('com.instagram.android')
.then(({ isInstalled }) => console.log(isInstalled))
```
***NOTE: in iOS you can use `Linking.canOpenURL(url)`***
### Static Values for social

@@ -194,2 +189,3 @@

title: 'Share via',
message: 'some message',
url: 'some share url',

@@ -207,7 +203,11 @@ social: Share.Social.WHATSAPP

| **INSTAGRAM** | yes | yes | no |
| **INSTAGRAM_STORIES** | no | yes | no |
| **GOOGLEPLUS** | yes | yes | no |
| **EMAIL** | yes | yes | no |
| **PINTEREST** | yes | no | no |
| **SMS** | yes | no | no |
| **SNAPCHAT** | yes | no | no |
| **MESSENGER** | yes | no | no |
## how it looks:
## How it looks:

@@ -473,3 +473,3 @@ | | Android | IOS | Windows |

```
```jsx
static sharePDFWithIOS(fileUrl, type) {

@@ -500,3 +500,3 @@ let filePath = null;

```
```jsx
static sharePDFWithAndroid(fileUrl, type) {

@@ -520,1 +520,100 @@ let filePath = null;

```
#### Static Values for Instagram Stories
These can be assessed using Share.Social property
For eg.
```javascript
import Share from 'react-native-share';
const shareOptions = {
method: Share.InstagramStories.SHARE_BACKGROUND_AND_STICKER_IMAGE,
backgroundImage: 'http://urlto.png',
stickerImage: 'data:image/png;base64,<imageInBase64>', //or you can use "data:" link
backgroundBottomColor: '#fefefe',
backgroundTopColor: '#906df4',
attributionURL: 'http://deep-link-to-app', //in beta
social: Share.Social.INSTAGRAM_STORIES
};
Share.shareSingle(shareOptions);
```
Supported options for INSTAGRAM_STORIES:
| Name | Type | Description |
| :---- | :------: | :--- |
| backgroundImage | string | URL you want to share |
| stickerImage | string | URL you want to share |
| method | string | [List](#instagram-stories-method-list) |
| backgroundBottomColor | string | (optional) default #837DF4 |
| backgroundTopColor | string | (optional) default #906df4 |
| attributionURL | string | (optional) facebook beta-test |
#### Instagram stories method list
| Name | Required options |
| :---- | :------: |
| **SHARE_BACKGROUND_IMAGE** | backgroundImage |
| **SHARE_STICKER_IMAGE** | stickerImage |
| **SHARE_BACKGROUND_AND_STICKER_IMAGE** | backgroundImage, stickerImage |
#### Adding your implementation of FileProvider
[Android guide](https://developer.android.com/training/secure-file-sharing/setup-sharing.html).
- `applicationId` should be defined in the `defaultConfig` section in your `android/app/build.gradle`:
- File: `android/app/build.gradle`
```
defaultConfig {
applicationId "com.yourcompany.yourappname"
...
}
```
- Add this `<provider>` section to your `AndroidManifest.xml`
File: `AndroidManifest.xml`
```xml
<application>
<provider
android:name="android.support.v4.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/filepaths.xml`
```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 add `implements ShareApplication` and `getFileProviderAuthority`
- The `getFileProviderAuthority` function returns the `android:authorities` value added in the `AndroidManifest.xml` file
- `applicationId` is defined in the `defaultConfig` section of your `android/app/build.gradle` and referenced using `BuildConfig.APPLICATION_ID`
```java
import cl.json.ShareApplication
public class MainApplication extends Application implements ShareApplication, ReactApplication {
@Override
public String getFileProviderAuthority() {
return BuildConfig.APPLICATION_ID + ".provider";
}
// ...Your own code
}
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc