fix: Fix takeSnapshot not working on Android (#961)

Accessing previewView.bitmap was throwing an error because it wasn't being done on the main thread.
Any access to previewView needs to be done on the main (UI) thread. This commit fixes the issue by
ensuring this access is now run on the main thread.

Fixes #547
This commit is contained in:
Menardi 2022-04-04 10:03:08 +01:00 committed by GitHub
parent fe01295226
commit 3850491b9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,9 @@ suspend fun CameraView.takeSnapshot(options: ReadableMap): WritableMap = corouti
camera.cameraControl.enableTorch(true).await()
}
val bitmap = this@takeSnapshot.previewView.bitmap ?: throw CameraNotReadyError()
val bitmap = withContext(coroutineScope.coroutineContext) {
previewView.bitmap ?: throw CameraNotReadyError()
}
val quality = if (options.hasKey("quality")) options.getInt("quality") else 100