From 909546e04b1941bd25595c1233b48427300d26a0 Mon Sep 17 00:00:00 2001 From: Seph Soliman Date: Tue, 10 Oct 2023 17:49:59 -0700 Subject: [PATCH] Fixed QR scanner not always picking up clear codes Aspect ratio was sometimes set incorrectly, depending on device (Pixel 6 and 7 phones had troubles scanning 20x20mm codes) --- .../src/main/java/com/rncamerakit/CKCamera.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/rncamerakit/CKCamera.kt b/android/src/main/java/com/rncamerakit/CKCamera.kt index efbfe8632..4009bdcc8 100644 --- a/android/src/main/java/com/rncamerakit/CKCamera.kt +++ b/android/src/main/java/com/rncamerakit/CKCamera.kt @@ -285,19 +285,20 @@ class CKCamera(context: ThemedReactContext) : FrameLayout(context), LifecycleObs // ImageCapture imageCapture = ImageCapture.Builder() - .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY) - // We request aspect ratio but no resolution to match preview config, but letting - // CameraX optimize for whatever specific resolution best fits our use cases - .setTargetAspectRatio(screenAspectRatio) - // Set initial target rotation, we will have to call this again if rotation changes - // during the lifecycle of this use case - .setTargetRotation(rotation) - .build() + .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY) + // We request aspect ratio but no resolution to match preview config, but letting + // CameraX optimize for whatever specific resolution best fits our use cases + .setTargetAspectRatio(screenAspectRatio) + // Set initial target rotation, we will have to call this again if rotation changes + // during the lifecycle of this use case + .setTargetRotation(rotation) + .build() // ImageAnalysis imageAnalyzer = ImageAnalysis.Builder() - .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) - .build() + .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) + .setTargetAspectRatio(screenAspectRatio) + .build() val useCases = mutableListOf(preview, imageCapture)