Last active
October 3, 2023 07:58
-
-
Save garmoshka-mo/a6e5eca85537771082e7ca5ffb8131e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView.kt b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView.kt | |
index e666cb5..729fda2 100644 | |
--- a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView.kt | |
+++ b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraView.kt | |
@@ -8,6 +8,7 @@ import android.content.res.Configuration | |
import android.hardware.camera2.* | |
import android.util.Log | |
import android.util.Range | |
+import android.util.Size | |
import android.view.* | |
import android.view.View.OnTouchListener | |
import android.widget.FrameLayout | |
@@ -401,13 +402,16 @@ class CameraView(context: Context, private val frameProcessorThread: ExecutorSer | |
.setBackgroundExecutor(frameProcessorThread) | |
if (format == null) { | |
- // let CameraX automatically find best resolution for the target aspect ratio | |
- Log.i(TAG, "No custom format has been set, CameraX will automatically determine best configuration...") | |
- val aspectRatio = aspectRatio(previewView.height, previewView.width) // flipped because it's in sensor orientation. | |
- previewBuilder.setTargetAspectRatio(aspectRatio) | |
- imageCaptureBuilder.setTargetAspectRatio(aspectRatio) | |
- // TODO: Aspect Ratio for Video Recorder? | |
- imageAnalysisBuilder.setTargetAspectRatio(aspectRatio) | |
+ var size = Size(768, 1024) // Vertical photo | |
+ if (video == true) { | |
+ size = Size(480, 640) | |
+ } else if (orientation == "landscapeLeft" || orientation == "landscapeRight") { | |
+ size = Size(1024, 768) | |
+ } | |
+ previewBuilder.setTargetResolution(size) | |
+ imageCaptureBuilder.setTargetResolution(size) | |
+ imageAnalysisBuilder.setTargetResolution(size) | |
+ videoRecorderBuilder.setQualitySelector(QualitySelector.from(Quality.SD)) | |
} else { | |
// User has selected a custom format={}. Use that | |
val format = DeviceFormat(format!!) | |
diff --git a/node_modules/react-native-vision-camera/ios/CameraView+AVCaptureSession.swift b/node_modules/react-native-vision-camera/ios/CameraView+AVCaptureSession.swift | |
index 5c9b77d..1a6cd91 100644 | |
--- a/node_modules/react-native-vision-camera/ios/CameraView+AVCaptureSession.swift | |
+++ b/node_modules/react-native-vision-camera/ios/CameraView+AVCaptureSession.swift | |
@@ -219,10 +219,20 @@ extension CameraView { | |
*/ | |
final func configureFormat() { | |
ReactLogger.log(level: .info, message: "Configuring Format...") | |
- guard let filter = format else { | |
- // Format Filter was null. Ignore it. | |
- return | |
+ | |
+ var filter: NSDictionary | |
+ if photo?.boolValue == true { | |
+ filter = [ | |
+ "height": 768, | |
+ "width": 1024 | |
+ ] | |
+ } else { | |
+ filter = [ | |
+ "height": 480, | |
+ "width": 640 | |
+ ] | |
} | |
+ | |
guard let device = videoDeviceInput?.device else { | |
invokeOnError(.session(.cameraNotReady)) | |
return | |
@@ -234,7 +244,7 @@ extension CameraView { | |
} | |
// get matching format | |
- let matchingFormats = device.formats.filter { $0.matchesFilter(filter) }.sorted { $0.isBetterThan($1) } | |
+ let matchingFormats = device.formats.filter { $0.matchesFilter(filter) } | |
guard let format = matchingFormats.first else { | |
invokeOnError(.format(.invalidFormat)) | |
return | |
diff --git a/node_modules/react-native-vision-camera/ios/Extensions/AVCaptureDevice.Format+matchesFilter.swift b/node_modules/react-native-vision-camera/ios/Extensions/AVCaptureDevice.Format+matchesFilter.swift | |
index 35789a6..9fc662b 100644 | |
--- a/node_modules/react-native-vision-camera/ios/Extensions/AVCaptureDevice.Format+matchesFilter.swift | |
+++ b/node_modules/react-native-vision-camera/ios/Extensions/AVCaptureDevice.Format+matchesFilter.swift | |
@@ -14,22 +14,13 @@ extension AVCaptureDevice.Format { | |
* The `dictionary` dictionary must be of type `CameraDeviceFormat` (from `CameraDevice.d.ts`) | |
*/ | |
func matchesFilter(_ filter: NSDictionary) -> Bool { | |
- if let photoHeight = filter.value(forKey: "photoHeight") as? NSNumber { | |
- if highResolutionStillImageDimensions.height != photoHeight.intValue { | |
- return false | |
- } | |
- } | |
- if let photoWidth = filter.value(forKey: "photoWidth") as? NSNumber { | |
- if highResolutionStillImageDimensions.width != photoWidth.intValue { | |
- return false | |
- } | |
- } | |
- if let videoHeight = filter.value(forKey: "videoHeight") as? NSNumber { | |
+ | |
+ if let videoHeight = filter.value(forKey: "height") as? NSNumber { | |
if videoDimensions.height != CGFloat(videoHeight.doubleValue) { | |
return false | |
} | |
} | |
- if let videoWidth = filter.value(forKey: "videoWidth") as? NSNumber { | |
+ if let videoWidth = filter.value(forKey: "width") as? NSNumber { | |
if videoDimensions.width != CGFloat(videoWidth.doubleValue) { | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment