expo-screen-capture 5.8.0 → 5.8.1
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 +6 -0
- package/android/build.gradle +2 -2
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/expo/modules/screencapture/ScreenCaptureModule.kt +24 -1
- package/android/src/main/java/expo/modules/screencapture/ScreenShotEventEmitter.kt +3 -16
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 5.8.1 — 2024-01-23
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Fix screenshot listener not being called on Android 34. ([#26549](https://github.com/expo/expo/pull/26549) by [@alanjhughes](https://github.com/alanjhughes))
|
|
18
|
+
|
|
13
19
|
## 5.8.0 — 2023-12-15
|
|
14
20
|
|
|
15
21
|
### 🎉 New features
|
package/android/build.gradle
CHANGED
|
@@ -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.8.
|
|
6
|
+
version = '5.8.1'
|
|
7
7
|
|
|
8
8
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
9
9
|
if (expoModulesCorePlugin.exists()) {
|
|
@@ -94,7 +94,7 @@ android {
|
|
|
94
94
|
namespace "expo.modules.screencapture"
|
|
95
95
|
defaultConfig {
|
|
96
96
|
versionCode 7
|
|
97
|
-
versionName '5.8.
|
|
97
|
+
versionName '5.8.1'
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
2
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
|
|
3
3
|
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
|
|
4
|
+
<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" android:maxSdkVersion="34" />
|
|
4
5
|
</manifest>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package expo.modules.screencapture
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
|
+
import android.app.Activity
|
|
4
5
|
import android.content.Context
|
|
5
6
|
import android.os.Build
|
|
6
7
|
import android.view.WindowManager
|
|
@@ -11,17 +12,31 @@ import expo.modules.kotlin.functions.Queues
|
|
|
11
12
|
import expo.modules.kotlin.modules.Module
|
|
12
13
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
13
14
|
|
|
15
|
+
const val eventName = "onScreenshot"
|
|
16
|
+
|
|
14
17
|
class ScreenCaptureModule : Module() {
|
|
15
18
|
private val context: Context
|
|
16
19
|
get() = appContext.reactContext ?: throw Exceptions.AppContextLost()
|
|
17
20
|
private val currentActivity
|
|
18
21
|
get() = appContext.currentActivity ?: throw Exceptions.MissingActivity()
|
|
22
|
+
private var screenCaptureCallback: Activity.ScreenCaptureCallback? = null
|
|
19
23
|
|
|
20
24
|
override fun definition() = ModuleDefinition {
|
|
21
25
|
Name("ExpoScreenCapture")
|
|
22
26
|
|
|
27
|
+
Events(eventName)
|
|
28
|
+
|
|
23
29
|
OnCreate {
|
|
24
|
-
|
|
30
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
31
|
+
screenCaptureCallback = Activity.ScreenCaptureCallback {
|
|
32
|
+
sendEvent(eventName)
|
|
33
|
+
}
|
|
34
|
+
currentActivity.registerScreenCaptureCallback(currentActivity.mainExecutor, screenCaptureCallback!!)
|
|
35
|
+
} else {
|
|
36
|
+
ScreenshotEventEmitter(context) {
|
|
37
|
+
sendEvent(eventName)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
25
40
|
}
|
|
26
41
|
|
|
27
42
|
AsyncFunction("getPermissionsAsync") { promise: Promise ->
|
|
@@ -47,5 +62,13 @@ class ScreenCaptureModule : Module() {
|
|
|
47
62
|
AsyncFunction("allowScreenCapture") {
|
|
48
63
|
currentActivity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
|
49
64
|
}.runOnQueue(Queues.MAIN)
|
|
65
|
+
|
|
66
|
+
OnDestroy {
|
|
67
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
68
|
+
screenCaptureCallback?.let {
|
|
69
|
+
currentActivity.unregisterScreenCaptureCallback(it)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
50
73
|
}
|
|
51
74
|
}
|
|
@@ -6,32 +6,19 @@ import android.content.pm.PackageManager
|
|
|
6
6
|
import android.database.ContentObserver
|
|
7
7
|
import android.net.Uri
|
|
8
8
|
import android.os.Build
|
|
9
|
-
import android.os.Bundle
|
|
10
9
|
import android.os.Handler
|
|
11
10
|
import android.os.Looper
|
|
12
11
|
import android.provider.MediaStore
|
|
13
12
|
import android.util.Log
|
|
14
|
-
|
|
15
|
-
import androidx.core.content.ContextCompat
|
|
16
13
|
import androidx.annotation.Nullable
|
|
17
|
-
|
|
18
|
-
import expo.modules.core.ModuleRegistry
|
|
14
|
+
import androidx.core.content.ContextCompat
|
|
19
15
|
import expo.modules.core.interfaces.LifecycleEventListener
|
|
20
|
-
import expo.modules.core.interfaces.services.EventEmitter
|
|
21
|
-
import expo.modules.core.interfaces.services.UIManager
|
|
22
|
-
|
|
23
|
-
import java.lang.Exception
|
|
24
16
|
|
|
25
|
-
class ScreenshotEventEmitter(val context: Context,
|
|
26
|
-
private val onScreenshotEventName: String = "onScreenshot"
|
|
17
|
+
class ScreenshotEventEmitter(val context: Context, onCapture: () -> Unit) : LifecycleEventListener {
|
|
27
18
|
private var isListening: Boolean = true
|
|
28
|
-
private var eventEmitter: EventEmitter
|
|
29
19
|
private var previousPath: String = ""
|
|
30
20
|
|
|
31
21
|
init {
|
|
32
|
-
moduleRegistry.getModule(UIManager::class.java).registerLifecycleEventListener(this)
|
|
33
|
-
eventEmitter = moduleRegistry.getModule(EventEmitter::class.java)
|
|
34
|
-
|
|
35
22
|
val contentObserver: ContentObserver = object : ContentObserver(Handler(Looper.getMainLooper())) {
|
|
36
23
|
override fun onChange(selfChange: Boolean, uri: Uri?) {
|
|
37
24
|
super.onChange(selfChange, uri)
|
|
@@ -43,7 +30,7 @@ class ScreenshotEventEmitter(val context: Context, moduleRegistry: ModuleRegistr
|
|
|
43
30
|
val path = getFilePathFromContentResolver(context, uri)
|
|
44
31
|
if (path != null && isPathOfNewScreenshot(path)) {
|
|
45
32
|
previousPath = path
|
|
46
|
-
|
|
33
|
+
onCapture()
|
|
47
34
|
}
|
|
48
35
|
}
|
|
49
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-screen-capture",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.1",
|
|
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": "
|
|
42
|
+
"gitHead": "7fb94e3c0598d0e2d428184b16eec5ec67d80388"
|
|
43
43
|
}
|