react-native-share 12.0.5 → 12.0.7

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/README.md CHANGED
@@ -33,7 +33,8 @@ Configure you `app.config.ts` or `app.json` to use the permissions needed by the
33
33
  "com.instagram.android",
34
34
  "com.twitter.android",
35
35
  "com.zhiliaoapp.musically",
36
- ]
36
+ ],
37
+ "enableBase64ShareAndroid": true
37
38
  }
38
39
  ]
39
40
  ]
@@ -63,6 +64,12 @@ Configure you `app.config.ts` or `app.json` to use the permissions needed by the
63
64
  </queries>
64
65
  ```
65
66
 
67
+ `enableBase64ShareAndroid` will take care of adding the permission to the AndroidManifest.xml.
68
+
69
+ ```xml
70
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
71
+ ```
72
+
66
73
  And prebuild the project with `expo prebuild`.
67
74
 
68
75
  ## Bare React Native
@@ -19,17 +19,17 @@ 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
34
  if (![[UIApplication sharedApplication] canOpenURL:urlScheme]) {
35
35
  NSError* error = [self fallbackInstagram];
@@ -85,50 +85,63 @@ RCT_EXPORT_MODULE();
85
85
 
86
86
  if(![options[@"backgroundVideo"] isEqual:[NSNull null]] && options[@"backgroundVideo"] != nil) {
87
87
  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
88
 
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
- }
89
+ if ([backgroundVideoURL.scheme isEqualToString:@"file"]) {
90
+ // Handle local file
91
+ NSData *videoData = [NSData dataWithContentsOfURL:backgroundVideoURL];
92
+ if (videoData) {
93
+ [items setObject:videoData forKey:@"com.instagram.sharedSticker.backgroundVideo"];
94
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
95
+ } else {
96
+ NSLog(@"Failed to read local video file");
97
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
98
+ }
99
+ } else {
100
+ NSString *urlString = backgroundVideoURL.absoluteString;
101
+ NSURLComponents *components = [[NSURLComponents alloc] initWithString:urlString];
102
+ NSString *assetId = nil;
103
+
104
+ // Get asset ID from URL
105
+ for (NSURLQueryItem *item in components.queryItems) {
106
+ if ([item.name isEqualToString:@"id"]) {
107
+ assetId = item.value;
108
+ break;
109
+ }
110
+ }
111
+
112
+ if (assetId) {
113
+ // Fetch the asset
114
+ PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:nil];
115
+ PHAsset *asset = fetchResult.firstObject;
116
+
117
+ if (asset) {
118
+ PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
119
+ options.networkAccessAllowed = YES;
120
+ options.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
121
+
122
+ [[PHImageManager defaultManager] requestAVAssetForVideo:asset
123
+ options:options
124
+ resultHandler:^(AVAsset * _Nullable avAsset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
125
+ if ([avAsset isKindOfClass:[AVURLAsset class]]) {
126
+ AVURLAsset *urlAsset = (AVURLAsset *)avAsset;
127
+ NSData *video = [NSData dataWithContentsOfURL:urlAsset.URL];
128
+
129
+ dispatch_async(dispatch_get_main_queue(), ^{
130
+ if (video) {
131
+ [items setObject:video forKey:@"com.instagram.sharedSticker.backgroundVideo"];
132
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
133
+ } else {
134
+ NSLog(@"Failed to convert video asset to NSData");
135
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
136
+ }
137
+ });
138
+ }
139
+ }];
140
+ } else {
141
+ NSLog(@"Could not find asset with ID: %@", assetId);
142
+ [self openInstagramWithItems:items urlScheme:urlScheme resolve:resolve];
143
+ }
144
+ }
132
145
  }
133
146
  } else {
134
147
  [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.5",
4
+ "version": "12.0.7",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/react-native-community/react-native-share.git"
@@ -48,6 +48,7 @@
48
48
  "babel-jest": "^29.7.0",
49
49
  "eslint": "^8.53.0",
50
50
  "eslint-config-satya164": "^3.2.0",
51
+ "expo-build-properties": "^0.13.1",
51
52
  "husky": "^4.3.0",
52
53
  "jest": "^29.7.0",
53
54
  "lint-staged": "^15.0.2",
@@ -61,7 +62,9 @@
61
62
  "react-native-windows": "^0.72.19",
62
63
  "react-test-renderer": "^18.2.0",
63
64
  "semantic-release": "^22.0.7",
64
- "typescript": "^5.2.2"
65
+ "typescript": "^5.2.2",
66
+ "patch-package": "^8.0.0",
67
+ "postinstall-postinstall": "^2.1.0"
65
68
  },
66
69
  "resolutions": {
67
70
  "eslint-plugin-prettier": "5.0.1",
@@ -91,6 +94,7 @@
91
94
  },
92
95
  "readmeFilename": "README.md",
93
96
  "scripts": {
97
+ "postinstall": "patch-package",
94
98
  "start": "react-native start",
95
99
  "start:android": "react-native run-android",
96
100
  "start:ios": "react-native run-ios",
@@ -153,5 +157,6 @@
153
157
  },
154
158
  "engines": {
155
159
  "node": ">=16"
156
- }
160
+ },
161
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
157
162
  }
@@ -1 +1,7 @@
1
- export {};
1
+ import { ExportedConfig } from '@expo/config-plugins';
2
+ declare const _default: (config: ExportedConfig, props: {
3
+ enableBase64ShareAndroid?: boolean;
4
+ android?: string[];
5
+ ios?: string[];
6
+ }) => any;
7
+ export default _default;
@@ -1,84 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const config_plugins_1 = require("@expo/config-plugins");
4
- // eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-var-requires
5
- const pkg = require('../../package.json');
3
+ const expo_build_properties_1 = require("expo-build-properties");
6
4
  /**
7
- * @type {import('./types').ManifestQueries}
8
- * what we are trying to add:
9
- * <queries>
10
- <package android:name="com.facebook.katana"/>
11
- <package android:name="com.instagram.android"/>
12
- <package android:name="com.twitter.android"/>
13
- <package android:name="com.zhiliaoapp.musically"/>
14
- <intent></intent>
15
- <action android:name="android.intent.action.VIEW"/>
16
- <category android:name="android.intent.category.BROWSABLE"/>
17
- <data android:scheme="https"/>
18
- </intent>
19
- </queries>
5
+ * Handles for edge case when LSApplicationQueriesSchemes is an object or undefined.
20
6
  */
21
- /**
22
- * @param {import('@expo/config-plugins').ExportedConfig} config
23
- */
24
- const withAndroidManifestService = (config, props) => {
25
- return (0, config_plugins_1.withAndroidManifest)(config, (config) => {
26
- config.modResults.manifest = {
27
- ...config.modResults.manifest,
28
- queries: {
29
- package: props?.android?.map((social) => ({
30
- $: {
31
- 'android:name': social,
32
- },
33
- })),
34
- intent: [
35
- {
36
- action: {
37
- $: {
38
- 'android:name': 'android.intent.action.VIEW',
39
- },
40
- },
41
- category: {
42
- $: {
43
- 'android:name': 'android.intent.category.BROWSABLE',
44
- },
45
- },
46
- data: {
47
- $: {
48
- 'android:scheme': 'https',
49
- },
50
- },
51
- },
52
- ],
53
- },
54
- };
55
- return config;
56
- });
57
- };
58
- /**
59
- * Handles for edge case when LSApplicationQueriesSchemes is an object or undefined.
60
- */
61
7
  const getIOSQuerySchemes = (config) => {
62
8
  return Array.isArray(config.ios?.infoPlist?.LSApplicationQueriesSchemes)
63
9
  ? config.ios?.infoPlist?.LSApplicationQueriesSchemes ?? []
64
10
  : [];
65
11
  };
66
- const withInfoPlist = (config, props) => {
67
- return {
12
+ exports.default = (config, props) => {
13
+ return (0, expo_build_properties_1.withBuildProperties)({
68
14
  ...config,
15
+ android: {
16
+ ...config.android,
17
+ ...(props.enableBase64ShareAndroid
18
+ ? {
19
+ permissions: [
20
+ ...new Set([
21
+ ...(config.android?.permissions ?? []),
22
+ 'android.permission.WRITE_EXTERNAL_STORAGE',
23
+ ]),
24
+ ],
25
+ }
26
+ : {}),
27
+ },
69
28
  ios: {
70
29
  ...config.ios,
71
30
  infoPlist: {
72
31
  ...config.ios?.infoPlist,
73
- LSApplicationQueriesSchemes: [...getIOSQuerySchemes(config), ...props?.ios ?? []]
32
+ LSApplicationQueriesSchemes: [...getIOSQuerySchemes(config), ...(props?.ios ?? [])],
74
33
  },
75
34
  },
76
- };
35
+ }, {
36
+ android: {
37
+ manifestQueries: {
38
+ package: props.android ?? [],
39
+ },
40
+ },
41
+ });
77
42
  };
78
- function withSocialShare(config, props) {
79
- config = withAndroidManifestService(config, props); // Android
80
- config = withInfoPlist(config, props); // iOS
81
- return config;
82
- }
83
- // eslint-disable-next-line import/no-commonjs
84
- module.exports = (0, config_plugins_1.createRunOncePlugin)(withSocialShare, pkg.name, pkg.version);
@@ -1,100 +1,53 @@
1
- import {
2
- withAndroidManifest,
3
- createRunOncePlugin,
4
- ExportedConfigWithProps,
5
- ExportedConfig,
6
- } from '@expo/config-plugins';
7
-
8
- // eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-var-requires
9
- const pkg = require('../../package.json');
1
+ import { ExportedConfig } from '@expo/config-plugins';
2
+ import { withBuildProperties } from 'expo-build-properties';
10
3
 
11
4
  /**
12
- * @type {import('./types').ManifestQueries}
13
- * what we are trying to add:
14
- * <queries>
15
- <package android:name="com.facebook.katana"/>
16
- <package android:name="com.instagram.android"/>
17
- <package android:name="com.twitter.android"/>
18
- <package android:name="com.zhiliaoapp.musically"/>
19
- <intent></intent>
20
- <action android:name="android.intent.action.VIEW"/>
21
- <category android:name="android.intent.category.BROWSABLE"/>
22
- <data android:scheme="https"/>
23
- </intent>
24
- </queries>
5
+ * Handles for edge case when LSApplicationQueriesSchemes is an object or undefined.
25
6
  */
26
-
27
- /**
28
- * @param {import('@expo/config-plugins').ExportedConfig} config
29
- */
30
- const withAndroidManifestService = (config: ExportedConfig, props: WithSocialShareProps) => {
31
- return withAndroidManifest(config, (config: ExportedConfigWithProps) => {
32
- config.modResults.manifest = {
33
- ...config.modResults.manifest,
34
- queries: {
35
- package: props?.android?.map((social) => ({
36
- $: {
37
- 'android:name': social,
38
- },
39
- })),
40
- intent: [
41
- {
42
- action: {
43
- $: {
44
- 'android:name': 'android.intent.action.VIEW',
45
- },
46
- },
47
- category: {
48
- $: {
49
- 'android:name': 'android.intent.category.BROWSABLE',
50
- },
51
- },
52
- data: {
53
- $: {
54
- 'android:scheme': 'https',
55
- },
56
- },
57
- },
58
- ],
59
- },
60
- };
61
-
62
- return config;
63
- });
64
- };
65
-
66
- /**
67
- * Handles for edge case when LSApplicationQueriesSchemes is an object or undefined.
68
- */
69
- const getIOSQuerySchemes = (config: ExportedConfig): Array<string> => {
7
+ const getIOSQuerySchemes = (config: ExportedConfig): string[] => {
70
8
  return Array.isArray(config.ios?.infoPlist?.LSApplicationQueriesSchemes)
71
9
  ? config.ios?.infoPlist?.LSApplicationQueriesSchemes ?? []
72
10
  : [];
73
- }
11
+ };
74
12
 
75
- const withInfoPlist = (config: ExportedConfig, props: WithSocialShareProps) => {
76
- return {
77
- ...config,
78
- ios: {
79
- ...config.ios,
80
- infoPlist: {
81
- ...config.ios?.infoPlist,
82
- LSApplicationQueriesSchemes: [...getIOSQuerySchemes(config), ...props?.ios ?? []]
13
+ export default (
14
+ config: ExportedConfig,
15
+ props: {
16
+ enableBase64ShareAndroid?: boolean;
17
+ android?: string[];
18
+ ios?: string[];
19
+ },
20
+ ) => {
21
+ return withBuildProperties(
22
+ {
23
+ ...config,
24
+ android: {
25
+ ...config.android,
26
+ ...(props.enableBase64ShareAndroid
27
+ ? {
28
+ permissions: [
29
+ ...new Set([
30
+ ...(config.android?.permissions ?? []),
31
+ 'android.permission.WRITE_EXTERNAL_STORAGE',
32
+ ]),
33
+ ],
34
+ }
35
+ : {}),
36
+ },
37
+ ios: {
38
+ ...config.ios,
39
+ infoPlist: {
40
+ ...config.ios?.infoPlist,
41
+ LSApplicationQueriesSchemes: [...getIOSQuerySchemes(config), ...(props?.ios ?? [])],
42
+ },
83
43
  },
84
44
  },
85
- };
86
- };
87
-
88
- type WithSocialShareProps = {
89
- ios: string[];
90
- android: string[];
45
+ {
46
+ android: {
47
+ manifestQueries: {
48
+ package: props.android ?? [],
49
+ },
50
+ },
51
+ },
52
+ );
91
53
  };
92
-
93
- function withSocialShare(config: ExportedConfig, props: WithSocialShareProps) {
94
- config = withAndroidManifestService(config, props); // Android
95
- config = withInfoPlist(config, props); // iOS
96
- return config;
97
- }
98
-
99
- // eslint-disable-next-line import/no-commonjs
100
- module.exports = createRunOncePlugin(withSocialShare, pkg.name, pkg.version);