react-native-share 12.0.10 → 12.1.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.
@@ -14,9 +14,9 @@
14
14
  - (void)shareSingle:(NSDictionary *)options
15
15
  reject:(RCTPromiseRejectBlock)reject
16
16
  resolve:(RCTPromiseResolveBlock)resolve {
17
-
17
+
18
18
  NSLog(@"Try open view");
19
-
19
+
20
20
  NSURL * shareURL;
21
21
  float videoDurationSeconds = 0.0f;
22
22
  NSString* url = options[@"url"];
@@ -25,13 +25,13 @@
25
25
  AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
26
26
  CMTime videoDuration = videoAsset.duration;
27
27
  float videoDurationSeconds = CMTimeGetSeconds(videoDuration);
28
-
28
+
29
29
  NSLog(@"Video duration: %f seconds for file %@", videoDurationSeconds, videoAsset.URL.absoluteString);
30
30
  } else {
31
31
  //this will send message directly to instagram DM with plain text
32
32
  shareURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://sharesheet?text=%@", options[@"message"]]];
33
33
  }
34
-
34
+
35
35
  if (shareURL) {
36
36
  NSLog(@"url is already available, no need to do anything");
37
37
  } else if (videoDurationSeconds <= 60.0f) {
@@ -42,7 +42,7 @@
42
42
  } else {
43
43
  shareURL = [NSURL URLWithString:@"instagram://camera"];
44
44
  }
45
-
45
+
46
46
  if ([[UIApplication sharedApplication] canOpenURL: shareURL]) {
47
47
  [[UIApplication sharedApplication] openURL:shareURL options:@{} completionHandler:nil];
48
48
  resolve(@[@true, @""]);
@@ -50,22 +50,22 @@
50
50
  // Cannot open instagram
51
51
  NSString *stringURL = @"https://itunes.apple.com/app/instagram/id389801252";
52
52
  NSURL *url = [NSURL URLWithString:stringURL];
53
-
53
+
54
54
  [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {}];
55
-
55
+
56
56
  NSString *errorMessage = @"Not installed";
57
57
  NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: NSLocalizedString(errorMessage, nil)};
58
58
  NSError *error = [NSError errorWithDomain:@"com.rnshare" code:1 userInfo:userInfo];
59
-
59
+
60
60
  NSLog(@"%@", errorMessage);
61
61
  reject(@"com.rnshare",@"Not installed",error);
62
- }
62
+ }
63
63
  }
64
64
 
65
65
  - (void)shareSingleImage:(NSDictionary *)options
66
66
  reject:(RCTPromiseRejectBlock)reject
67
67
  resolve:(RCTPromiseResolveBlock)resolve {
68
-
68
+
69
69
  UIImage *image;
70
70
  NSURL *imageURL = [RCTConvert NSURL:options[@"url"]];
71
71
  if (imageURL) {
@@ -92,22 +92,45 @@
92
92
  -(void)savePictureAndOpenInstagram:(UIImage *)base64Image
93
93
  reject:(RCTPromiseRejectBlock)reject
94
94
  resolve:(RCTPromiseResolveBlock)resolve {
95
-
95
+
96
+ // Check for photo library permissions
97
+ PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
98
+ if (status == PHAuthorizationStatusNotDetermined) {
99
+ [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus newStatus) {
100
+ dispatch_async(dispatch_get_main_queue(), ^{
101
+ if (newStatus == PHAuthorizationStatusAuthorized) {
102
+ [self savePictureAndOpenInstagram:base64Image reject:reject resolve:resolve];
103
+ } else {
104
+ if (reject != NULL) {
105
+ reject(@"com.rnshare", @"Photo library access denied by user", nil);
106
+ }
107
+ }
108
+ });
109
+ }];
110
+ return;
111
+ } else if (status != PHAuthorizationStatusAuthorized) {
112
+
113
+ if (reject != NULL) {
114
+ reject(@"com.rnshare", @"Photo library access not authorized", nil);
115
+ }
116
+ return;
117
+ }
118
+
96
119
  NSURL *URL = [self fileURLWithTemporaryImageData:UIImageJPEGRepresentation(base64Image, 0.9)];
97
120
  __block PHAssetChangeRequest *_mChangeRequest = nil;
98
121
  __block PHObjectPlaceholder *placeholder;
99
-
122
+
100
123
  [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
101
-
124
+
102
125
  NSData *pngData = [NSData dataWithContentsOfURL:URL];
103
126
  UIImage *image = [UIImage imageWithData:pngData];
104
127
  _mChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
105
128
  placeholder = _mChangeRequest.placeholderForCreatedAsset;
106
129
  } completionHandler:^(BOOL success, NSError *error) {
107
-
130
+
108
131
  if (success) {
109
132
  NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?LocalIdentifier=\%@", [placeholder localIdentifier]]];
110
-
133
+
111
134
  if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
112
135
  if (@available(iOS 10.0, *)) {
113
136
  [[UIApplication sharedApplication] openURL:instagramURL options:@{} completionHandler:NULL];
package/ios/RNShare.mm CHANGED
@@ -18,6 +18,7 @@
18
18
  #import "GooglePlusShare.h"
19
19
  #import "EmailShare.h"
20
20
  #import "TelegramShare.h"
21
+ #import "TwitterShare.h"
21
22
  #import "ViberShare.h"
22
23
  #import "MessengerShare.h"
23
24
  #import "SmsShare.h"
@@ -153,10 +154,14 @@ RCT_EXPORT_METHOD(shareSingle:(NSDictionary *)options
153
154
  NSLog(@"TRY OPEN instagram-stories");
154
155
  InstagramStories *shareCtl = [[InstagramStories alloc] init];
155
156
  [shareCtl shareSingle:options reject: reject resolve: resolve];
156
- } else if([social isEqualToString:@"telegram"]) {
157
+ } else if([social isEqualToString:@"telegram"]) {
157
158
  NSLog(@"TRY OPEN telegram");
158
159
  TelegramShare *shareCtl = [[TelegramShare alloc] init];
159
160
  [shareCtl shareSingle:options reject: reject resolve: resolve];
161
+ } else if([social isEqualToString:@"twitter"]) {
162
+ NSLog(@"TRY OPEN twitter");
163
+ TwitterShare *shareCtl = [[TwitterShare alloc] init];
164
+ [shareCtl shareSingle:options reject: reject resolve: resolve];
160
165
  } else if([social isEqualToString:@"email"]) {
161
166
  NSLog(@"TRY OPEN email");
162
167
  [shareCtl shareSingle:options reject: reject resolve: resolve];
@@ -0,0 +1,23 @@
1
+ //
2
+ // TwitterShare.h
3
+ // RNShare
4
+ //
5
+ // Created by Akinn Rosa on 06-06-25.
6
+ //
7
+
8
+ #import <UIKit/UIKit.h>
9
+ // import RCTConvert
10
+ #import <React/RCTConvert.h>
11
+ // import RCTBridge
12
+ #import <React/RCTBridge.h>
13
+ // import RCTUIManager
14
+ #import <React/RCTUIManager.h>
15
+ // import RCTLog
16
+ #import <React/RCTLog.h>
17
+ // import RCTUtils
18
+ #import <React/RCTUtils.h>
19
+ @interface TwitterShare : NSObject <RCTBridgeModule>
20
+
21
+ - (void) shareSingle:(NSDictionary *)options reject:(RCTPromiseRejectBlock)reject resolve:(RCTPromiseResolveBlock)resolve;
22
+
23
+ @end
@@ -0,0 +1,48 @@
1
+ //
2
+ // TwitterShare.m
3
+ // RNShare
4
+ //
5
+ // Created by Akinn Rosa on 06-06-25.
6
+ //
7
+
8
+ #import "TwitterShare.h"
9
+ #import <AVFoundation/AVFoundation.h>
10
+ @import Photos;
11
+
12
+ @implementation TwitterShare
13
+ RCT_EXPORT_MODULE();
14
+
15
+ - (void)shareSingle:(NSDictionary *)options
16
+ reject:(RCTPromiseRejectBlock)reject
17
+ resolve:(RCTPromiseResolveBlock)resolve {
18
+
19
+ NSString *text = [RCTConvert NSString:options[@"message"]];
20
+ NSString *url = [RCTConvert NSString:options[@"url"]];
21
+
22
+ // URL encode text and url
23
+ NSString *encodedText = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
24
+ NULL, (CFStringRef)text, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8));
25
+
26
+ NSString *encodedUrl = url ? (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
27
+ NULL, (CFStringRef)url, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8)) : nil;
28
+
29
+ // First try deep link to app
30
+ NSString *appUrlString = [NSString stringWithFormat:@"twitter://post?message=%@", encodedText];
31
+ NSURL *appUrl = [NSURL URLWithString:appUrlString];
32
+
33
+ if ([[UIApplication sharedApplication] canOpenURL:appUrl]) {
34
+ [[UIApplication sharedApplication] openURL:appUrl options:@{} completionHandler:^(BOOL success) {}];
35
+ resolve(@[@true, @"opened in twitter app"]);
36
+ } else {
37
+ // Fallback to web intent
38
+ NSString *webUrlString = url ?
39
+ [NSString stringWithFormat:@"https://twitter.com/intent/tweet?text=%@&url=%@", encodedText, encodedUrl] :
40
+ [NSString stringWithFormat:@"https://twitter.com/intent/tweet?text=%@", encodedText];
41
+
42
+ NSURL *webUrl = [NSURL URLWithString:webUrlString];
43
+ [[UIApplication sharedApplication] openURL:webUrl options:@{} completionHandler:^(BOOL success) {}];
44
+ resolve(@[@true, @"opened in browser"]);
45
+ }
46
+ }
47
+
48
+ @end
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": "12.0.10",
4
+ "version": "12.1.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/react-native-community/react-native-share.git"