react-native-share 8.2.2 → 9.0.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/RNShare.podspec +18 -1
- package/android/build.gradle +16 -0
- package/android/src/main/java/cl/json/{RNShareModule.java → RNShareImpl.java} +52 -60
- package/android/src/main/java/cl/json/RNSharePackage.java +34 -17
- package/android/src/main/java/cl/json/social/FacebookStoriesShare.java +1 -1
- package/android/src/main/java/cl/json/social/InstagramShare.java +7 -1
- package/android/src/main/java/cl/json/social/InstagramStoriesShare.java +1 -1
- package/android/src/main/java/cl/json/social/ShareIntent.java +11 -6
- package/android/src/main/java/cl/json/social/SingleShareIntent.java +15 -6
- package/android/src/main/java/cl/json/social/TargetChosenReceiver.java +23 -17
- package/android/src/newarch/cl/json/RNShare.java +55 -0
- package/android/src/oldarch/cl/json/RNShare.java +52 -0
- package/ios/EmailShare.h +1 -1
- package/ios/EmailShare.m +5 -5
- package/ios/FacebookStories.h +1 -1
- package/ios/FacebookStories.m +4 -4
- package/ios/GenericShare.h +1 -1
- package/ios/GenericShare.m +5 -5
- package/ios/GooglePlusShare.h +1 -1
- package/ios/GooglePlusShare.m +4 -4
- package/ios/InstagramShare.h +3 -3
- package/ios/InstagramShare.m +16 -16
- package/ios/InstagramStories.h +1 -1
- package/ios/InstagramStories.m +4 -4
- package/ios/MessengerShare.h +1 -1
- package/ios/MessengerShare.m +3 -3
- package/ios/RNShare.h +16 -2
- package/ios/{RNShare.m → RNShare.mm} +71 -25
- package/ios/TelegramShare.h +1 -1
- package/ios/TelegramShare.m +4 -4
- package/ios/ViberShare.h +1 -1
- package/ios/ViberShare.m +4 -4
- package/ios/WhatsAppShare.h +1 -1
- package/ios/WhatsAppShare.m +8 -8
- package/lib/commonjs/components/Button.js +21 -25
- package/lib/commonjs/components/Button.js.map +1 -1
- package/lib/commonjs/components/Overlay.js +7 -15
- package/lib/commonjs/components/Overlay.js.map +1 -1
- package/lib/commonjs/components/ShareSheet.js +10 -21
- package/lib/commonjs/components/ShareSheet.js.map +1 -1
- package/lib/commonjs/components/Sheet.js +7 -13
- package/lib/commonjs/components/Sheet.js.map +1 -1
- package/lib/commonjs/helpers/requireAndAskPermissions.js +6 -16
- package/lib/commonjs/helpers/requireAndAskPermissions.js.map +1 -1
- package/lib/commonjs/index.js +40 -68
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js +9 -12
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/components/Button.js +19 -18
- package/lib/module/components/Button.js.map +1 -1
- package/lib/module/components/Overlay.js +5 -7
- package/lib/module/components/Overlay.js.map +1 -1
- package/lib/module/components/ShareSheet.js +8 -10
- package/lib/module/components/ShareSheet.js.map +1 -1
- package/lib/module/components/Sheet.js +5 -6
- package/lib/module/components/Sheet.js.map +1 -1
- package/lib/module/helpers/requireAndAskPermissions.js +6 -15
- package/lib/module/helpers/requireAndAskPermissions.js.map +1 -1
- package/lib/module/index.js +31 -50
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +8 -9
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/codegenSpec/NativeRNShare.d.ts +39 -0
- package/lib/typescript/{index.d.ts → src/index.d.ts} +17 -17
- package/lib/typescript/{types.d.ts → src/types.d.ts} +1 -0
- package/package.json +11 -3
- package/src/helpers/requireAndAskPermissions.ts +9 -9
- package/src/index.tsx +46 -60
- package/src/types.ts +1 -0
- package/CHANGELOG.md +0 -133
- package/lib/commonjs/typings/react-native.d.js +0 -4
- package/lib/commonjs/typings/react-native.d.js.map +0 -1
- package/lib/module/typings/react-native.d.js +0 -2
- package/lib/module/typings/react-native.d.js.map +0 -1
- package/src/typings/react-native.d.ts +0 -58
- package/windows/.gitignore +0 -92
- /package/lib/typescript/{components → src/components}/Button.d.ts +0 -0
- /package/lib/typescript/{components → src/components}/Overlay.d.ts +0 -0
- /package/lib/typescript/{components → src/components}/ShareSheet.d.ts +0 -0
- /package/lib/typescript/{components → src/components}/Sheet.d.ts +0 -0
- /package/lib/typescript/{helpers → src/helpers}/requireAndAskPermissions.d.ts +0 -0
package/RNShare.podspec
CHANGED
|
@@ -12,9 +12,26 @@ Pod::Spec.new do |s|
|
|
|
12
12
|
s.platform = :ios, "8.0"
|
|
13
13
|
s.source = { :git => "https://github.com/react-native-community/react-native-share.git", :tag => "v#{s.version}" }
|
|
14
14
|
|
|
15
|
-
s.source_files = "ios/**/*.{h,m}"
|
|
15
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
16
16
|
|
|
17
17
|
s.dependency "React-Core"
|
|
18
18
|
|
|
19
19
|
s.ios.weak_framework = 'LinkPresentation'
|
|
20
|
+
|
|
21
|
+
if ENV["RCT_NEW_ARCH_ENABLED"] == "1"
|
|
22
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
23
|
+
s.pod_target_xcconfig = {
|
|
24
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
25
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
26
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
s.dependency "React-Codegen"
|
|
30
|
+
s.dependency "React-RCTFabric"
|
|
31
|
+
s.dependency "RCT-Folly"
|
|
32
|
+
s.dependency "RCTRequired"
|
|
33
|
+
s.dependency "RCTTypeSafety"
|
|
34
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
35
|
+
end
|
|
36
|
+
|
|
20
37
|
end
|
package/android/build.gradle
CHANGED
|
@@ -17,7 +17,14 @@ buildscript {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
def isNewArchitectureEnabled() {
|
|
21
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
apply plugin: 'com.android.library'
|
|
25
|
+
if (isNewArchitectureEnabled()) {
|
|
26
|
+
apply plugin: 'com.facebook.react'
|
|
27
|
+
}
|
|
21
28
|
|
|
22
29
|
android {
|
|
23
30
|
compileSdkVersion safeExtGet('compileSdkVersion', 28)
|
|
@@ -29,6 +36,15 @@ android {
|
|
|
29
36
|
abortOnError false
|
|
30
37
|
warning 'InvalidPackage'
|
|
31
38
|
}
|
|
39
|
+
sourceSets {
|
|
40
|
+
main {
|
|
41
|
+
if (isNewArchitectureEnabled()) {
|
|
42
|
+
java.srcDirs += ['src/newarch']
|
|
43
|
+
} else {
|
|
44
|
+
java.srcDirs += ['src/oldarch']
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
repositories {
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
package cl.json;
|
|
2
2
|
|
|
3
3
|
import android.app.Activity;
|
|
4
|
-
import android.content.ActivityNotFoundException;
|
|
5
4
|
import android.content.Intent;
|
|
6
|
-
import android.
|
|
5
|
+
import android.content.ActivityNotFoundException;
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
7
|
import androidx.annotation.Nullable;
|
|
8
|
+
import android.net.Uri;
|
|
8
9
|
|
|
9
|
-
import com.facebook.react.bridge.
|
|
10
|
+
import com.facebook.react.bridge.Arguments;
|
|
10
11
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
|
-
import com.facebook.react.bridge.
|
|
12
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
12
|
+
import com.facebook.react.bridge.ActivityEventListener;
|
|
13
13
|
import com.facebook.react.bridge.ReadableMap;
|
|
14
|
-
import com.facebook.react.bridge.
|
|
15
|
-
|
|
16
|
-
import java.util.HashMap;
|
|
17
|
-
import java.util.Locale;
|
|
18
|
-
import java.util.Map;
|
|
14
|
+
import com.facebook.react.bridge.Promise;
|
|
15
|
+
import com.facebook.react.bridge.WritableMap;
|
|
19
16
|
|
|
20
17
|
import cl.json.social.EmailShare;
|
|
21
18
|
import cl.json.social.FacebookShare;
|
|
@@ -38,31 +35,39 @@ import cl.json.social.MessengerShare;
|
|
|
38
35
|
import cl.json.social.LinkedinShare;
|
|
39
36
|
import cl.json.social.ViberShare;
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
import java.util.HashMap;
|
|
39
|
+
import java.util.Locale;
|
|
40
|
+
import java.util.Map;
|
|
41
|
+
|
|
42
|
+
import android.util.Log;
|
|
43
|
+
|
|
44
|
+
public class RNShareImpl implements ActivityEventListener {
|
|
45
|
+
|
|
46
|
+
public static final String NAME = "RNShare";
|
|
47
|
+
|
|
48
|
+
static ReactApplicationContext RCTContext = null;
|
|
42
49
|
|
|
43
50
|
public static final int SHARE_REQUEST_CODE = 16845;
|
|
44
|
-
private final ReactApplicationContext reactContext;
|
|
45
51
|
|
|
46
|
-
// removed @Override temporarily just to get it working on different versions of RN
|
|
47
52
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
48
53
|
if (requestCode == SHARE_REQUEST_CODE) {
|
|
49
54
|
if (resultCode == Activity.RESULT_CANCELED) {
|
|
50
|
-
|
|
55
|
+
WritableMap reply = Arguments.createMap();
|
|
56
|
+
reply.putBoolean("success", false);
|
|
57
|
+
reply.putString("message", "CANCELED");
|
|
51
58
|
} else if (resultCode == Activity.RESULT_OK) {
|
|
52
|
-
|
|
59
|
+
WritableMap reply = Arguments.createMap();
|
|
60
|
+
reply.putBoolean("success", true);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
// removed @Override temporarily just to get it working on different versions of RN
|
|
58
65
|
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
59
66
|
onActivityResult(requestCode, resultCode, data);
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
@Override
|
|
63
|
-
public void onNewIntent(Intent intent) {
|
|
64
|
-
|
|
65
|
-
}
|
|
70
|
+
public void onNewIntent(Intent intent) { }
|
|
66
71
|
|
|
67
72
|
private enum SHARES {
|
|
68
73
|
facebook,
|
|
@@ -130,19 +135,11 @@ public class RNShareModule extends ReactContextBaseJavaModule implements Activit
|
|
|
130
135
|
}
|
|
131
136
|
};
|
|
132
137
|
|
|
133
|
-
public
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.reactContext = reactContext;
|
|
138
|
+
public RNShareImpl(ReactApplicationContext reactContext) {
|
|
139
|
+
RCTContext = reactContext;
|
|
140
|
+
RCTContext.addActivityEventListener(this);
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
@Override
|
|
140
|
-
public String getName() {
|
|
141
|
-
return "RNShare";
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
@javax.annotation.Nullable
|
|
145
|
-
@Override
|
|
146
143
|
public Map<String, Object> getConstants() {
|
|
147
144
|
Map<String, Object> constants = new HashMap<>();
|
|
148
145
|
for (SHARES val : SHARES.values()) {
|
|
@@ -151,74 +148,69 @@ public class RNShareModule extends ReactContextBaseJavaModule implements Activit
|
|
|
151
148
|
return constants;
|
|
152
149
|
}
|
|
153
150
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
TargetChosenReceiver.registerCallbacks(successCallback, failureCallback);
|
|
151
|
+
public void open(ReadableMap options, Promise promise) {
|
|
152
|
+
TargetChosenReceiver.registerCallbacks(promise);
|
|
157
153
|
try {
|
|
158
|
-
GenericShare share = new GenericShare(
|
|
154
|
+
GenericShare share = new GenericShare(RCTContext);
|
|
159
155
|
share.open(options);
|
|
160
156
|
} catch (ActivityNotFoundException ex) {
|
|
161
|
-
|
|
157
|
+
Log.e(NAME,ex.getMessage());
|
|
162
158
|
ex.printStackTrace(System.out);
|
|
163
|
-
TargetChosenReceiver.
|
|
159
|
+
TargetChosenReceiver.callbackReject("not_available");
|
|
164
160
|
} catch (Exception e) {
|
|
165
|
-
|
|
161
|
+
Log.e(NAME,e.getMessage());
|
|
166
162
|
e.printStackTrace(System.out);
|
|
167
|
-
TargetChosenReceiver.
|
|
163
|
+
TargetChosenReceiver.callbackReject(e.getMessage());
|
|
168
164
|
}
|
|
169
165
|
}
|
|
170
166
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
System.out.println("SHARE SINGLE METHOD");
|
|
174
|
-
TargetChosenReceiver.registerCallbacks(successCallback, failureCallback);
|
|
167
|
+
public void shareSingle(ReadableMap options, Promise promise) {
|
|
168
|
+
TargetChosenReceiver.registerCallbacks(promise);
|
|
175
169
|
if (ShareIntent.hasValidKey("social", options)) {
|
|
176
170
|
try {
|
|
177
|
-
ShareIntent shareClass = SHARES.getShareClass(options.getString("social"),
|
|
171
|
+
ShareIntent shareClass = SHARES.getShareClass(options.getString("social"), RCTContext);
|
|
178
172
|
if (shareClass != null && shareClass instanceof ShareIntent) {
|
|
179
173
|
shareClass.open(options);
|
|
180
174
|
} else {
|
|
181
175
|
throw new ActivityNotFoundException("Invalid share activity");
|
|
182
176
|
}
|
|
183
177
|
} catch (ActivityNotFoundException ex) {
|
|
184
|
-
|
|
178
|
+
Log.e(NAME,ex.getMessage());
|
|
185
179
|
ex.printStackTrace(System.out);
|
|
186
|
-
TargetChosenReceiver.
|
|
180
|
+
TargetChosenReceiver.callbackReject(ex.getMessage());
|
|
187
181
|
} catch (Exception e) {
|
|
188
|
-
|
|
182
|
+
Log.e(NAME,e.getMessage());
|
|
189
183
|
e.printStackTrace(System.out);
|
|
190
|
-
TargetChosenReceiver.
|
|
184
|
+
TargetChosenReceiver.callbackReject(e.getMessage());
|
|
191
185
|
}
|
|
192
186
|
} else {
|
|
193
|
-
TargetChosenReceiver.
|
|
187
|
+
TargetChosenReceiver.callbackReject("key 'social' missing in options");
|
|
194
188
|
}
|
|
195
189
|
}
|
|
196
190
|
|
|
197
|
-
|
|
198
|
-
public void isPackageInstalled(String packagename, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
|
|
191
|
+
public void isPackageInstalled(String packagename, Promise promise) {
|
|
199
192
|
try {
|
|
200
|
-
boolean res = ShareIntent.isPackageInstalled(packagename,
|
|
201
|
-
|
|
193
|
+
boolean res = ShareIntent.isPackageInstalled(packagename, RCTContext);
|
|
194
|
+
promise.resolve(res);
|
|
202
195
|
} catch (Exception e) {
|
|
203
|
-
|
|
204
|
-
|
|
196
|
+
Log.e(NAME,e.getMessage());
|
|
197
|
+
promise.reject(e.getMessage());
|
|
205
198
|
}
|
|
206
199
|
}
|
|
207
200
|
|
|
208
|
-
|
|
209
|
-
public void isBase64File(String url, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
|
|
201
|
+
public void isBase64File(String url, Promise promise) {
|
|
210
202
|
try {
|
|
211
203
|
Uri uri = Uri.parse(url);
|
|
212
204
|
String scheme = uri.getScheme();
|
|
213
205
|
if ((scheme != null) && scheme.equals("data")) {
|
|
214
|
-
|
|
206
|
+
promise.resolve(true);
|
|
215
207
|
} else {
|
|
216
|
-
|
|
208
|
+
promise.resolve(false);
|
|
217
209
|
}
|
|
218
210
|
} catch (Exception e) {
|
|
219
|
-
|
|
211
|
+
Log.e(NAME,e.getMessage());
|
|
220
212
|
e.printStackTrace(System.out);
|
|
221
|
-
|
|
213
|
+
promise.reject(e.getMessage());
|
|
222
214
|
}
|
|
223
215
|
}
|
|
224
216
|
}
|
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
package cl.json;
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import java.util.Collections;
|
|
5
|
-
import java.util.List;
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
6
4
|
|
|
7
|
-
import com.facebook.react.ReactPackage;
|
|
8
5
|
import com.facebook.react.bridge.NativeModule;
|
|
9
6
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
-
import com.facebook.react.
|
|
11
|
-
import com.facebook.react.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
9
|
+
import com.facebook.react.TurboReactPackage;
|
|
10
|
+
|
|
11
|
+
import java.util.HashMap;
|
|
12
|
+
import java.util.Map;
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
public class RNSharePackage extends TurboReactPackage {
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
@Override
|
|
18
|
+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
|
|
19
|
+
if (name.equals(RNShareImpl.NAME)) {
|
|
20
|
+
return new RNShare(reactContext);
|
|
21
|
+
} else {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
@Override
|
|
24
|
-
public
|
|
25
|
-
|
|
27
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
28
|
+
return () -> {
|
|
29
|
+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
|
|
30
|
+
moduleInfos.put(
|
|
31
|
+
RNShareImpl.NAME,
|
|
32
|
+
new ReactModuleInfo(
|
|
33
|
+
RNShareImpl.NAME,
|
|
34
|
+
RNShareImpl.NAME,
|
|
35
|
+
false, // canOverrideExistingModule
|
|
36
|
+
false, // needsEagerInit
|
|
37
|
+
true, // hasConstants
|
|
38
|
+
false, // isCxxModule
|
|
39
|
+
false // isTurboModule
|
|
40
|
+
));
|
|
41
|
+
return moduleInfos;
|
|
42
|
+
};
|
|
26
43
|
}
|
|
27
|
-
}
|
|
44
|
+
}
|
|
@@ -61,7 +61,7 @@ public class FacebookStoriesShare extends SingleShareIntent {
|
|
|
61
61
|
Activity activity = this.reactContext.getCurrentActivity();
|
|
62
62
|
|
|
63
63
|
if (activity == null) {
|
|
64
|
-
TargetChosenReceiver.
|
|
64
|
+
TargetChosenReceiver.callbackReject("Something went wrong");
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -6,8 +6,10 @@ import android.content.Intent;
|
|
|
6
6
|
import android.net.Uri;
|
|
7
7
|
import android.util.Log;
|
|
8
8
|
|
|
9
|
+
import com.facebook.react.bridge.Arguments;
|
|
9
10
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
11
|
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
+
import com.facebook.react.bridge.WritableMap;
|
|
11
13
|
|
|
12
14
|
import cl.json.ShareFile;
|
|
13
15
|
|
|
@@ -107,7 +109,11 @@ public class InstagramShare extends SingleShareIntent {
|
|
|
107
109
|
Activity activity = this.reactContext.getCurrentActivity();
|
|
108
110
|
activity.grantUriPermission(PACKAGE, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
109
111
|
this.reactContext.startActivity(chooserIntent);
|
|
110
|
-
|
|
112
|
+
|
|
113
|
+
WritableMap reply = Arguments.createMap();
|
|
114
|
+
reply.putBoolean("success", true);
|
|
115
|
+
reply.putString("message", this.getIntent().getPackage());
|
|
116
|
+
TargetChosenReceiver.callbackResolve(reply);
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
@Override
|
|
@@ -57,7 +57,7 @@ public class InstagramStoriesShare extends SingleShareIntent {
|
|
|
57
57
|
Activity activity = this.reactContext.getCurrentActivity();
|
|
58
58
|
|
|
59
59
|
if (activity == null) {
|
|
60
|
-
TargetChosenReceiver.
|
|
60
|
+
TargetChosenReceiver.callbackReject("Something went wrong");
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -15,6 +15,8 @@ import android.content.ComponentName;
|
|
|
15
15
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
16
16
|
import com.facebook.react.bridge.ReadableArray;
|
|
17
17
|
import com.facebook.react.bridge.ReadableMap;
|
|
18
|
+
import com.facebook.react.bridge.Arguments;
|
|
19
|
+
import com.facebook.react.bridge.WritableMap;
|
|
18
20
|
|
|
19
21
|
import java.io.UnsupportedEncodingException;
|
|
20
22
|
import java.util.Arrays;
|
|
@@ -25,7 +27,7 @@ import java.util.List;
|
|
|
25
27
|
import java.net.URLEncoder;
|
|
26
28
|
import java.util.ArrayList;
|
|
27
29
|
|
|
28
|
-
import cl.json.
|
|
30
|
+
import cl.json.RNShareImpl;
|
|
29
31
|
import cl.json.ShareFile;
|
|
30
32
|
import cl.json.ShareFiles;
|
|
31
33
|
|
|
@@ -257,7 +259,7 @@ public abstract class ShareIntent {
|
|
|
257
259
|
protected void openIntentChooser() throws ActivityNotFoundException {
|
|
258
260
|
Activity activity = this.reactContext.getCurrentActivity();
|
|
259
261
|
if (activity == null) {
|
|
260
|
-
TargetChosenReceiver.
|
|
262
|
+
TargetChosenReceiver.callbackReject("Something went wrong");
|
|
261
263
|
return;
|
|
262
264
|
}
|
|
263
265
|
Intent chooser;
|
|
@@ -282,16 +284,19 @@ public abstract class ShareIntent {
|
|
|
282
284
|
if (ShareIntent.hasValidKey("excludedActivityTypes", options)) {
|
|
283
285
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
|
284
286
|
chooser.putExtra(Intent.EXTRA_EXCLUDE_COMPONENTS, getExcludedComponentArray(options.getArray("excludedActivityTypes")));
|
|
285
|
-
activity.startActivityForResult(chooser,
|
|
287
|
+
activity.startActivityForResult(chooser, RNShareImpl.SHARE_REQUEST_CODE);
|
|
286
288
|
} else {
|
|
287
|
-
activity.startActivityForResult(excludeChooserIntent(this.getIntent(),options),
|
|
289
|
+
activity.startActivityForResult(excludeChooserIntent(this.getIntent(),options), RNShareImpl.SHARE_REQUEST_CODE);
|
|
288
290
|
}
|
|
289
291
|
} else {
|
|
290
|
-
activity.startActivityForResult(chooser,
|
|
292
|
+
activity.startActivityForResult(chooser, RNShareImpl.SHARE_REQUEST_CODE);
|
|
291
293
|
}
|
|
292
294
|
|
|
293
295
|
if (intentSender == null) {
|
|
294
|
-
|
|
296
|
+
WritableMap reply = Arguments.createMap();
|
|
297
|
+
reply.putBoolean("success", true);
|
|
298
|
+
reply.putString("message", "OK");
|
|
299
|
+
TargetChosenReceiver.callbackResolve(reply);
|
|
295
300
|
}
|
|
296
301
|
}
|
|
297
302
|
|
|
@@ -8,10 +8,12 @@ import android.content.Intent;
|
|
|
8
8
|
import android.content.IntentSender;
|
|
9
9
|
import android.net.Uri;
|
|
10
10
|
|
|
11
|
+
import com.facebook.react.bridge.Arguments;
|
|
11
12
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
12
13
|
import com.facebook.react.bridge.ReadableMap;
|
|
14
|
+
import com.facebook.react.bridge.WritableMap;
|
|
13
15
|
|
|
14
|
-
import cl.json.
|
|
16
|
+
import cl.json.RNShareImpl;
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Created by disenodosbbcl on 23-07-16.
|
|
@@ -67,7 +69,7 @@ public abstract class SingleShareIntent extends ShareIntent {
|
|
|
67
69
|
if (this.options.hasKey("forceDialog") && this.options.getBoolean("forceDialog")) {
|
|
68
70
|
Activity activity = this.reactContext.getCurrentActivity();
|
|
69
71
|
if (activity == null) {
|
|
70
|
-
TargetChosenReceiver.
|
|
72
|
+
TargetChosenReceiver.callbackReject("Something went wrong");
|
|
71
73
|
return;
|
|
72
74
|
}
|
|
73
75
|
if (options != null) {
|
|
@@ -79,17 +81,24 @@ public abstract class SingleShareIntent extends ShareIntent {
|
|
|
79
81
|
IntentSender sender = TargetChosenReceiver.getSharingSenderIntent(this.reactContext);
|
|
80
82
|
Intent chooser = Intent.createChooser(this.getIntent(), this.chooserTitle, sender);
|
|
81
83
|
chooser.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
|
82
|
-
activity.startActivityForResult(chooser,
|
|
84
|
+
activity.startActivityForResult(chooser, RNShareImpl.SHARE_REQUEST_CODE);
|
|
83
85
|
} else {
|
|
84
86
|
Intent chooser = Intent.createChooser(this.getIntent(), this.chooserTitle);
|
|
85
87
|
chooser.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
|
86
|
-
activity.startActivityForResult(chooser,
|
|
87
|
-
|
|
88
|
+
activity.startActivityForResult(chooser, RNShareImpl.SHARE_REQUEST_CODE);
|
|
89
|
+
|
|
90
|
+
WritableMap reply = Arguments.createMap();
|
|
91
|
+
reply.putBoolean("success", true);
|
|
92
|
+
reply.putString("message", "OK");
|
|
93
|
+
TargetChosenReceiver.callbackResolve(reply);
|
|
88
94
|
}
|
|
89
95
|
} else {
|
|
90
96
|
this.getIntent().addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
91
97
|
this.reactContext.startActivity(this.getIntent());
|
|
92
|
-
|
|
98
|
+
WritableMap reply = Arguments.createMap();
|
|
99
|
+
reply.putBoolean("success", true);
|
|
100
|
+
reply.putString("message", this.getIntent().getPackage());
|
|
101
|
+
TargetChosenReceiver.callbackResolve(reply);
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
}
|
|
@@ -10,8 +10,10 @@ import android.content.IntentFilter;
|
|
|
10
10
|
import android.content.IntentSender;
|
|
11
11
|
import android.os.Build;
|
|
12
12
|
|
|
13
|
-
import com.facebook.react.bridge.
|
|
13
|
+
import com.facebook.react.bridge.Promise;
|
|
14
14
|
import com.facebook.react.bridge.ReactContext;
|
|
15
|
+
import com.facebook.react.bridge.Arguments;
|
|
16
|
+
import com.facebook.react.bridge.WritableMap;
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Receiver to record the chosen component when sharing an Intent.
|
|
@@ -23,16 +25,14 @@ public class TargetChosenReceiver extends BroadcastReceiver {
|
|
|
23
25
|
private static String sTargetChosenReceiveAction;
|
|
24
26
|
private static TargetChosenReceiver sLastRegisteredReceiver;
|
|
25
27
|
|
|
26
|
-
private static
|
|
27
|
-
private static Callback failureCallback;
|
|
28
|
+
private static Promise callback;
|
|
28
29
|
|
|
29
30
|
public static boolean isSupported() {
|
|
30
31
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
public static void registerCallbacks(
|
|
34
|
-
|
|
35
|
-
failureCallback = failure;
|
|
34
|
+
public static void registerCallbacks(Promise promise) {
|
|
35
|
+
callback = promise;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
|
|
@@ -73,22 +73,28 @@ public class TargetChosenReceiver extends BroadcastReceiver {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
ComponentName target = intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT);
|
|
76
|
+
WritableMap reply = Arguments.createMap();
|
|
77
|
+
reply.putBoolean("success", true);
|
|
76
78
|
if (target != null) {
|
|
77
|
-
|
|
79
|
+
reply.putString("message", target.flattenToString());
|
|
80
|
+
|
|
78
81
|
} else {
|
|
79
|
-
|
|
82
|
+
reply.putString("message", "OK");
|
|
80
83
|
}
|
|
84
|
+
callbackResolve(reply);
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
public static void sendCallback(boolean isSuccess, Object
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
// public static void sendCallback(boolean isSuccess, Object reply) {
|
|
88
|
+
public static void callbackResolve(Object reply) {
|
|
89
|
+
if (callback != null) {
|
|
90
|
+
callback.resolve(reply);
|
|
91
|
+
}
|
|
92
|
+
callback = null;
|
|
93
|
+
}
|
|
94
|
+
public static void callbackReject(String err) {
|
|
95
|
+
if (callback != null) {
|
|
96
|
+
callback.reject(err);
|
|
90
97
|
}
|
|
91
|
-
|
|
92
|
-
failureCallback = null;
|
|
98
|
+
callback = null;
|
|
93
99
|
}
|
|
94
100
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package cl.json;
|
|
2
|
+
|
|
3
|
+
import android.os.Build;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
10
|
+
import com.facebook.react.bridge.Promise;
|
|
11
|
+
|
|
12
|
+
import java.util.Map;
|
|
13
|
+
|
|
14
|
+
import cl.json.NativeRNShareSpec;
|
|
15
|
+
|
|
16
|
+
public class RNShare extends NativeRNShareSpec {
|
|
17
|
+
|
|
18
|
+
private final RNShareImpl delegate;
|
|
19
|
+
|
|
20
|
+
public RNShare(ReactApplicationContext reactContext) {
|
|
21
|
+
super(reactContext);
|
|
22
|
+
delegate = new RNShareImpl(reactContext);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@NonNull
|
|
26
|
+
@Override
|
|
27
|
+
public String getName() {
|
|
28
|
+
return RNShareImpl.NAME;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Override
|
|
32
|
+
public Map<String, Object> getConstants() {
|
|
33
|
+
return delegate.getConstants();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Override
|
|
37
|
+
public void open(ReadableMap options, Promise promise) {
|
|
38
|
+
delegate.open(options,promise);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Override
|
|
42
|
+
public void shareSingle(ReadableMap options, Promise promise) {
|
|
43
|
+
delegate.shareSingle(options,promise);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Override
|
|
47
|
+
public void isPackageInstalled(String packagename, Promise promise) {
|
|
48
|
+
delegate.isPackageInstalled(packagename,promise);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Override
|
|
52
|
+
public void isBase64File(String url, Promise promise) {
|
|
53
|
+
delegate.isBase64File(url,promise);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package cl.json;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
9
|
+
import com.facebook.react.bridge.Promise;
|
|
10
|
+
|
|
11
|
+
import java.util.Map;
|
|
12
|
+
|
|
13
|
+
public class RNShare extends ReactContextBaseJavaModule {
|
|
14
|
+
|
|
15
|
+
private final RNShareImpl delegate;
|
|
16
|
+
|
|
17
|
+
public RNShare(ReactApplicationContext reactContext) {
|
|
18
|
+
super(reactContext);
|
|
19
|
+
delegate = new RNShareImpl(reactContext);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public String getName() {
|
|
24
|
+
return RNShareImpl.NAME;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@javax.annotation.Nullable
|
|
28
|
+
@Override
|
|
29
|
+
public Map<String, Object> getConstants() {
|
|
30
|
+
return delegate.getConstants();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ReactMethod
|
|
34
|
+
public void open(ReadableMap options, Promise promise) {
|
|
35
|
+
delegate.open(options,promise);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactMethod
|
|
39
|
+
public void shareSingle(ReadableMap options, Promise promise) {
|
|
40
|
+
delegate.shareSingle(options,promise);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ReactMethod
|
|
44
|
+
public void isPackageInstalled(String packagename, Promise promise) {
|
|
45
|
+
delegate.isPackageInstalled(packagename,promise);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ReactMethod
|
|
49
|
+
public void isBase64File(String url, Promise promise) {
|
|
50
|
+
delegate.isBase64File(url,promise);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/ios/EmailShare.h
CHANGED
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
#import <MessageUI/MessageUI.h>
|
|
22
22
|
@interface EmailShare : NSObject <MFMailComposeViewControllerDelegate>
|
|
23
23
|
|
|
24
|
-
- (void) shareSingle:(NSDictionary *)options
|
|
24
|
+
- (void) shareSingle:(NSDictionary *)options reject:(RCTPromiseRejectBlock)reject resolve:(RCTPromiseResolveBlock)resolve;
|
|
25
25
|
@end
|