diff --git a/Sources/SwiftyCrop/SwiftyCrop.swift b/Sources/SwiftyCrop/SwiftyCrop.swift index 22268a9..979b212 100644 --- a/Sources/SwiftyCrop/SwiftyCrop.swift +++ b/Sources/SwiftyCrop/SwiftyCrop.swift @@ -10,22 +10,26 @@ import SwiftUI /// - configuration: The configuration for the cropping behavior. If nothing is specified, the default is used. /// - onComplete: A closure that's called when the cropping is complete. This closure returns the cropped `UIImage?`. /// If an error occurs the return value is nil. +/// - onCancel: The user selected cancel and the cropping was stopped public struct SwiftyCropView: View { private let imageToCrop: UIImage private let maskShape: MaskShape private let configuration: SwiftyCropConfiguration private let onComplete: (UIImage?) -> Void + private let onCancel: () -> Void public init( imageToCrop: UIImage, maskShape: MaskShape, configuration: SwiftyCropConfiguration = SwiftyCropConfiguration(), - onComplete: @escaping (UIImage?) -> Void + onComplete: @escaping (UIImage?) -> Void, + onCancel: @escaping () -> Void ) { self.imageToCrop = imageToCrop self.maskShape = maskShape self.configuration = configuration self.onComplete = onComplete + self.onCancel = onCancel } public var body: some View { @@ -33,7 +37,8 @@ public struct SwiftyCropView: View { image: imageToCrop, maskShape: maskShape, configuration: configuration, - onComplete: onComplete + onComplete: onComplete, + onCancel: onCancel ) } } diff --git a/Sources/SwiftyCrop/View/CropView.swift b/Sources/SwiftyCrop/View/CropView.swift index a61aa47..a314283 100644 --- a/Sources/SwiftyCrop/View/CropView.swift +++ b/Sources/SwiftyCrop/View/CropView.swift @@ -8,18 +8,21 @@ struct CropView: View { private let maskShape: MaskShape private let configuration: SwiftyCropConfiguration private let onComplete: (UIImage?) -> Void + private let onCancel: () -> Void private let localizableTableName: String init( image: UIImage, maskShape: MaskShape, configuration: SwiftyCropConfiguration, - onComplete: @escaping (UIImage?) -> Void + onComplete: @escaping (UIImage?) -> Void, + onCancel: @escaping () -> Void ) { self.image = image self.maskShape = maskShape self.configuration = configuration self.onComplete = onComplete + self.onCancel = onCancel _viewModel = StateObject( wrappedValue: CropViewModel( maskRadius: configuration.maskRadius, @@ -115,6 +118,7 @@ struct CropView: View { HStack { Button { + onCancel() dismiss() } label: { Text("cancel_button", tableName: localizableTableName, bundle: .module)