react-native-bug-reporter 1.0.3 → 1.0.4
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.
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.bugreporter
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.os.Handler
|
|
5
|
+
import java.util.concurrent.Executor
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Isolated wrapper around the API 34+ `Activity.ScreenCaptureCallback`.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: this class is the ONLY place that references
|
|
11
|
+
* `Activity.ScreenCaptureCallback`. The main module must never reference that
|
|
12
|
+
* type directly — otherwise, on Android 13 and below where the class does not
|
|
13
|
+
* exist, the runtime's reflection over the module's methods throws
|
|
14
|
+
* `NoClassDefFoundError` and the whole native module fails to load.
|
|
15
|
+
*
|
|
16
|
+
* This class is only ever instantiated inside an `SDK_INT >= 34` guard, so it
|
|
17
|
+
* (and the missing framework class) is never loaded on older devices.
|
|
18
|
+
*/
|
|
19
|
+
class ScreenCaptureCallbackApi34(
|
|
20
|
+
private val activity: Activity,
|
|
21
|
+
private val handler: Handler,
|
|
22
|
+
private val onCapture: () -> Unit,
|
|
23
|
+
) {
|
|
24
|
+
private val callback = Activity.ScreenCaptureCallback { onCapture() }
|
|
25
|
+
|
|
26
|
+
fun register() {
|
|
27
|
+
val executor = Executor { command -> handler.post(command) }
|
|
28
|
+
activity.registerScreenCaptureCallback(executor, callback)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fun unregister() {
|
|
32
|
+
activity.unregisterScreenCaptureCallback(callback)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -20,7 +20,6 @@ import com.facebook.react.bridge.WritableMap
|
|
|
20
20
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
21
21
|
import java.io.File
|
|
22
22
|
import java.io.FileOutputStream
|
|
23
|
-
import java.util.concurrent.Executor
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Native screenshot detector for Android.
|
|
@@ -40,7 +39,8 @@ class ScreenshotDetectorModule(private val reactContext: ReactApplicationContext
|
|
|
40
39
|
|
|
41
40
|
private val mainHandler = Handler(Looper.getMainLooper())
|
|
42
41
|
private var contentObserver: ContentObserver? = null
|
|
43
|
-
|
|
42
|
+
// Typed as Any? so this class never references the API-34 ScreenCaptureCallback.
|
|
43
|
+
private var screenCapture: ScreenCaptureCallbackApi34? = null
|
|
44
44
|
private var isListening = false
|
|
45
45
|
|
|
46
46
|
override fun getName(): String = NAME
|
|
@@ -102,13 +102,14 @@ class ScreenshotDetectorModule(private val reactContext: ReactApplicationContext
|
|
|
102
102
|
private fun registerScreenCaptureCallback() {
|
|
103
103
|
val activity = reactContext.currentActivity ?: return
|
|
104
104
|
mainHandler.post {
|
|
105
|
-
val executor = Executor { command -> mainHandler.post(command) }
|
|
106
|
-
val callback = Activity.ScreenCaptureCallback {
|
|
107
|
-
onScreenshotDetected()
|
|
108
|
-
}
|
|
109
|
-
screenCaptureCallback = callback
|
|
110
105
|
try {
|
|
111
|
-
|
|
106
|
+
// All ScreenCaptureCallback usage is isolated in this helper so the
|
|
107
|
+
// missing class never loads on older Android.
|
|
108
|
+
val helper = ScreenCaptureCallbackApi34(activity, mainHandler) {
|
|
109
|
+
onScreenshotDetected()
|
|
110
|
+
}
|
|
111
|
+
helper.register()
|
|
112
|
+
screenCapture = helper
|
|
112
113
|
} catch (e: Exception) {
|
|
113
114
|
// Fall back to the content observer if the callback can't be registered.
|
|
114
115
|
registerContentObserver()
|
|
@@ -117,14 +118,13 @@ class ScreenshotDetectorModule(private val reactContext: ReactApplicationContext
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
private fun unregisterScreenCaptureCallback() {
|
|
120
|
-
val
|
|
121
|
-
val callback = screenCaptureCallback as? Activity.ScreenCaptureCallback ?: return
|
|
121
|
+
val helper = screenCapture ?: return
|
|
122
122
|
mainHandler.post {
|
|
123
123
|
try {
|
|
124
|
-
|
|
124
|
+
helper.unregister()
|
|
125
125
|
} catch (_: Exception) {
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
screenCapture = null
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-bug-reporter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Universal React Native bug reporter: auto-detect screenshots, annotate, collect device/app/user context, and ship to Supabase (Postgres + Storage) with Edge Function email.",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|