diff --git a/BusinessCard/Views/CardEditorView.swift b/BusinessCard/Views/CardEditorView.swift index 90d308a..9330d3a 100644 --- a/BusinessCard/Views/CardEditorView.swift +++ b/BusinessCard/Views/CardEditorView.swift @@ -72,6 +72,14 @@ struct CardEditorView: View { case .logo: return String.localized("Add company logo") } } + + var cropAspectRatio: CropAspectRatio { + switch self { + case .profile: return .square + case .cover: return .banner + case .logo: return .square + } + } } private var isEditing: Bool { card != nil } @@ -250,6 +258,7 @@ struct CardEditorView: View { .fullScreenCover(isPresented: $showingPhotoPicker) { NavigationStack { PhotoPickerWithCropper( + aspectRatio: activeImageType?.cropAspectRatio ?? .square, onSave: { croppedData in savePhoto(croppedData, for: activeImageType) showingPhotoPicker = false @@ -264,6 +273,7 @@ struct CardEditorView: View { } .fullScreenCover(isPresented: $showingCamera) { CameraWithCropper( + aspectRatio: activeImageType?.cropAspectRatio ?? .square, onSave: { croppedData in savePhoto(croppedData, for: activeImageType) showingCamera = false diff --git a/BusinessCard/Views/Components/CameraWithCropper.swift b/BusinessCard/Views/Components/CameraWithCropper.swift index 2f49af2..a74a543 100644 --- a/BusinessCard/Views/Components/CameraWithCropper.swift +++ b/BusinessCard/Views/Components/CameraWithCropper.swift @@ -7,9 +7,20 @@ import Bedrock struct CameraWithCropper: View { @Environment(\.dismiss) private var dismiss + let aspectRatio: CropAspectRatio let onSave: (Data) -> Void let onCancel: () -> Void + init( + aspectRatio: CropAspectRatio = .square, + onSave: @escaping (Data) -> Void, + onCancel: @escaping () -> Void + ) { + self.aspectRatio = aspectRatio + self.onSave = onSave + self.onCancel = onCancel + } + @State private var capturedImageData: Data? @State private var showingCropper = false @@ -31,6 +42,7 @@ struct CameraWithCropper: View { if showingCropper, let capturedImageData { PhotoCropperSheet( imageData: capturedImageData, + aspectRatio: aspectRatio, shouldDismissOnComplete: false ) { croppedData in if let croppedData {