expo-screen-capture 5.1.0 → 5.2.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.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,20 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 5.2.0 — 2023-05-08
14
+
15
+ ### 🎉 New features
16
+
17
+ - On Android, migrated to Expo Modules API. ([#22208](https://github.com/expo/expo/pull/22208) by [@alanjhughes](https://github.com/alanjhughes))
18
+
19
+ ### 💡 Others
20
+
21
+ - Android: Switch from deprecated `toLowerCase` to `lowercase` function ([#22225](https://github.com/expo/expo/pull/22225) by [@hbiede](https://github.com/hbiede))
22
+
23
+ ## 5.1.1 — 2023-02-09
24
+
25
+ _This version does not introduce any user-facing changes._
26
+
13
27
  ## 5.1.0 — 2023-02-03
14
28
 
15
29
  ### 💡 Others
package/README.md CHANGED
@@ -13,7 +13,7 @@ This is especially important on Android, since the [`android.media.projection`](
13
13
 
14
14
  ## Installation in managed Expo projects
15
15
 
16
- For [managed](https://docs.expo.dev/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/screen-capture/).
16
+ For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/screen-capture/).
17
17
 
18
18
  ## Installation in bare React Native projects
19
19
 
@@ -21,13 +21,13 @@ For bare React Native projects, you must ensure that you have [installed and con
21
21
 
22
22
  ### Add the package to your npm dependencies
23
23
 
24
- ```sh
25
- expo install expo-screen-capture
24
+ ```
25
+ npx expo install expo-screen-capture
26
26
  ```
27
27
 
28
28
  ### Configure for iOS
29
29
 
30
- ```sh
30
+ ```
31
31
  npx pod-install
32
32
  ```
33
33
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '5.1.0'
6
+ version = '5.2.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -22,7 +22,7 @@ buildscript {
22
22
  if (ext.has("kotlinVersion")) {
23
23
  ext.kotlinVersion()
24
24
  } else {
25
- ext.safeExtGet("kotlinVersion", "1.6.10")
25
+ ext.safeExtGet("kotlinVersion", "1.8.10")
26
26
  }
27
27
  }
28
28
 
@@ -74,7 +74,7 @@ android {
74
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
75
  targetSdkVersion safeExtGet("targetSdkVersion", 33)
76
76
  versionCode 7
77
- versionName '5.1.0'
77
+ versionName '5.2.0'
78
78
  }
79
79
  lintOptions {
80
80
  abortOnError false
@@ -1,69 +1,31 @@
1
1
  package expo.modules.screencapture
2
2
 
3
- import android.app.Activity
4
3
  import android.content.Context
5
4
  import android.view.WindowManager
6
-
7
- import expo.modules.core.ExportedModule
8
- import expo.modules.core.ModuleRegistry
9
- import expo.modules.core.Promise
10
- import expo.modules.core.errors.CurrentActivityNotFoundException
11
- import expo.modules.core.interfaces.ActivityProvider
12
- import expo.modules.core.interfaces.ExpoMethod
13
-
14
- class ScreenCaptureModule(context: Context) : ExportedModule(context) {
15
-
16
- private lateinit var mActivityProvider: ActivityProvider
17
-
18
- override fun getName(): String {
19
- return NAME
20
- }
21
-
22
- override fun onCreate(moduleRegistry: ModuleRegistry) {
23
- mActivityProvider = moduleRegistry.getModule(ActivityProvider::class.java)
24
- ScreenshotEventEmitter(context, moduleRegistry)
25
- }
26
-
27
- @ExpoMethod
28
- fun preventScreenCapture(promise: Promise) {
29
- val activity = getCurrentActivity()
30
-
31
- activity.runOnUiThread {
32
- try {
33
- activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE)
34
- } catch (exception: Exception) {
35
- promise.reject(ERROR_CODE_PREVENTION, "Failed to prevent screen capture: " + exception)
36
- }
37
- }
38
- promise.resolve(null)
39
- }
40
-
41
- @ExpoMethod
42
- fun allowScreenCapture(promise: Promise) {
43
- val activity = getCurrentActivity()
44
-
45
- activity.runOnUiThread {
46
- try {
47
- activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
48
- } catch (exception: Exception) {
49
- promise.reject(ERROR_CODE_PREVENTION, "Failed to reallow screen capture: " + exception)
50
- }
5
+ import expo.modules.kotlin.exception.Exceptions
6
+ import expo.modules.kotlin.functions.Queues
7
+ import expo.modules.kotlin.modules.Module
8
+ import expo.modules.kotlin.modules.ModuleDefinition
9
+
10
+ class ScreenCaptureModule : Module() {
11
+ private val context: Context
12
+ get() = appContext.reactContext ?: throw Exceptions.AppContextLost()
13
+ private val currentActivity
14
+ get() = appContext.currentActivity ?: throw Exceptions.MissingActivity()
15
+
16
+ override fun definition() = ModuleDefinition {
17
+ Name("ExpoScreenCapture")
18
+
19
+ OnCreate {
20
+ ScreenshotEventEmitter(context, appContext.legacyModuleRegistry)
51
21
  }
52
- promise.resolve(null)
53
- }
54
22
 
55
- @Throws(CurrentActivityNotFoundException::class)
56
- fun getCurrentActivity(): Activity {
57
- val activity = mActivityProvider.currentActivity
58
- if (activity != null) {
59
- return activity
60
- } else {
61
- throw CurrentActivityNotFoundException()
62
- }
63
- }
23
+ AsyncFunction("preventScreenCapture") {
24
+ currentActivity.window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
25
+ }.runOnQueue(Queues.MAIN)
64
26
 
65
- companion object {
66
- private val NAME = "ExpoScreenCapture"
67
- private const val ERROR_CODE_PREVENTION = "ERR_SCREEN_CAPTURE_PREVENTION"
27
+ AsyncFunction("allowScreenCapture") {
28
+ currentActivity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
29
+ }.runOnQueue(Queues.MAIN)
68
30
  }
69
31
  }
@@ -7,6 +7,7 @@ import android.database.ContentObserver
7
7
  import android.net.Uri
8
8
  import android.os.Bundle
9
9
  import android.os.Handler
10
+ import android.os.Looper
10
11
  import android.provider.MediaStore
11
12
  import android.util.Log
12
13
 
@@ -30,7 +31,7 @@ class ScreenshotEventEmitter(val context: Context, moduleRegistry: ModuleRegistr
30
31
  moduleRegistry.getModule(UIManager::class.java).registerLifecycleEventListener(this)
31
32
  eventEmitter = moduleRegistry.getModule(EventEmitter::class.java)
32
33
 
33
- val contentObserver: ContentObserver = object : ContentObserver(Handler()) {
34
+ val contentObserver: ContentObserver = object : ContentObserver(Handler(Looper.getMainLooper())) {
34
35
  override fun onChange(selfChange: Boolean, uri: Uri?) {
35
36
  super.onChange(selfChange, uri)
36
37
  if (isListening) {
@@ -65,14 +66,16 @@ class ScreenshotEventEmitter(val context: Context, moduleRegistry: ModuleRegistr
65
66
  return ContextCompat.checkSelfPermission(context, permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
66
67
  }
67
68
 
68
- @Nullable private fun getFilePathFromContentResolver(context: Context, uri: Uri?): String? {
69
+ @Nullable
70
+ private fun getFilePathFromContentResolver(context: Context, uri: Uri?): String? {
69
71
  if (uri == null) {
70
72
  return null
71
73
  }
72
74
  try {
73
75
  val cursor = context.contentResolver.query(uri, arrayOf(MediaStore.Images.Media.DATA), null, null, null)
74
76
  if (cursor != null && cursor.moveToFirst()) {
75
- val path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA))
77
+ val index = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
78
+ val path = cursor.getString(index)
76
79
  cursor.close()
77
80
  return path
78
81
  }
@@ -83,7 +86,7 @@ class ScreenshotEventEmitter(val context: Context, moduleRegistry: ModuleRegistr
83
86
  }
84
87
 
85
88
  private fun isPathOfNewScreenshot(path: String): Boolean {
86
- if (!path.toLowerCase().contains("screenshot")) {
89
+ if (!path.lowercase().contains("screenshot")) {
87
90
  return false
88
91
  }
89
92
  // Cannot check that the onChange event is for an insert operation until API level 30
@@ -1,3 +1,3 @@
1
- declare const _default: import("expo-modules-core").ProxyNativeModule;
1
+ declare const _default: any;
2
2
  export default _default;
3
3
  //# sourceMappingURL=ExpoScreenCapture.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoScreenCapture.d.ts","sourceRoot":"","sources":["../src/ExpoScreenCapture.ts"],"names":[],"mappings":";AAEA,wBAAoD"}
1
+ {"version":3,"file":"ExpoScreenCapture.d.ts","sourceRoot":"","sources":["../src/ExpoScreenCapture.ts"],"names":[],"mappings":";AACA,wBAAwD"}
@@ -1,3 +1,3 @@
1
- import { NativeModulesProxy } from 'expo-modules-core';
2
- export default NativeModulesProxy.ExpoScreenCapture;
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ export default requireNativeModule('ExpoScreenCapture');
3
3
  //# sourceMappingURL=ExpoScreenCapture.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoScreenCapture.js","sourceRoot":"","sources":["../src/ExpoScreenCapture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,eAAe,kBAAkB,CAAC,iBAAiB,CAAC","sourcesContent":["import { NativeModulesProxy } from 'expo-modules-core';\n\nexport default NativeModulesProxy.ExpoScreenCapture;\n"]}
1
+ {"version":3,"file":"ExpoScreenCapture.js","sourceRoot":"","sources":["../src/ExpoScreenCapture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,eAAe,mBAAmB,CAAC,mBAAmB,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nexport default requireNativeModule('ExpoScreenCapture');\n"]}
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "expo-screen-capture",
3
+ "platforms": ["ios", "android", "web"],
4
+ "android": {
5
+ "modules": ["expo.modules.screencapture.ScreenCaptureModule"]
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-screen-capture",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "ExpoScreenCapture standalone module",
5
5
  "main": "build/ScreenCapture.js",
6
6
  "types": "build/ScreenCapture.d.ts",
@@ -39,5 +39,5 @@
39
39
  "peerDependencies": {
40
40
  "expo": "*"
41
41
  },
42
- "gitHead": "1815e2eaad8c753588c7b1eb74420174a28e01f4"
42
+ "gitHead": "4ba50c428c8369bb6b3a51a860d4898ad4ccbe78"
43
43
  }
@@ -1,3 +1,2 @@
1
- import { NativeModulesProxy } from 'expo-modules-core';
2
-
3
- export default NativeModulesProxy.ExpoScreenCapture;
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ export default requireNativeModule('ExpoScreenCapture');
@@ -1,12 +0,0 @@
1
- package expo.modules.screencapture
2
-
3
- import android.content.Context
4
-
5
- import expo.modules.core.BasePackage
6
- import expo.modules.core.ExportedModule
7
-
8
- class ScreenCapturePackage : BasePackage() {
9
- override fun createExportedModules(context: Context): List<ExportedModule> {
10
- return listOf(ScreenCaptureModule(context) as ExportedModule)
11
- }
12
- }
package/unimodule.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "name": "expo-screen-capture",
3
- "platforms": ["ios", "android", "web"]
4
- }