expo-sharing 9.2.1 → 10.0.3

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/CHANGELOG.md CHANGED
@@ -10,10 +10,34 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 9.2.1 — 2021-06-22
13
+ ## 10.0.3 — 2021-10-21
14
14
 
15
15
  _This version does not introduce any user-facing changes._
16
16
 
17
+ ## 10.0.2 — 2021-10-15
18
+
19
+ _This version does not introduce any user-facing changes._
20
+
21
+ ## 10.0.1 — 2021-10-01
22
+
23
+ _This version does not introduce any user-facing changes._
24
+
25
+ ## 10.0.0 — 2021-09-28
26
+
27
+ ### 🛠 Breaking changes
28
+
29
+ - Dropped support for iOS 11.0 ([#14383](https://github.com/expo/expo/pull/14383) by [@cruzach](https://github.com/cruzach))
30
+
31
+ ### 🐛 Bug fixes
32
+
33
+ - Fix building errors from use_frameworks! in Podfile. ([#14523](https://github.com/expo/expo/pull/14523) by [@kudo](https://github.com/kudo))
34
+
35
+ ### 💡 Others
36
+
37
+ - Migrated from `@unimodules/core` to `expo-modules-core`. ([#13757](https://github.com/expo/expo/pull/13757) by [@tsapeta](https://github.com/tsapeta))
38
+ - Rewrote Android part from Java to Kotlin ([#14010](https://github.com/expo/expo/pull/14010) by [@m1st4ke](https://github.com/m1st4ke))
39
+ - Migrated from `AsyncTask` to Kotlin coroutines. ([#14029](https://github.com/expo/expo/pull/14029) by [@m1st4ke](https://github.com/m1st4ke))
40
+
17
41
  ## 9.2.0 — 2021-06-16
18
42
 
19
43
  ### 🐛 Bug fixes
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '9.2.1'
6
+ version = '10.0.3'
7
7
 
8
8
  buildscript {
9
9
  // Simple helper that allows the root project to override versions declared by this library.
@@ -53,28 +53,23 @@ android {
53
53
  targetCompatibility JavaVersion.VERSION_1_8
54
54
  }
55
55
 
56
+ kotlinOptions {
57
+ jvmTarget = JavaVersion.VERSION_1_8
58
+ }
59
+
56
60
  defaultConfig {
57
61
  minSdkVersion safeExtGet("minSdkVersion", 21)
58
62
  targetSdkVersion safeExtGet("targetSdkVersion", 30)
59
63
  versionCode 16
60
- versionName '9.2.1'
64
+ versionName '10.0.3'
61
65
  }
62
66
  lintOptions {
63
67
  abortOnError false
64
68
  }
65
69
  }
66
70
 
67
- if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
68
- apply from: project(":unimodules-core").file("../unimodules-core.gradle")
69
- } else {
70
- throw new GradleException(
71
- "'unimodules-core.gradle' was not found in the usual React Native dependency location. " +
72
- "This package can only be used in such projects. Are you sure you've installed the dependencies properly?")
73
- }
74
-
75
71
  dependencies {
76
- unimodule 'unimodules-core'
77
- unimodule 'expo-modules-core'
72
+ implementation project(':expo-modules-core')
78
73
 
79
74
  api "androidx.legacy:legacy-support-v4:1.0.0"
80
75
 
@@ -0,0 +1,5 @@
1
+ package expo.modules.sharing
2
+
3
+ import androidx.core.content.FileProvider
4
+
5
+ class SharingFileProvider : FileProvider()
@@ -0,0 +1,126 @@
1
+ package expo.modules.sharing
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.content.Intent
6
+ import android.content.pm.PackageManager
7
+ import android.net.Uri
8
+ import android.os.Bundle
9
+ import androidx.core.content.FileProvider
10
+ import expo.modules.core.ExportedModule
11
+ import expo.modules.core.ModuleRegistry
12
+ import expo.modules.core.ModuleRegistryDelegate
13
+ import expo.modules.core.Promise
14
+ import expo.modules.core.arguments.ReadableArguments
15
+ import expo.modules.core.errors.InvalidArgumentException
16
+ import expo.modules.core.interfaces.ActivityEventListener
17
+ import expo.modules.core.interfaces.ActivityProvider
18
+ import expo.modules.core.interfaces.ExpoMethod
19
+ import expo.modules.core.interfaces.services.UIManager
20
+ import expo.modules.interfaces.filesystem.FilePermissionModuleInterface
21
+ import expo.modules.interfaces.filesystem.Permission
22
+ import java.io.File
23
+ import java.net.URLConnection
24
+
25
+ class SharingModule(
26
+ context: Context,
27
+ private val moduleRegistryDelegate: ModuleRegistryDelegate = ModuleRegistryDelegate()
28
+ ) : ExportedModule(context), ActivityEventListener {
29
+ private var pendingPromise: Promise? = null
30
+ private val uiManager: UIManager by moduleRegistry()
31
+ override fun getName() = "ExpoSharing"
32
+
33
+ private inline fun <reified T> moduleRegistry() =
34
+ moduleRegistryDelegate.getFromModuleRegistry<T>()
35
+
36
+ override fun onCreate(moduleRegistry: ModuleRegistry) {
37
+ moduleRegistryDelegate.onCreate(moduleRegistry)
38
+ uiManager.registerActivityEventListener(this)
39
+ }
40
+
41
+ override fun onDestroy() {
42
+ uiManager.unregisterActivityEventListener(this)
43
+ }
44
+
45
+ @ExpoMethod
46
+ fun shareAsync(url: String?, params: ReadableArguments, promise: Promise) {
47
+ if (pendingPromise != null) {
48
+ promise.reject("ERR_SHARING_MUL", "Another share request is being processed now.")
49
+ return
50
+ }
51
+ try {
52
+ val fileToShare = getLocalFileFoUrl(url)
53
+ val contentUri = FileProvider.getUriForFile(
54
+ context,
55
+ context.applicationInfo.packageName + ".SharingFileProvider",
56
+ fileToShare
57
+ )
58
+ val mimeType = params.getString(MIME_TYPE_OPTIONS_KEY)
59
+ ?: URLConnection.guessContentTypeFromName(fileToShare.name)
60
+ ?: "*/*"
61
+ val intent = Intent.createChooser(
62
+ createSharingIntent(contentUri, mimeType),
63
+ params.getString(DIALOG_TITLE_OPTIONS_KEY)
64
+ )
65
+ val resInfoList = context.packageManager.queryIntentActivities(
66
+ intent,
67
+ PackageManager.MATCH_DEFAULT_ONLY
68
+ )
69
+ resInfoList.forEach {
70
+ val packageName = it.activityInfo.packageName
71
+ context.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
72
+ }
73
+ val activityProvider: ActivityProvider by moduleRegistry()
74
+ activityProvider.currentActivity.startActivityForResult(intent, REQUEST_CODE)
75
+ pendingPromise = promise
76
+ } catch (e: InvalidArgumentException) {
77
+ promise.reject("ERR_SHARING_URL", e.message, e)
78
+ } catch (e: Exception) {
79
+ promise.reject("ERR_SHARING", "Failed to share the file: " + e.message, e)
80
+ }
81
+ }
82
+
83
+ @Throws(InvalidArgumentException::class)
84
+ private fun getLocalFileFoUrl(url: String?): File {
85
+ if (url == null) {
86
+ throw InvalidArgumentException("URL to share cannot be null.")
87
+ }
88
+ val uri = Uri.parse(url)
89
+ if ("file" != uri.scheme) {
90
+ throw InvalidArgumentException("Only local file URLs are supported (expected scheme to be 'file', got '" + uri.scheme + "'.")
91
+ }
92
+ val path = uri.path
93
+ ?: throw InvalidArgumentException("Path component of the URL to share cannot be null.")
94
+ if (!isAllowedToRead(path)) {
95
+ throw InvalidArgumentException("Not allowed to read file under given URL.")
96
+ }
97
+ return File(path)
98
+ }
99
+
100
+ private fun isAllowedToRead(url: String?): Boolean {
101
+ val permissionModuleInterface: FilePermissionModuleInterface by moduleRegistry()
102
+ return permissionModuleInterface.getPathPermissions(context, url).contains(Permission.READ)
103
+ }
104
+
105
+ private fun createSharingIntent(uri: Uri, mimeType: String?) =
106
+ Intent(Intent.ACTION_SEND).apply {
107
+ putExtra(Intent.EXTRA_STREAM, uri)
108
+ setTypeAndNormalize(mimeType)
109
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
110
+ }
111
+
112
+ override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
113
+ if (requestCode == REQUEST_CODE && pendingPromise != null) {
114
+ pendingPromise?.resolve(Bundle.EMPTY)
115
+ pendingPromise = null
116
+ }
117
+ }
118
+
119
+ override fun onNewIntent(intent: Intent) = Unit
120
+
121
+ companion object {
122
+ private const val REQUEST_CODE = 8524
123
+ private const val MIME_TYPE_OPTIONS_KEY = "mimeType"
124
+ private const val DIALOG_TITLE_OPTIONS_KEY = "dialogTitle"
125
+ }
126
+ }
@@ -0,0 +1,9 @@
1
+ package expo.modules.sharing
2
+
3
+ import android.content.Context
4
+ import expo.modules.core.BasePackage
5
+
6
+ class SharingPackage : BasePackage() {
7
+ override fun createExportedModules(context: Context) =
8
+ listOf(SharingModule(context))
9
+ }
@@ -1,2 +1,2 @@
1
- declare const _default: import("@unimodules/core").ProxyNativeModule;
1
+ declare const _default: import("expo-modules-core").ProxyNativeModule;
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
- import { NativeModulesProxy } from '@unimodules/core';
1
+ import { NativeModulesProxy } from 'expo-modules-core';
2
2
  export default NativeModulesProxy.ExpoSharing;
3
3
  //# sourceMappingURL=ExpoSharing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoSharing.js","sourceRoot":"","sources":["../src/ExpoSharing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAe,kBAAkB,CAAC,WAAW,CAAC","sourcesContent":["import { NativeModulesProxy } from '@unimodules/core';\n\nexport default NativeModulesProxy.ExpoSharing;\n"]}
1
+ {"version":3,"file":"ExpoSharing.js","sourceRoot":"","sources":["../src/ExpoSharing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,eAAe,kBAAkB,CAAC,WAAW,CAAC","sourcesContent":["import { NativeModulesProxy } from 'expo-modules-core';\n\nexport default NativeModulesProxy.ExpoSharing;\n"]}
@@ -1,4 +1,4 @@
1
- import { UnavailabilityError } from '@unimodules/core';
1
+ import { UnavailabilityError } from 'expo-modules-core';
2
2
  export default {
3
3
  get name() {
4
4
  return 'ExpoSharing';
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoSharing.web.js","sourceRoot":"","sources":["../src/ExpoSharing.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAIvD,eAAe;IACb,IAAI,IAAI;QACN,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,KAAK,CAAC,gBAAgB;QACpB,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE;YACpC,OAAO,KAAK,CAAC;SACd;QAED,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC;IAC3B,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,GAAW,EAAE,UAAwB,EAAE;QACtD,sDAAsD;QACtD,IAAI,SAAS,CAAC,KAAK,EAAE;YACnB,MAAM,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;SAC5C;aAAM;YACL,MAAM,IAAI,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;SACrD;IACH,CAAC;CACF,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\n\ntype ShareOptions = { title?: string; text?: string; url?: string };\n\nexport default {\n get name(): string {\n return 'ExpoSharing';\n },\n async isAvailableAsync(): Promise<boolean> {\n if (typeof navigator === 'undefined') {\n return false;\n }\n\n return !!navigator.share;\n },\n async shareAsync(url: string, options: ShareOptions = {}): Promise<void> {\n // NOTE: `navigator.share` is only available via HTTPS\n if (navigator.share) {\n await navigator.share({ ...options, url });\n } else {\n throw new UnavailabilityError('navigator', 'share');\n }\n },\n};\n"]}
1
+ {"version":3,"file":"ExpoSharing.web.js","sourceRoot":"","sources":["../src/ExpoSharing.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAIxD,eAAe;IACb,IAAI,IAAI;QACN,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,KAAK,CAAC,gBAAgB;QACpB,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE;YACpC,OAAO,KAAK,CAAC;SACd;QAED,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC;IAC3B,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,GAAW,EAAE,UAAwB,EAAE;QACtD,sDAAsD;QACtD,IAAI,SAAS,CAAC,KAAK,EAAE;YACnB,MAAM,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;SAC5C;aAAM;YACL,MAAM,IAAI,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;SACrD;IACH,CAAC;CACF,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\ntype ShareOptions = { title?: string; text?: string; url?: string };\n\nexport default {\n get name(): string {\n return 'ExpoSharing';\n },\n async isAvailableAsync(): Promise<boolean> {\n if (typeof navigator === 'undefined') {\n return false;\n }\n\n return !!navigator.share;\n },\n async shareAsync(url: string, options: ShareOptions = {}): Promise<void> {\n // NOTE: `navigator.share` is only available via HTTPS\n if (navigator.share) {\n await navigator.share({ ...options, url });\n } else {\n throw new UnavailabilityError('navigator', 'share');\n }\n },\n};\n"]}
package/build/Sharing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { UnavailabilityError } from '@unimodules/core';
1
+ import { UnavailabilityError } from 'expo-modules-core';
2
2
  import Sharing from './ExpoSharing';
3
3
  // @needsAudit
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Sharing.js","sourceRoot":"","sources":["../src/Sharing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,OAAO,MAAM,eAAe,CAAC;AAmBpC,cAAc;AACd;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,OAAO,EAAE;QACX,IAAI,OAAO,CAAC,gBAAgB,EAAE;YAC5B,OAAO,MAAM,OAAO,CAAC,gBAAgB,EAAE,CAAC;SACzC;QACD,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,UAA0B,EAAE;IACxE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;QACnC,MAAM,IAAI,mBAAmB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;KACxD;IACD,OAAO,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\n\nimport Sharing from './ExpoSharing';\n\n// @needsAudit\nexport type SharingOptions = {\n /**\n * Sets `mimeType` for `Intent` *(Android only)*\n */\n mimeType?: string;\n /**\n * ([Uniform Type Identifier](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html))\n * the type of the target file *(iOS only)*\n */\n UTI?: string;\n /**\n * Sets share dialog title *(Android and Web only)*\n */\n dialogTitle?: string;\n};\n\n// @needsAudit\n/**\n * Determine if the sharing API can be used in this app.\n * @return A promise that fulfills with `true` if the sharing API can be used, and `false` otherwise.\n */\nexport async function isAvailableAsync(): Promise<boolean> {\n if (Sharing) {\n if (Sharing.isAvailableAsync) {\n return await Sharing.isAvailableAsync();\n }\n return true;\n }\n\n return false;\n}\n\n// @needsAudit\n/**\n * Opens action sheet to share file to different applications which can handle this type of file.\n * @param url Local file URL to share.\n * @param options A map of share options.\n */\nexport async function shareAsync(url: string, options: SharingOptions = {}): Promise<object> {\n if (!Sharing || !Sharing.shareAsync) {\n throw new UnavailabilityError('Sharing', 'shareAsync');\n }\n return await Sharing.shareAsync(url, options);\n}\n"]}
1
+ {"version":3,"file":"Sharing.js","sourceRoot":"","sources":["../src/Sharing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,OAAO,MAAM,eAAe,CAAC;AAmBpC,cAAc;AACd;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,OAAO,EAAE;QACX,IAAI,OAAO,CAAC,gBAAgB,EAAE;YAC5B,OAAO,MAAM,OAAO,CAAC,gBAAgB,EAAE,CAAC;SACzC;QACD,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,UAA0B,EAAE;IACxE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;QACnC,MAAM,IAAI,mBAAmB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;KACxD;IACD,OAAO,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport Sharing from './ExpoSharing';\n\n// @needsAudit\nexport type SharingOptions = {\n /**\n * Sets `mimeType` for `Intent` *(Android only)*\n */\n mimeType?: string;\n /**\n * ([Uniform Type Identifier](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html))\n * the type of the target file *(iOS only)*\n */\n UTI?: string;\n /**\n * Sets share dialog title *(Android and Web only)*\n */\n dialogTitle?: string;\n};\n\n// @needsAudit\n/**\n * Determine if the sharing API can be used in this app.\n * @return A promise that fulfills with `true` if the sharing API can be used, and `false` otherwise.\n */\nexport async function isAvailableAsync(): Promise<boolean> {\n if (Sharing) {\n if (Sharing.isAvailableAsync) {\n return await Sharing.isAvailableAsync();\n }\n return true;\n }\n\n return false;\n}\n\n// @needsAudit\n/**\n * Opens action sheet to share file to different applications which can handle this type of file.\n * @param url Local file URL to share.\n * @param options A map of share options.\n */\nexport async function shareAsync(url: string, options: SharingOptions = {}): Promise<object> {\n if (!Sharing || !Sharing.shareAsync) {\n throw new UnavailabilityError('Sharing', 'shareAsync');\n }\n return await Sharing.shareAsync(url, options);\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  // Copyright © 2018 650 Industries. All rights reserved.
2
2
 
3
- #import <UMCore/UMExportedModule.h>
4
- #import <UMCore/UMModuleRegistryConsumer.h>
3
+ #import <ExpoModulesCore/EXExportedModule.h>
4
+ #import <ExpoModulesCore/EXModuleRegistryConsumer.h>
5
5
  #import <UIKit/UIKit.h>
6
6
 
7
- @interface EXSharingModule : UMExportedModule <UMModuleRegistryConsumer, UIDocumentInteractionControllerDelegate>
7
+ @interface EXSharingModule : EXExportedModule <EXModuleRegistryConsumer, UIDocumentInteractionControllerDelegate>
8
8
  @end
@@ -1,37 +1,37 @@
1
1
  // Copyright 2018-present 650 Industries. All rights reserved.
2
2
 
3
3
  #import <EXSharing/EXSharingModule.h>
4
- #import <UMCore/UMUtilitiesInterface.h>
4
+ #import <ExpoModulesCore/EXUtilitiesInterface.h>
5
5
  #import <ExpoModulesCore/EXFileSystemInterface.h>
6
6
  #import <ExpoModulesCore/EXFilePermissionModuleInterface.h>
7
7
 
8
8
  @interface EXSharingModule ()
9
9
 
10
- @property (nonatomic, weak) UMModuleRegistry *moduleRegistry;
10
+ @property (nonatomic, weak) EXModuleRegistry *moduleRegistry;
11
11
  @property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController;
12
12
 
13
- @property (nonatomic, strong) UMPromiseResolveBlock pendingResolver;
13
+ @property (nonatomic, strong) EXPromiseResolveBlock pendingResolver;
14
14
 
15
15
  @end
16
16
 
17
17
  @implementation EXSharingModule
18
18
 
19
- UM_EXPORT_MODULE(ExpoSharing);
19
+ EX_EXPORT_MODULE(ExpoSharing);
20
20
 
21
- - (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
21
+ - (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
22
22
  {
23
23
  _moduleRegistry = moduleRegistry;
24
24
  }
25
25
 
26
- UM_EXPORT_METHOD_AS(shareAsync,
26
+ EX_EXPORT_METHOD_AS(shareAsync,
27
27
  fileUrl:(NSString *)fileUrl
28
28
  params:(NSDictionary *)params
29
- resolve:(UMPromiseResolveBlock)resolve
30
- reject:(UMPromiseRejectBlock)reject)
29
+ resolve:(EXPromiseResolveBlock)resolve
30
+ reject:(EXPromiseRejectBlock)reject)
31
31
  {
32
32
  if (_documentInteractionController) {
33
33
  NSString *errorMessage = @"Another item is being shared. Await the `shareAsync` request and then share the item again.";
34
- reject(@"E_SHARING_MUL", errorMessage, UMErrorWithMessage(errorMessage));
34
+ reject(@"E_SHARING_MUL", errorMessage, EXErrorWithMessage(errorMessage));
35
35
  return;
36
36
  }
37
37
 
@@ -40,7 +40,7 @@ UM_EXPORT_METHOD_AS(shareAsync,
40
40
  id<EXFilePermissionModuleInterface> filePermissionsModule = [_moduleRegistry getModuleImplementingProtocol:@protocol(EXFilePermissionModuleInterface)];
41
41
  if (filePermissionsModule && !([filePermissionsModule getPathPermissions:url.path] & EXFileSystemPermissionRead)) {
42
42
  NSString *errorMessage = @"You don't have access to provided file.";
43
- reject(@"E_SHARING_PERM", errorMessage, UMErrorWithMessage(errorMessage));
43
+ reject(@"E_SHARING_PERM", errorMessage, EXErrorWithMessage(errorMessage));
44
44
  return;
45
45
  }
46
46
 
@@ -48,11 +48,11 @@ UM_EXPORT_METHOD_AS(shareAsync,
48
48
  _documentInteractionController.delegate = self;
49
49
  _documentInteractionController.UTI = params[@"UTI"];
50
50
 
51
- UIViewController *viewController = [[_moduleRegistry getModuleImplementingProtocol:@protocol(UMUtilitiesInterface)] currentViewController];
51
+ UIViewController *viewController = [[_moduleRegistry getModuleImplementingProtocol:@protocol(EXUtilitiesInterface)] currentViewController];
52
52
 
53
- UM_WEAKIFY(self);
53
+ EX_WEAKIFY(self);
54
54
  dispatch_async(dispatch_get_main_queue(), ^{
55
- UM_ENSURE_STRONGIFY(self);
55
+ EX_ENSURE_STRONGIFY(self);
56
56
  UIView *rootView = [viewController view];
57
57
  if ([self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:rootView animated:YES]) {
58
58
  self.pendingResolver = resolve;
@@ -10,10 +10,10 @@ Pod::Spec.new do |s|
10
10
  s.license = package['license']
11
11
  s.author = package['author']
12
12
  s.homepage = package['homepage']
13
- s.platform = :ios, '11.0'
13
+ s.platform = :ios, '12.0'
14
14
  s.source = { git: 'https://github.com/expo/expo.git' }
15
+ s.static_framework = true
15
16
 
16
- s.dependency 'UMCore'
17
17
  s.dependency 'ExpoModulesCore'
18
18
 
19
19
  if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-sharing",
3
- "version": "9.2.1",
3
+ "version": "10.0.3",
4
4
  "description": "ExpoSharing standalone module",
5
5
  "main": "build/Sharing.js",
6
6
  "types": "build/Sharing.d.ts",
@@ -29,15 +29,12 @@
29
29
  },
30
30
  "author": "650 Industries, Inc.",
31
31
  "license": "MIT",
32
- "homepage": "https://docs.expo.io/versions/latest/sdk/sharing/",
33
- "unimodulePeerDependencies": {
34
- "@unimodules/core": "*"
35
- },
32
+ "homepage": "https://docs.expo.dev/versions/latest/sdk/sharing/",
36
33
  "dependencies": {
37
- "expo-modules-core": "~0.2.0"
34
+ "expo-modules-core": "~0.4.4"
38
35
  },
39
36
  "devDependencies": {
40
37
  "expo-module-scripts": "^2.0.0"
41
38
  },
42
- "gitHead": "6e8cfadff90f106d6321d0dd8c4158f12a973d30"
39
+ "gitHead": "4fa0497a180ae707fa860cb03858630ab7af19f4"
43
40
  }
@@ -1,3 +1,3 @@
1
- import { NativeModulesProxy } from '@unimodules/core';
1
+ import { NativeModulesProxy } from 'expo-modules-core';
2
2
 
3
3
  export default NativeModulesProxy.ExpoSharing;
@@ -1,4 +1,4 @@
1
- import { UnavailabilityError } from '@unimodules/core';
1
+ import { UnavailabilityError } from 'expo-modules-core';
2
2
 
3
3
  type ShareOptions = { title?: string; text?: string; url?: string };
4
4
 
package/src/Sharing.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UnavailabilityError } from '@unimodules/core';
1
+ import { UnavailabilityError } from 'expo-modules-core';
2
2
 
3
3
  import Sharing from './ExpoSharing';
4
4
 
@@ -1,5 +0,0 @@
1
- package expo.modules.sharing;
2
-
3
- import androidx.core.content.FileProvider;
4
-
5
- public class SharingFileProvider extends FileProvider {}
@@ -1,155 +0,0 @@
1
- package expo.modules.sharing;
2
-
3
- import android.app.Activity;
4
- import android.content.Context;
5
- import android.content.Intent;
6
- import android.content.pm.PackageManager;
7
- import android.content.pm.ResolveInfo;
8
- import android.net.Uri;
9
- import android.os.Bundle;
10
- import androidx.core.content.FileProvider;
11
-
12
- import org.unimodules.core.ExportedModule;
13
- import org.unimodules.core.ModuleRegistry;
14
- import org.unimodules.core.Promise;
15
- import org.unimodules.core.arguments.ReadableArguments;
16
- import org.unimodules.core.errors.InvalidArgumentException;
17
- import org.unimodules.core.interfaces.ActivityEventListener;
18
- import org.unimodules.core.interfaces.ActivityProvider;
19
- import org.unimodules.core.interfaces.ExpoMethod;
20
- import org.unimodules.core.interfaces.services.UIManager;
21
-
22
- import java.io.File;
23
- import java.net.URLConnection;
24
- import java.util.List;
25
-
26
- import expo.modules.interfaces.filesystem.FilePermissionModuleInterface;
27
- import expo.modules.interfaces.filesystem.Permission;
28
-
29
- public class SharingModule extends ExportedModule implements ActivityEventListener {
30
- private static final int REQUEST_CODE = 8524;
31
- private static final String TAG = "ExpoSharing";
32
- private static final String MIME_TYPE_OPTIONS_KEY = "mimeType";
33
- private static final String DIALOG_TITLE_OPTIONS_KEY = "dialogTitle";
34
-
35
- private ModuleRegistry mModuleRegistry;
36
- private Context mContext;
37
- private Promise mPendingPromise;
38
-
39
- public SharingModule(Context context) {
40
- super(context);
41
- mContext = context;
42
- }
43
-
44
- @Override
45
- public String getName() {
46
- return TAG;
47
- }
48
-
49
- @Override
50
- public void onCreate(ModuleRegistry moduleRegistry) {
51
- mModuleRegistry = moduleRegistry;
52
- UIManager uiManager = mModuleRegistry.getModule(UIManager.class);
53
- uiManager.registerActivityEventListener(this);
54
- }
55
-
56
- @Override
57
- public void onDestroy() {
58
- UIManager uiManager = mModuleRegistry.getModule(UIManager.class);
59
- uiManager.unregisterActivityEventListener(this);
60
-
61
- mModuleRegistry = null;
62
- }
63
-
64
- @ExpoMethod
65
- public void shareAsync(String url, ReadableArguments params, final Promise promise) {
66
- if (mPendingPromise != null) {
67
- promise.reject("ERR_SHARING_MUL", "Another share request is being processed now.");
68
- return;
69
- }
70
-
71
- try {
72
- File fileToShare = getLocalFileFoUrl(url);
73
- Uri contentUri = FileProvider.getUriForFile(mContext, mContext.getApplicationInfo().packageName + ".SharingFileProvider", fileToShare);
74
-
75
- String mimeType = params.getString(MIME_TYPE_OPTIONS_KEY);
76
- if (mimeType == null) {
77
- String guessedMimeType = URLConnection.guessContentTypeFromName(fileToShare.getName());
78
- if (guessedMimeType != null) {
79
- mimeType = guessedMimeType;
80
- } else {
81
- mimeType = "*/*";
82
- }
83
- }
84
-
85
- Intent intent = Intent.createChooser(createSharingIntent(contentUri, mimeType), params.getString(DIALOG_TITLE_OPTIONS_KEY));
86
-
87
- List<ResolveInfo> resInfoList = mContext.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
88
-
89
- for (ResolveInfo resolveInfo : resInfoList) {
90
- String packageName = resolveInfo.activityInfo.packageName;
91
- mContext.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
92
- }
93
-
94
- mModuleRegistry.getModule(ActivityProvider.class).getCurrentActivity().startActivityForResult(intent, REQUEST_CODE);
95
-
96
- mPendingPromise = promise;
97
- } catch (InvalidArgumentException e) {
98
- promise.reject("ERR_SHARING_URL", e.getMessage(), e);
99
- } catch (Exception e) {
100
- promise.reject("ERR_SHARING", "Failed to share the file: " + e.getMessage(), e);
101
- }
102
- }
103
-
104
- private File getLocalFileFoUrl(String url) throws InvalidArgumentException {
105
- if (url == null) {
106
- throw new InvalidArgumentException("URL to share cannot be null.");
107
- }
108
-
109
- Uri uri = Uri.parse(url);
110
- if (uri.getPath() == null) {
111
- throw new InvalidArgumentException("Path component of the URL to share cannot be null.");
112
- }
113
-
114
- if (!"file".equals(uri.getScheme())) {
115
- throw new InvalidArgumentException("Only local file URLs are supported (expected scheme to be 'file', got '" + uri.getScheme() + "'.");
116
- }
117
-
118
- if (!isAllowedToRead(uri.getPath())) {
119
- throw new InvalidArgumentException("Not allowed to read file under given URL.");
120
- }
121
-
122
- return new File(uri.getPath());
123
- }
124
-
125
- private boolean isAllowedToRead(String url) {
126
- if (mModuleRegistry != null) {
127
- FilePermissionModuleInterface permissionModuleInterface = mModuleRegistry.getModule(FilePermissionModuleInterface.class);
128
- if (permissionModuleInterface != null) {
129
- return permissionModuleInterface.getPathPermissions(mContext, url).contains(Permission.READ);
130
- }
131
- }
132
- return true;
133
- }
134
-
135
- protected Intent createSharingIntent(Uri uri, String mimeType) {
136
- Intent intent = new Intent(Intent.ACTION_SEND);
137
- intent.putExtra(Intent.EXTRA_STREAM, uri);
138
- intent.setTypeAndNormalize(mimeType);
139
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
140
- return intent;
141
- }
142
-
143
- @Override
144
- public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
145
- if (requestCode == REQUEST_CODE && mPendingPromise != null) {
146
- mPendingPromise.resolve(Bundle.EMPTY);
147
- mPendingPromise = null;
148
- }
149
- }
150
-
151
- @Override
152
- public void onNewIntent(Intent intent) {
153
- // do nothing
154
- }
155
- }
@@ -1,16 +0,0 @@
1
- package expo.modules.sharing;
2
-
3
- import android.content.Context;
4
-
5
- import org.unimodules.core.BasePackage;
6
- import org.unimodules.core.ExportedModule;
7
-
8
- import java.util.Collections;
9
- import java.util.List;
10
-
11
- public class SharingPackage extends BasePackage {
12
- @Override
13
- public List<ExportedModule> createExportedModules(Context context) {
14
- return Collections.<ExportedModule>singletonList(new SharingModule(context));
15
- }
16
- }