react-native-share 12.0.6 → 12.0.8

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.
@@ -19,23 +19,18 @@ RCT_EXPORT_MODULE();
19
19
  // Putting dictionary of options inside an array
20
20
  NSArray *pasteboardItems = @[items];
21
21
  NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]};
22
-
22
+
23
23
  [[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions];
24
24
  [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil];
25
-
25
+
26
26
  resolve(@[@true, @""]);
27
27
  }
28
28
 
29
29
  - (void)shareSingle:(NSDictionary *)options
30
30
  reject:(RCTPromiseRejectBlock)reject
31
31
  resolve:(RCTPromiseResolveBlock)resolve {
32
-
32
+
33
33
  NSURL *urlScheme = [NSURL URLWithString:[NSString stringWithFormat:@"instagram-stories://share?source_application=%@", options[@"appId"]]];
34
- if (![[UIApplication sharedApplication] canOpenURL:urlScheme]) {
35
- NSError* error = [self fallbackInstagram];
36
- reject(@"cannot open URL",@"cannot open URL",error);
37
- return;
38
- }
39
34
 
40
35
  // Create dictionary of assets and attribution
41
36
  NSMutableDictionary *items = [NSMutableDictionary dictionary];
@@ -85,50 +80,63 @@ RCT_EXPORT_MODULE();
85
80
 
86
81
  if(![options[@"backgroundVideo"] isEqual:[NSNull null]] && options[@"backgroundVideo"] != nil) {
87
82
  NSURL *backgroundVideoURL = [RCTConvert NSURL:options[@"backgroundVideo"]];
88
- NSString *urlString = backgroundVideoURL.absoluteString;
89
- NSURLComponents *components = [[NSURLComponents alloc] initWithString:urlString];
90
- NSString *assetId = nil;
91
-
92
- // Get asset ID from URL
93
- for (NSURLQueryItem *item in components.queryItems) {
94
- if ([item.name isEqualToString:@"id"]) {
95
- assetId = item.value;
96
- break;
97
- }
98
- }
99
83
 
100
- if (assetId) {
101
- // Fetch the asset
102
- PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:nil];
103
- PHAsset *asset = fetchResult.firstObject;
104
-
105
- if (asset) {
106
- PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
107
- options.networkAccessAllowed = YES;
108
- options.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
109
-
110
- [[PHImageManager defaultManager] requestAVAssetForVideo:asset
111
- options:options
112
- resultHandler:^(AVAsset * _Nullable avAsset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
113
- if ([avAsset isKindOfClass:[AVURLAsset class]]) {
114
- AVURLAsset *urlAsset = (AVURLAsset *)avAsset;
115
- NSData *video = [NSData dataWithContentsOfURL:urlAsset.URL];
116
-
117
- dispatch_async(dispatch_get_main_queue(), ^{
118
- if (video) {
119
- [items setObject:video forKey:@"com.instagram.sharedSticker.backgroundVideo"];
120
- [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
121
- } else {
122
- NSLog(@"Failed to convert video asset to NSData");
123
- [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
124
- }
125
- });
126
- }
127
- }];
128
- } else {
129
- NSLog(@"Could not find asset with ID: %@", assetId);
130
- [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
131
- }
84
+ if ([backgroundVideoURL.scheme isEqualToString:@"file"]) {
85
+ // Handle local file
86
+ NSData *videoData = [NSData dataWithContentsOfURL:backgroundVideoURL];
87
+ if (videoData) {
88
+ [items setObject:videoData forKey:@"com.instagram.sharedSticker.backgroundVideo"];
89
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
90
+ } else {
91
+ NSLog(@"Failed to read local video file");
92
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
93
+ }
94
+ } else {
95
+ NSString *urlString = backgroundVideoURL.absoluteString;
96
+ NSURLComponents *components = [[NSURLComponents alloc] initWithString:urlString];
97
+ NSString *assetId = nil;
98
+
99
+ // Get asset ID from URL
100
+ for (NSURLQueryItem *item in components.queryItems) {
101
+ if ([item.name isEqualToString:@"id"]) {
102
+ assetId = item.value;
103
+ break;
104
+ }
105
+ }
106
+
107
+ if (assetId) {
108
+ // Fetch the asset
109
+ PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:nil];
110
+ PHAsset *asset = fetchResult.firstObject;
111
+
112
+ if (asset) {
113
+ PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
114
+ options.networkAccessAllowed = YES;
115
+ options.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
116
+
117
+ [[PHImageManager defaultManager] requestAVAssetForVideo:asset
118
+ options:options
119
+ resultHandler:^(AVAsset * _Nullable avAsset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
120
+ if ([avAsset isKindOfClass:[AVURLAsset class]]) {
121
+ AVURLAsset *urlAsset = (AVURLAsset *)avAsset;
122
+ NSData *video = [NSData dataWithContentsOfURL:urlAsset.URL];
123
+
124
+ dispatch_async(dispatch_get_main_queue(), ^{
125
+ if (video) {
126
+ [items setObject:video forKey:@"com.instagram.sharedSticker.backgroundVideo"];
127
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
128
+ } else {
129
+ NSLog(@"Failed to convert video asset to NSData");
130
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
131
+ }
132
+ });
133
+ }
134
+ }];
135
+ } else {
136
+ NSLog(@"Could not find asset with ID: %@", assetId);
137
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
138
+ }
139
+ }
132
140
  }
133
141
  } else {
134
142
  [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
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.6",
4
+ "version": "12.0.8",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/react-native-community/react-native-share.git"
@@ -62,7 +62,9 @@
62
62
  "react-native-windows": "^0.72.19",
63
63
  "react-test-renderer": "^18.2.0",
64
64
  "semantic-release": "^22.0.7",
65
- "typescript": "^5.2.2"
65
+ "typescript": "^5.2.2",
66
+ "patch-package": "^8.0.0",
67
+ "postinstall-postinstall": "^2.1.0"
66
68
  },
67
69
  "resolutions": {
68
70
  "eslint-plugin-prettier": "5.0.1",
@@ -92,6 +94,7 @@
92
94
  },
93
95
  "readmeFilename": "README.md",
94
96
  "scripts": {
97
+ "postinstall": "patch-package",
95
98
  "start": "react-native start",
96
99
  "start:android": "react-native run-android",
97
100
  "start:ios": "react-native run-ios",
@@ -154,5 +157,6 @@
154
157
  },
155
158
  "engines": {
156
159
  "node": ">=16"
157
- }
160
+ },
161
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
158
162
  }