Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions ios/ReactNativeCameraKit/CKCameraManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ @interface RCT_EXTERN_MODULE(CKCameraManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(zoomMode, CKZoomMode)
RCT_EXPORT_VIEW_PROPERTY(zoom, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(maxZoom, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(shutterPhotoSound, BOOL)

@end
8 changes: 6 additions & 2 deletions ios/ReactNativeCameraKit/CKCameraViewComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
_view.barcodeFrameSize = @{@"width": @(barcodeWidth), @"height": @(barcodeHeight)};
[changedProps addObject:@"barcodeFrameSize"];
}


bool shutterPhotoSound = newProps.shutterPhotoSound;
if (shutterPhotoSound != _view.shutterPhotoSound) {
_view.shutterPhotoSound = shutterPhotoSound;
[changedProps addObject:@"shutterPhotoSound"];
}

[super updateProps:props oldProps:oldProps];
[_view didSetProps:changedProps];
}
Expand Down
5 changes: 4 additions & 1 deletion ios/ReactNativeCameraKit/CameraProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AVFoundation

protocol CameraProtocol: AnyObject, FocusInterfaceViewDelegate {
var previewView: UIView { get }
var imageBuffer: CMSampleBuffer? { get }

func setup(cameraType: CameraType, supportedBarcodeType: [CodeFormat])
func cameraRemovedFromSuperview()
Expand All @@ -21,6 +22,7 @@ protocol CameraProtocol: AnyObject, FocusInterfaceViewDelegate {
func update(resizeMode: ResizeMode)
func update(maxPhotoQualityPrioritization: MaxPhotoQualityPrioritization?)
func update(barcodeFrameSize: CGSize?)
func update(shutterPhotoSound: Bool)

func zoomPinchStart()
func zoomPinchChange(pinchScale: CGFloat)
Expand All @@ -31,7 +33,8 @@ protocol CameraProtocol: AnyObject, FocusInterfaceViewDelegate {

func update(scannerFrameSize: CGRect?)

func capturePicture(onWillCapture: @escaping () -> Void,
func capturePicture(captureOptions: CaptureOptions,
onWillCapture: @escaping () -> Void,
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?, _ dimensions: CMVideoDimensions) -> Void,
onError: @escaping (_ message: String) -> Void)
}
56 changes: 36 additions & 20 deletions ios/ReactNativeCameraKit/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class CameraView: UIView {
@objc public var flashMode: FlashMode = .auto
@objc public var torchMode: TorchMode = .off
@objc public var maxPhotoQualityPrioritization: MaxPhotoQualityPrioritization = .balanced
@objc public var shutterPhotoSound: Bool = true
// ratio overlay
@objc public var ratioOverlay: String?
@objc public var ratioOverlayColor: UIColor?
Expand Down Expand Up @@ -65,6 +66,14 @@ public class CameraView: UIView {

var eventInteraction: Any? = nil

var isSimulator: Bool {
#if targetEnvironment(simulator)
true
#else
false
#endif
}

// MARK: - Setup

// This is used to delay camera setup until we have both granted permission & received default props
Expand Down Expand Up @@ -288,31 +297,38 @@ public class CameraView: UIView {
if changedProps.contains("maxZoom") {
camera.update(maxZoom: maxZoom?.doubleValue)
}

if changedProps.contains("shutterPhotoSound") {
camera.update(shutterPhotoSound: shutterPhotoSound)
}
}

// MARK: Public

@objc public func capture(onSuccess: @escaping (_ imageObject: [String: Any]) -> Void,
onError: @escaping (_ error: String) -> Void) {
camera.capturePicture(onWillCapture: { [weak self] in
// Flash/dim preview to indicate shutter action
DispatchQueue.main.async {
self?.camera.previewView.alpha = 0
UIView.animate(withDuration: 0.35, animations: {
self?.camera.previewView.alpha = 1
})
}
}, onSuccess: { [weak self] imageData, thumbnailData, dimensions in
DispatchQueue.global(qos: .default).async {
self?.writeCaptured(imageData: imageData,
thumbnailData: thumbnailData,
dimensions: dimensions,
onSuccess: onSuccess,
onError: onError)

self?.focusInterfaceView.resetFocus()
}
}, onError: onError)
onError: @escaping (_ error: String) -> Void) {
let captureOptions = CaptureOptions(shutterPhotoSound: shutterPhotoSound)

camera.capturePicture(captureOptions: captureOptions,
onWillCapture: { [weak self] in
// Flash/dim preview to indicate shutter action
DispatchQueue.main.async {
self?.camera.previewView.alpha = 0
UIView.animate(withDuration: 0.35, animations: {
self?.camera.previewView.alpha = 1
})
}
}, onSuccess: { [weak self] imageData, thumbnailData, dimensions in
DispatchQueue.global(qos: .default).async {
self?.writeCaptured(imageData: imageData,
thumbnailData: thumbnailData,
dimensions: dimensions,
onSuccess: onSuccess,
onError: onError)

self?.focusInterfaceView.resetFocus()
}
}, onError: onError)
}

// MARK: - Private Helper
Expand Down
Loading