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.
Files changed (81) hide show
  1. package/RNShare.podspec +18 -1
  2. package/android/build.gradle +16 -0
  3. package/android/src/main/java/cl/json/{RNShareModule.java → RNShareImpl.java} +52 -60
  4. package/android/src/main/java/cl/json/RNSharePackage.java +34 -17
  5. package/android/src/main/java/cl/json/social/FacebookStoriesShare.java +1 -1
  6. package/android/src/main/java/cl/json/social/InstagramShare.java +7 -1
  7. package/android/src/main/java/cl/json/social/InstagramStoriesShare.java +1 -1
  8. package/android/src/main/java/cl/json/social/ShareIntent.java +11 -6
  9. package/android/src/main/java/cl/json/social/SingleShareIntent.java +15 -6
  10. package/android/src/main/java/cl/json/social/TargetChosenReceiver.java +23 -17
  11. package/android/src/newarch/cl/json/RNShare.java +55 -0
  12. package/android/src/oldarch/cl/json/RNShare.java +52 -0
  13. package/ios/EmailShare.h +1 -1
  14. package/ios/EmailShare.m +5 -5
  15. package/ios/FacebookStories.h +1 -1
  16. package/ios/FacebookStories.m +4 -4
  17. package/ios/GenericShare.h +1 -1
  18. package/ios/GenericShare.m +5 -5
  19. package/ios/GooglePlusShare.h +1 -1
  20. package/ios/GooglePlusShare.m +4 -4
  21. package/ios/InstagramShare.h +3 -3
  22. package/ios/InstagramShare.m +16 -16
  23. package/ios/InstagramStories.h +1 -1
  24. package/ios/InstagramStories.m +4 -4
  25. package/ios/MessengerShare.h +1 -1
  26. package/ios/MessengerShare.m +3 -3
  27. package/ios/RNShare.h +16 -2
  28. package/ios/{RNShare.m → RNShare.mm} +71 -25
  29. package/ios/TelegramShare.h +1 -1
  30. package/ios/TelegramShare.m +4 -4
  31. package/ios/ViberShare.h +1 -1
  32. package/ios/ViberShare.m +4 -4
  33. package/ios/WhatsAppShare.h +1 -1
  34. package/ios/WhatsAppShare.m +8 -8
  35. package/lib/commonjs/components/Button.js +21 -25
  36. package/lib/commonjs/components/Button.js.map +1 -1
  37. package/lib/commonjs/components/Overlay.js +7 -15
  38. package/lib/commonjs/components/Overlay.js.map +1 -1
  39. package/lib/commonjs/components/ShareSheet.js +10 -21
  40. package/lib/commonjs/components/ShareSheet.js.map +1 -1
  41. package/lib/commonjs/components/Sheet.js +7 -13
  42. package/lib/commonjs/components/Sheet.js.map +1 -1
  43. package/lib/commonjs/helpers/requireAndAskPermissions.js +6 -16
  44. package/lib/commonjs/helpers/requireAndAskPermissions.js.map +1 -1
  45. package/lib/commonjs/index.js +40 -68
  46. package/lib/commonjs/index.js.map +1 -1
  47. package/lib/commonjs/types.js +9 -12
  48. package/lib/commonjs/types.js.map +1 -1
  49. package/lib/module/components/Button.js +19 -18
  50. package/lib/module/components/Button.js.map +1 -1
  51. package/lib/module/components/Overlay.js +5 -7
  52. package/lib/module/components/Overlay.js.map +1 -1
  53. package/lib/module/components/ShareSheet.js +8 -10
  54. package/lib/module/components/ShareSheet.js.map +1 -1
  55. package/lib/module/components/Sheet.js +5 -6
  56. package/lib/module/components/Sheet.js.map +1 -1
  57. package/lib/module/helpers/requireAndAskPermissions.js +6 -15
  58. package/lib/module/helpers/requireAndAskPermissions.js.map +1 -1
  59. package/lib/module/index.js +31 -50
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/module/types.js +8 -9
  62. package/lib/module/types.js.map +1 -1
  63. package/lib/typescript/codegenSpec/NativeRNShare.d.ts +39 -0
  64. package/lib/typescript/{index.d.ts → src/index.d.ts} +17 -17
  65. package/lib/typescript/{types.d.ts → src/types.d.ts} +1 -0
  66. package/package.json +11 -3
  67. package/src/helpers/requireAndAskPermissions.ts +9 -9
  68. package/src/index.tsx +46 -60
  69. package/src/types.ts +1 -0
  70. package/CHANGELOG.md +0 -133
  71. package/lib/commonjs/typings/react-native.d.js +0 -4
  72. package/lib/commonjs/typings/react-native.d.js.map +0 -1
  73. package/lib/module/typings/react-native.d.js +0 -2
  74. package/lib/module/typings/react-native.d.js.map +0 -1
  75. package/src/typings/react-native.d.ts +0 -58
  76. package/windows/.gitignore +0 -92
  77. /package/lib/typescript/{components → src/components}/Button.d.ts +0 -0
  78. /package/lib/typescript/{components → src/components}/Overlay.d.ts +0 -0
  79. /package/lib/typescript/{components → src/components}/ShareSheet.d.ts +0 -0
  80. /package/lib/typescript/{components → src/components}/Sheet.d.ts +0 -0
  81. /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
@@ -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.net.Uri;
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.ActivityEventListener;
10
+ import com.facebook.react.bridge.Arguments;
10
11
  import com.facebook.react.bridge.ReactApplicationContext;
11
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
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.Callback;
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
- public class RNShareModule extends ReactContextBaseJavaModule implements ActivityEventListener {
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
- TargetChosenReceiver.sendCallback(true, false, "CANCELED");
55
+ WritableMap reply = Arguments.createMap();
56
+ reply.putBoolean("success", false);
57
+ reply.putString("message", "CANCELED");
51
58
  } else if (resultCode == Activity.RESULT_OK) {
52
- TargetChosenReceiver.sendCallback(true, true);
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 RNShareModule(ReactApplicationContext reactContext) {
134
- super(reactContext);
135
- reactContext.addActivityEventListener(this);
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
- @ReactMethod
155
- public void open(ReadableMap options, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
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(this.reactContext);
154
+ GenericShare share = new GenericShare(RCTContext);
159
155
  share.open(options);
160
156
  } catch (ActivityNotFoundException ex) {
161
- System.out.println("ERROR " + ex.getMessage());
157
+ Log.e(NAME,ex.getMessage());
162
158
  ex.printStackTrace(System.out);
163
- TargetChosenReceiver.sendCallback(false, "not_available");
159
+ TargetChosenReceiver.callbackReject("not_available");
164
160
  } catch (Exception e) {
165
- System.out.println("ERROR " + e.getMessage());
161
+ Log.e(NAME,e.getMessage());
166
162
  e.printStackTrace(System.out);
167
- TargetChosenReceiver.sendCallback(false, e.getMessage());
163
+ TargetChosenReceiver.callbackReject(e.getMessage());
168
164
  }
169
165
  }
170
166
 
171
- @ReactMethod
172
- public void shareSingle(ReadableMap options, @Nullable Callback failureCallback, @Nullable Callback successCallback) {
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"), this.reactContext);
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
- System.out.println("ERROR " + ex.getMessage());
178
+ Log.e(NAME,ex.getMessage());
185
179
  ex.printStackTrace(System.out);
186
- TargetChosenReceiver.sendCallback(false, ex.getMessage());
180
+ TargetChosenReceiver.callbackReject(ex.getMessage());
187
181
  } catch (Exception e) {
188
- System.out.println("ERROR " + e.getMessage());
182
+ Log.e(NAME,e.getMessage());
189
183
  e.printStackTrace(System.out);
190
- TargetChosenReceiver.sendCallback(false, e.getMessage());
184
+ TargetChosenReceiver.callbackReject(e.getMessage());
191
185
  }
192
186
  } else {
193
- TargetChosenReceiver.sendCallback(false, "key 'social' missing in options");
187
+ TargetChosenReceiver.callbackReject("key 'social' missing in options");
194
188
  }
195
189
  }
196
190
 
197
- @ReactMethod
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, this.reactContext);
201
- successCallback.invoke(res);
193
+ boolean res = ShareIntent.isPackageInstalled(packagename, RCTContext);
194
+ promise.resolve(res);
202
195
  } catch (Exception e) {
203
- System.out.println("Error: " + e.getMessage());
204
- failureCallback.invoke(e.getMessage());
196
+ Log.e(NAME,e.getMessage());
197
+ promise.reject(e.getMessage());
205
198
  }
206
199
  }
207
200
 
208
- @ReactMethod
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
- successCallback.invoke(true);
206
+ promise.resolve(true);
215
207
  } else {
216
- successCallback.invoke(false);
208
+ promise.resolve(false);
217
209
  }
218
210
  } catch (Exception e) {
219
- System.out.println("ERROR " + e.getMessage());
211
+ Log.e(NAME,e.getMessage());
220
212
  e.printStackTrace(System.out);
221
- failureCallback.invoke(e.getMessage());
213
+ promise.reject(e.getMessage());
222
214
  }
223
215
  }
224
216
  }
@@ -1,27 +1,44 @@
1
1
  package cl.json;
2
2
 
3
- import java.util.Arrays;
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.uimanager.ViewManager;
11
- import com.facebook.react.bridge.JavaScriptModule;
12
- public class RNSharePackage implements ReactPackage {
13
- @Override
14
- public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
- return Arrays.<NativeModule>asList(new RNShareModule(reactContext));
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
- // Deprecated from RN 0.47.0
19
- public List<Class<? extends JavaScriptModule>> createJSModules() {
20
- return Collections.emptyList();
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 List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
25
- return Collections.emptyList();
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.sendCallback(false, "Something went wrong");
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
- TargetChosenReceiver.sendCallback(true, true, this.getIntent().getPackage());
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.sendCallback(false, "Something went wrong");
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.RNShareModule;
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.sendCallback(false, "Something went wrong");
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, RNShareModule.SHARE_REQUEST_CODE);
287
+ activity.startActivityForResult(chooser, RNShareImpl.SHARE_REQUEST_CODE);
286
288
  } else {
287
- activity.startActivityForResult(excludeChooserIntent(this.getIntent(),options), RNShareModule.SHARE_REQUEST_CODE);
289
+ activity.startActivityForResult(excludeChooserIntent(this.getIntent(),options), RNShareImpl.SHARE_REQUEST_CODE);
288
290
  }
289
291
  } else {
290
- activity.startActivityForResult(chooser, RNShareModule.SHARE_REQUEST_CODE);
292
+ activity.startActivityForResult(chooser, RNShareImpl.SHARE_REQUEST_CODE);
291
293
  }
292
294
 
293
295
  if (intentSender == null) {
294
- TargetChosenReceiver.sendCallback(true, true, "OK");
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.RNShareModule;
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.sendCallback(false, "Something went wrong");
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, RNShareModule.SHARE_REQUEST_CODE);
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, RNShareModule.SHARE_REQUEST_CODE);
87
- TargetChosenReceiver.sendCallback(true, true, "OK");
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
- TargetChosenReceiver.sendCallback(true, true, this.getIntent().getPackage());
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.Callback;
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 Callback successCallback;
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(Callback success, Callback failure) {
34
- successCallback = success;
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
- sendCallback(true, true, target.flattenToString());
79
+ reply.putString("message", target.flattenToString());
80
+
78
81
  } else {
79
- sendCallback(true, true, "OK");
82
+ reply.putString("message", "OK");
80
83
  }
84
+ callbackResolve(reply);
81
85
  }
82
86
 
83
- public static void sendCallback(boolean isSuccess, Object... reply) {
84
- if (isSuccess) {
85
- if (successCallback != null) {
86
- successCallback.invoke(reply);
87
- }
88
- } else if (failureCallback != null) {
89
- failureCallback.invoke(reply);
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
- successCallback = null;
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 failureCallback:(RCTResponseErrorBlock)failureCallback successCallback:(RCTResponseSenderBlock)successCallback;
24
+ - (void) shareSingle:(NSDictionary *)options reject:(RCTPromiseRejectBlock)reject resolve:(RCTPromiseResolveBlock)resolve;
25
25
  @end