Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions android/src/main/java/com/reactnativedetector/DetectorModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.modules.core.DeviceEventManagerModule


import android.app.Activity

class DetectorModule(val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), ScreenshotDetectionListener {
private val screenshotDetectionDelegate = ScreenshotDetectionDelegate(reactContext, this)
private var screenshotDetectionDelegate: ScreenshotDetectionDelegate? = null

override fun getName(): String {
return "Detector"
}

@ReactMethod
fun startScreenshotDetection() {
screenshotDetectionDelegate.startScreenshotDetection()
val currentActivity = reactContext.currentActivity
if (currentActivity != null) {
screenshotDetectionDelegate = ScreenshotDetectionDelegate(currentActivity, this)
screenshotDetectionDelegate?.startScreenshotDetection()
}
}

@ReactMethod
fun stopScreenshotDetection() {
screenshotDetectionDelegate.stopScreenshotDetection()
screenshotDetectionDelegate?.stopScreenshotDetection()
screenshotDetectionDelegate = null;
}

override fun onScreenCaptured(path: String) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit("UIApplicationUserDidTakeScreenshotNotification", null)
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit("UIApplicationUserDidTakeScreenshotNotification", null)
}

override fun onScreenCapturedWithDeniedPermission() {
Expand Down