react-native-share 7.3.0 → 7.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,16 @@
1
1
  package cl.json.social;
2
2
 
3
+ import android.app.Activity;
3
4
  import android.content.ActivityNotFoundException;
4
5
  import android.content.Intent;
5
- import java.io.File;
6
- import android.os.Environment;
7
6
  import android.net.Uri;
8
7
  import android.util.Log;
9
8
 
10
9
  import com.facebook.react.bridge.ReactApplicationContext;
11
10
  import com.facebook.react.bridge.ReadableMap;
12
11
 
12
+ import cl.json.ShareFile;
13
+
13
14
  /**
14
15
  * Created by Ralf Nieuwenhuizen on 10-04-17.
15
16
  */
@@ -24,17 +25,64 @@ public class InstagramShare extends SingleShareIntent {
24
25
 
25
26
  @Override
26
27
  public void open(ReadableMap options) throws ActivityNotFoundException {
27
- super.open(options);
28
- try {
29
- // passing instagram://share as url option opens Publishing screen with camera view
30
- if (ShareIntent.hasValidKey("url", options) && options.getString("url").startsWith("instagram://")) {
31
- this.getIntent().setAction(Intent.ACTION_VIEW);
32
- this.getIntent().setData(Uri.parse(options.getString("url")));
28
+ super.open(options);
29
+
30
+ if (!ShareIntent.hasValidKey("url", options)) {
31
+ Log.e("RNShare", "No url provided");
32
+ return;
33
+ }
34
+ String url = options.getString("url");
35
+
36
+ Boolean isUrlScheme = url.startsWith("instagram://");
37
+ if (isUrlScheme) {
38
+ openInstagramUrlScheme(url);
39
+ return;
40
+ }
41
+
42
+
43
+ if (!ShareIntent.hasValidKey("type", options)) {
44
+ Log.e("RNShare", "No type provided");
45
+ return;
46
+ }
47
+ String type = options.getString("type");
48
+ Boolean isImage = type.startsWith("image");
49
+
50
+ if (isImage) {
51
+ this.openInstagramIntentChooserForImage(url, chooserTitle);
52
+ } else {
53
+ super.openIntentChooser();
33
54
  }
34
- } catch (Exception e) {
35
- Log.w("RNShare", e.getMessage());
36
- }
37
- this.openIntentChooser();
55
+ }
56
+
57
+ protected void openInstagramUrlScheme(String url) {
58
+ Uri uri = Uri.parse(url);
59
+ this.getIntent().setAction(Intent.ACTION_VIEW);
60
+ this.getIntent().setData(uri);
61
+ super.openIntentChooser();
62
+ }
63
+
64
+ protected void openInstagramIntentChooserForImage(String url, String chooserTitle) {
65
+ Boolean shouldUseInternalStorage = ShareIntent.hasValidKey("useInternalStorage", options) && options.getBoolean("useInternalStorage");
66
+ ShareFile shareFile = new ShareFile(url, "image/jpeg", "image", shouldUseInternalStorage, this.reactContext);
67
+ Uri uri = shareFile.getURI();
68
+
69
+ Intent feedIntent = new Intent(Intent.ACTION_SEND);
70
+ feedIntent.setType("image/*");
71
+ feedIntent.putExtra(Intent.EXTRA_STREAM, uri);
72
+ feedIntent.setPackage(PACKAGE);
73
+
74
+ Intent storiesIntent = new Intent("com.instagram.share.ADD_TO_STORY");
75
+ storiesIntent.setDataAndType(uri, "jpg");
76
+ storiesIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
77
+ storiesIntent.setPackage(PACKAGE);
78
+
79
+ Intent chooserIntent = Intent.createChooser(feedIntent, chooserTitle);
80
+ chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
81
+ chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {storiesIntent});
82
+
83
+ Activity activity = this.reactContext.getCurrentActivity();
84
+ activity.grantUriPermission(PACKAGE, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
85
+ this.reactContext.startActivity(chooserIntent);
38
86
  }
39
87
 
40
88
  @Override
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-share",
3
3
  "description": "Social share, sending simple data to other apps.",
4
- "version": "7.3.0",
4
+ "version": "7.3.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/react-native-community/react-native-share.git"