react-native-share 7.2.1 → 7.3.0
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.
- package/android/src/main/java/cl/json/RNSharePathUtil.java +3 -2
- package/android/src/main/java/cl/json/ShareFile.java +9 -7
- package/android/src/main/java/cl/json/ShareFiles.java +8 -5
- package/android/src/main/java/cl/json/social/FacebookStoriesShare.java +7 -2
- package/android/src/main/java/cl/json/social/InstagramStoriesShare.java +7 -2
- package/android/src/main/java/cl/json/social/ShareIntent.java +15 -6
- package/package.json +1 -1
|
@@ -63,7 +63,7 @@ public class RNSharePathUtil {
|
|
|
63
63
|
return result;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
public static String getRealPathFromURI(final Context context, final Uri uri) {
|
|
66
|
+
public static String getRealPathFromURI(final Context context, final Uri uri, Boolean useInternalStorage) {
|
|
67
67
|
|
|
68
68
|
String filePrefix = "";
|
|
69
69
|
// DocumentProvider
|
|
@@ -76,7 +76,8 @@ public class RNSharePathUtil {
|
|
|
76
76
|
final String type = split[0];
|
|
77
77
|
|
|
78
78
|
if ("primary".equalsIgnoreCase(type) || "0".equalsIgnoreCase(type)) {
|
|
79
|
-
|
|
79
|
+
File cacheDir = useInternalStorage ? context.getCacheDir() : context.getExternalCacheDir();
|
|
80
|
+
return filePrefix + cacheDir + "/" + split[1];
|
|
80
81
|
} else if ("raw".equalsIgnoreCase(type)) {
|
|
81
82
|
return filePrefix + split[1];
|
|
82
83
|
} else if (!TextUtils.isEmpty(type)) {
|
|
@@ -23,18 +23,19 @@ public class ShareFile {
|
|
|
23
23
|
private Uri uri;
|
|
24
24
|
private String type;
|
|
25
25
|
private String filename;
|
|
26
|
+
private Boolean useInternalStorage;
|
|
26
27
|
|
|
27
|
-
public ShareFile(String url, String type, String filename, ReactApplicationContext reactContext){
|
|
28
|
-
this(url, filename, reactContext);
|
|
28
|
+
public ShareFile(String url, String type, String filename, Boolean useInternalStorage, ReactApplicationContext reactContext){
|
|
29
|
+
this(url, filename, useInternalStorage, reactContext);
|
|
29
30
|
this.type = type;
|
|
30
|
-
this.filename = filename;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
public ShareFile(String url, String filename, ReactApplicationContext reactContext){
|
|
33
|
+
public ShareFile(String url, String filename, Boolean useInternalStorage, ReactApplicationContext reactContext){
|
|
34
34
|
this.url = url;
|
|
35
35
|
this.uri = Uri.parse(this.url);
|
|
36
|
-
this.reactContext = reactContext;
|
|
37
36
|
this.filename = filename;
|
|
37
|
+
this.useInternalStorage = useInternalStorage;
|
|
38
|
+
this.reactContext = reactContext;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* Obtain mime type from URL
|
|
@@ -110,7 +111,7 @@ public class ShareFile {
|
|
|
110
111
|
return this.type;
|
|
111
112
|
}
|
|
112
113
|
private String getRealPathFromURI(Uri contentUri) {
|
|
113
|
-
String result = RNSharePathUtil.getRealPathFromURI(this.reactContext,
|
|
114
|
+
String result = RNSharePathUtil.getRealPathFromURI(this.reactContext, contentUri, this.useInternalStorage);
|
|
114
115
|
return result;
|
|
115
116
|
}
|
|
116
117
|
public Uri getURI() {
|
|
@@ -122,7 +123,8 @@ public class ShareFile {
|
|
|
122
123
|
String encodedImg = this.uri.toString().substring(BASE_64_DATA_LENGTH + this.type.length() + BASE_64_DATA_OFFSET);
|
|
123
124
|
String filename = this.filename != null ? this.filename : System.nanoTime() + "";
|
|
124
125
|
try {
|
|
125
|
-
File
|
|
126
|
+
File cacheDir = this.useInternalStorage ? this.reactContext.getCacheDir() : this.reactContext.getExternalCacheDir();
|
|
127
|
+
File dir = new File(cacheDir, Environment.DIRECTORY_DOWNLOADS);
|
|
126
128
|
if (!dir.exists() && !dir.mkdirs()) {
|
|
127
129
|
throw new IOException("mkdirs failed on " + dir.getAbsolutePath());
|
|
128
130
|
}
|
|
@@ -23,13 +23,14 @@ public class ShareFiles
|
|
|
23
23
|
private ArrayList<Uri> uris;
|
|
24
24
|
private ArrayList<String> filenames;
|
|
25
25
|
private String intentType;
|
|
26
|
+
private Boolean useInternalStorage;
|
|
26
27
|
|
|
27
|
-
public ShareFiles(ReadableArray urls, ArrayList<String> filenames, String type, ReactApplicationContext reactContext) {
|
|
28
|
-
this(urls, filenames, reactContext);
|
|
28
|
+
public ShareFiles(ReadableArray urls, ArrayList<String> filenames, String type, Boolean useInternalStorage, ReactApplicationContext reactContext) {
|
|
29
|
+
this(urls, filenames, useInternalStorage, reactContext);
|
|
29
30
|
this.intentType = type;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
public ShareFiles(ReadableArray urls, ArrayList<String> filenames, ReactApplicationContext reactContext) {
|
|
33
|
+
public ShareFiles(ReadableArray urls, ArrayList<String> filenames, Boolean useInternalStorage, ReactApplicationContext reactContext) {
|
|
33
34
|
this.uris = new ArrayList<>();
|
|
34
35
|
for (int i = 0; i < urls.size(); i++) {
|
|
35
36
|
String url = urls.getString(i);
|
|
@@ -39,6 +40,7 @@ public class ShareFiles
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
this.filenames = filenames;
|
|
43
|
+
this.useInternalStorage = useInternalStorage;
|
|
42
44
|
this.reactContext = reactContext;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
@@ -124,7 +126,7 @@ public class ShareFiles
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
private String getRealPathFromURI(Uri contentUri) {
|
|
127
|
-
String result = RNSharePathUtil.getRealPathFromURI(this.reactContext, contentUri);
|
|
129
|
+
String result = RNSharePathUtil.getRealPathFromURI(this.reactContext, contentUri, this.useInternalStorage);
|
|
128
130
|
return result;
|
|
129
131
|
}
|
|
130
132
|
|
|
@@ -141,7 +143,8 @@ public class ShareFiles
|
|
|
141
143
|
String encodedImg = uri.getSchemeSpecificPart().substring(uri.getSchemeSpecificPart().indexOf(";base64,") + 8);
|
|
142
144
|
String fileName = filenames.size() >= uriIndex + 1 ? filenames.get(uriIndex) : (System.currentTimeMillis() + "." + extension);
|
|
143
145
|
try {
|
|
144
|
-
File
|
|
146
|
+
File cacheDir = this.useInternalStorage ? this.reactContext.getCacheDir() : this.reactContext.getExternalCacheDir();
|
|
147
|
+
File dir = new File(cacheDir, Environment.DIRECTORY_DOWNLOADS);
|
|
145
148
|
if (!dir.exists() && !dir.mkdirs()) {
|
|
146
149
|
throw new IOException("mkdirs failed on " + dir.getAbsolutePath());
|
|
147
150
|
}
|
|
@@ -81,6 +81,11 @@ public class FacebookStoriesShare extends SingleShareIntent {
|
|
|
81
81
|
this.intent.putExtra("bottom_background_color", options.getString("backgroundBottomColor"));
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
Boolean useInternalStorage = false;
|
|
85
|
+
if (this.hasValidKey("useInternalStorage", options)) {
|
|
86
|
+
useInternalStorage = options.getBoolean("useInternalStorage");
|
|
87
|
+
}
|
|
88
|
+
|
|
84
89
|
Boolean hasBackgroundAsset = this.hasValidKey("backgroundImage", options)
|
|
85
90
|
|| this.hasValidKey("backgroundVideo", options);
|
|
86
91
|
|
|
@@ -93,14 +98,14 @@ public class FacebookStoriesShare extends SingleShareIntent {
|
|
|
93
98
|
backgroundFileName = options.getString("backgroundVideo");
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
ShareFile backgroundAsset = new ShareFile(backgroundFileName, "background", this.reactContext);
|
|
101
|
+
ShareFile backgroundAsset = new ShareFile(backgroundFileName, "background", useInternalStorage, this.reactContext);
|
|
97
102
|
|
|
98
103
|
this.intent.setDataAndType(backgroundAsset.getURI(), backgroundAsset.getType());
|
|
99
104
|
this.intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
if (this.hasValidKey("stickerImage", options)) {
|
|
103
|
-
ShareFile stickerAsset = new ShareFile(options.getString("stickerImage"), "sticker", this.reactContext);
|
|
108
|
+
ShareFile stickerAsset = new ShareFile(options.getString("stickerImage"), "sticker", useInternalStorage, this.reactContext);
|
|
104
109
|
|
|
105
110
|
if (!hasBackgroundAsset) {
|
|
106
111
|
this.intent.setType("image/*");
|
|
@@ -76,6 +76,11 @@ public class InstagramStoriesShare extends SingleShareIntent {
|
|
|
76
76
|
this.intent.putExtra("bottom_background_color", options.getString("backgroundBottomColor"));
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
Boolean useInternalStorage = false;
|
|
80
|
+
if (this.hasValidKey("useInternalStorage", options)) {
|
|
81
|
+
useInternalStorage = options.getBoolean("useInternalStorage");
|
|
82
|
+
}
|
|
83
|
+
|
|
79
84
|
Boolean hasBackgroundAsset = this.hasValidKey("backgroundImage", options)
|
|
80
85
|
|| this.hasValidKey("backgroundVideo", options);
|
|
81
86
|
|
|
@@ -88,14 +93,14 @@ public class InstagramStoriesShare extends SingleShareIntent {
|
|
|
88
93
|
backgroundFileName = options.getString("backgroundVideo");
|
|
89
94
|
}
|
|
90
95
|
|
|
91
|
-
ShareFile backgroundAsset = new ShareFile(backgroundFileName, "background", this.reactContext);
|
|
96
|
+
ShareFile backgroundAsset = new ShareFile(backgroundFileName, "background", useInternalStorage, this.reactContext);
|
|
92
97
|
|
|
93
98
|
this.intent.setDataAndType(backgroundAsset.getURI(), backgroundAsset.getType());
|
|
94
99
|
this.intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
if (this.hasValidKey("stickerImage", options)) {
|
|
98
|
-
ShareFile stickerAsset = new ShareFile(options.getString("stickerImage"), "sticker", this.reactContext);
|
|
103
|
+
ShareFile stickerAsset = new ShareFile(options.getString("stickerImage"), "sticker", useInternalStorage, this.reactContext);
|
|
99
104
|
|
|
100
105
|
if (!hasBackgroundAsset) {
|
|
101
106
|
this.intent.setType("image/*");
|
|
@@ -135,7 +135,7 @@ public abstract class ShareIntent {
|
|
|
135
135
|
this.getIntent().putExtra("jid", chatAddress);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
if (socialType.equals("whatsappbusiness")) {
|
|
140
140
|
if (options.hasKey("whatsAppNumber")) {
|
|
141
141
|
String whatsAppNumber = options.getString("whatsAppNumber");
|
|
@@ -186,14 +186,19 @@ public abstract class ShareIntent {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
protected ShareFile getFileShare(ReadableMap options) {
|
|
189
|
-
|
|
189
|
+
String filename = null;
|
|
190
190
|
if (ShareIntent.hasValidKey("filename", options)) {
|
|
191
191
|
filename = options.getString("filename");
|
|
192
192
|
}
|
|
193
|
+
|
|
194
|
+
Boolean useInternalStorage = false;
|
|
195
|
+
if (ShareIntent.hasValidKey("useInternalStorage", options)) {
|
|
196
|
+
useInternalStorage = options.getBoolean("useInternalStorage");
|
|
197
|
+
}
|
|
193
198
|
if (ShareIntent.hasValidKey("type", options)) {
|
|
194
|
-
return new ShareFile(options.getString("url"), options.getString("type"), filename, this.reactContext);
|
|
199
|
+
return new ShareFile(options.getString("url"), options.getString("type"), filename, useInternalStorage, this.reactContext);
|
|
195
200
|
} else {
|
|
196
|
-
return new ShareFile(options.getString("url"), filename, this.reactContext);
|
|
201
|
+
return new ShareFile(options.getString("url"), filename, useInternalStorage, this.reactContext);
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
204
|
|
|
@@ -206,10 +211,14 @@ public abstract class ShareIntent {
|
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
213
|
|
|
214
|
+
Boolean useInternalStorage = false;
|
|
215
|
+
if (ShareIntent.hasValidKey("useInternalStorage", options)) {
|
|
216
|
+
useInternalStorage = options.getBoolean("useInternalStorage");
|
|
217
|
+
}
|
|
209
218
|
if (ShareIntent.hasValidKey("type", options)) {
|
|
210
|
-
return new ShareFiles(options.getArray("urls"), filenames, options.getString("type"), this.reactContext);
|
|
219
|
+
return new ShareFiles(options.getArray("urls"), filenames, options.getString("type"), useInternalStorage, this.reactContext);
|
|
211
220
|
} else {
|
|
212
|
-
return new ShareFiles(options.getArray("urls"), filenames, this.reactContext);
|
|
221
|
+
return new ShareFiles(options.getArray("urls"), filenames, useInternalStorage, this.reactContext);
|
|
213
222
|
}
|
|
214
223
|
}
|
|
215
224
|
|
package/package.json
CHANGED