Skip to content

Commit 00c461a

Browse files
authored
Return height/width of capture (#646)
To be consistent with Android
1 parent 11b15fd commit 00c461a

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

ios/ReactNativeCameraKit/CameraProtocol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ protocol CameraProtocol: AnyObject, FocusInterfaceViewDelegate {
2828
func update(scannerFrameSize: CGRect?)
2929

3030
func capturePicture(onWillCapture: @escaping () -> Void,
31-
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?) -> (),
31+
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?, _ dimensions: CMVideoDimensions) -> (),
3232
onError: @escaping (_ message: String) -> ())
3333
}

ios/ReactNativeCameraKit/CameraView.swift

+10-3
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,13 @@ class CameraView: UIView {
242242
self?.camera.previewView.alpha = 1
243243
})
244244
}
245-
}, onSuccess: { [weak self] imageData, thumbnailData in
245+
}, onSuccess: { [weak self] imageData, thumbnailData, dimensions in
246246
DispatchQueue.global(qos: .default).async {
247-
self?.writeCaptured(imageData: imageData, thumbnailData: thumbnailData, onSuccess: onSuccess, onError: onError)
247+
self?.writeCaptured(imageData: imageData,
248+
thumbnailData: thumbnailData,
249+
dimensions: dimensions,
250+
onSuccess: onSuccess,
251+
onError: onError)
248252

249253
self?.focusInterfaceView.resetFocus()
250254
}
@@ -289,6 +293,7 @@ class CameraView: UIView {
289293

290294
private func writeCaptured(imageData: Data,
291295
thumbnailData: Data?,
296+
dimensions: CMVideoDimensions,
292297
onSuccess: @escaping (_ imageObject: [String: Any]) -> (),
293298
onError: @escaping (_ error: String) -> ()) {
294299
do {
@@ -298,7 +303,9 @@ class CameraView: UIView {
298303
"size": imageData.count,
299304
"uri": temporaryImageFileURL.description,
300305
"name": temporaryImageFileURL.lastPathComponent,
301-
"thumb": ""
306+
"thumb": "",
307+
"height": dimensions.height,
308+
"width": dimensions.width
302309
])
303310
} catch {
304311
let errorMessage = "Error occurred while writing image data to a temporary file: \(error)"

ios/ReactNativeCameraKit/PhotoCaptureDelegate.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
1212
private(set) var requestedPhotoSettings: AVCapturePhotoSettings
1313

1414
private let onWillCapture: () -> Void
15-
private let onCaptureSuccess: (_ uniqueID: Int64, _ imageData: Data, _ thumbnailData: Data?) -> Void
15+
private let onCaptureSuccess: (_ uniqueID: Int64, _ imageData: Data, _ thumbnailData: Data?, _ dimensions: CMVideoDimensions) -> Void
1616
private let onCaptureError: (_ uniqueID: Int64, _ message: String) -> Void
1717

1818
init(with requestedPhotoSettings: AVCapturePhotoSettings,
1919
onWillCapture: @escaping () -> Void,
20-
onCaptureSuccess: @escaping (_ uniqueID: Int64, _ imageData: Data, _ thumbnailData: Data?) -> Void,
20+
onCaptureSuccess: @escaping (_ uniqueID: Int64, _ imageData: Data, _ thumbnailData: Data?, _ dimensions: CMVideoDimensions) -> Void,
2121
onCaptureError: @escaping (_ uniqueID: Int64, _ errorMessage: String) -> Void) {
2222
self.requestedPhotoSettings = requestedPhotoSettings
2323
self.onWillCapture = onWillCapture
@@ -50,6 +50,6 @@ class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
5050
thumbnailData = uiImage.jpegData(compressionQuality: 0.7)
5151
}
5252

53-
onCaptureSuccess(requestedPhotoSettings.uniqueID, imageData, thumbnailData)
53+
onCaptureSuccess(requestedPhotoSettings.uniqueID, imageData, thumbnailData, photo.resolvedSettings.photoDimensions)
5454
}
5555
}

ios/ReactNativeCameraKit/RealCamera.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
292292
}
293293

294294
func capturePicture(onWillCapture: @escaping () -> Void,
295-
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?) -> Void,
295+
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?, _ dimensions: CMVideoDimensions) -> Void,
296296
onError: @escaping (_ message: String) -> Void) {
297297
/*
298298
Retrieve the video preview layer's video orientation on the main queue before
@@ -317,10 +317,10 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
317317
let photoCaptureDelegate = PhotoCaptureDelegate(
318318
with: settings,
319319
onWillCapture: onWillCapture,
320-
onCaptureSuccess: { uniqueID, imageData, thumbnailData in
320+
onCaptureSuccess: { uniqueID, imageData, thumbnailData, dimensions in
321321
self.inProgressPhotoCaptureDelegates[uniqueID] = nil
322322

323-
onSuccess(imageData, thumbnailData)
323+
onSuccess(imageData, thumbnailData, dimensions)
324324
},
325325
onCaptureError: { uniqueID, errorMessage in
326326
self.inProgressPhotoCaptureDelegates[uniqueID] = nil

ios/ReactNativeCameraKit/SimulatorCamera.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class SimulatorCamera: CameraProtocol {
169169
func update(scannerFrameSize: CGRect?) {}
170170

171171
func capturePicture(onWillCapture: @escaping () -> Void,
172-
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?) -> (),
172+
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?, _ dimensions: CMVideoDimensions) -> (),
173173
onError: @escaping (_ message: String) -> ()) {
174174
onWillCapture()
175175

@@ -180,7 +180,7 @@ class SimulatorCamera: CameraProtocol {
180180
// Then switch to background thread
181181
DispatchQueue.global(qos: .default).async {
182182
if let imageData = previewSnapshot?.jpegData(compressionQuality: 0.85) {
183-
onSuccess(imageData, nil)
183+
onSuccess(imageData, nil, CMVideoDimensions(width: 480, height: 640))
184184
} else {
185185
onError("Failed to convert snapshot to JPEG data")
186186
}

src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export type ZoomMode = 'on' | 'off';
1414
export type CaptureData = {
1515
uri: string;
1616
name: string;
17+
height: number;
18+
width: number;
1719
// Android only
1820
id?: string;
1921
path?: string;
20-
height?: number;
21-
width?: number;
2222
// iOS only
2323
size?: number;
2424
};

0 commit comments

Comments
 (0)