diff --git a/Objective-C/TOCropViewController/TOCropViewController.h b/Objective-C/TOCropViewController/TOCropViewController.h index b894d569..77aaf485 100644 --- a/Objective-C/TOCropViewController/TOCropViewController.h +++ b/Objective-C/TOCropViewController/TOCropViewController.h @@ -317,6 +317,11 @@ */ @property (nullable, nonatomic, strong) NSArray *allowedAspectRatios; +/** + Called when the user hits the Done button. +*/ +@property (nullable, nonatomic, copy) void (^onDidTapDone)(void); + /** When the user hits cancel, or completes a UIActivityViewController operation, this block will be called, diff --git a/Objective-C/TOCropViewController/TOCropViewController.m b/Objective-C/TOCropViewController/TOCropViewController.m index aef0c5da..28af1663 100644 --- a/Objective-C/TOCropViewController/TOCropViewController.m +++ b/Objective-C/TOCropViewController/TOCropViewController.m @@ -894,6 +894,12 @@ - (void)doneButtonTapped { CGRect cropFrame = self.cropView.imageCropFrame; NSInteger angle = self.cropView.angle; + if (self.onDidTapDone) { + dispatch_async(dispatch_get_main_queue(), ^{ + self.onDidTapDone(); + }); + } + // If desired, when the user taps done, show an activity sheet if (self.showActivitySheetOnDone) { TOActivityCroppedImageProvider *imageItem = [[TOActivityCroppedImageProvider alloc] initWithImage:self.image cropFrame:cropFrame angle:angle circular:(self.croppingStyle == TOCropViewCroppingStyleCircular)]; diff --git a/Swift/CropViewController/CropViewController.swift b/Swift/CropViewController/CropViewController.swift index 6144de72..cc387e78 100644 --- a/Swift/CropViewController/CropViewController.swift +++ b/Swift/CropViewController/CropViewController.swift @@ -44,6 +44,11 @@ public typealias CropViewCroppingStyle = TOCropViewCroppingStyle // ------------------------------------------------ @MainActor @objc public protocol CropViewControllerDelegate: NSObjectProtocol { + /** + Called when the user hits the Done button. + */ + @objc optional func cropViewControllerDidTapDone(_ cropViewController: CropViewController) + /** Called when the user has committed the crop action, and provides just the cropping rectangle. @@ -319,7 +324,15 @@ open class CropViewController: UIViewController, TOCropViewControllerDelegate { set { toCropViewController.allowedAspectRatios = newValue } get { return toCropViewController.allowedAspectRatios } } - + + /** + Called when the user hits the Done button. + */ + public var onDidTapDone: (() -> Void)? { + set { toCropViewController.onDidTapDone = newValue } + get { return toCropViewController.onDidTapDone } + } + /** When the user hits cancel, or completes a UIActivityViewController operation, this block will be called, @@ -650,13 +663,21 @@ extension CropViewController { fileprivate func setUpDelegateHandlers() { guard let delegate = self.delegate else { + onDidTapDone = nil onDidCropToRect = nil onDidCropImageToRect = nil onDidCropToCircleImage = nil onDidFinishCancelled = nil return } - + + if delegate.responds(to: #selector((any CropViewControllerDelegate).cropViewControllerDidTapDone(_:))) { + self.onDidTapDone = { [weak self] in + guard let self else { return } + delegate.cropViewControllerDidTapDone?(self) + } + } + if delegate.responds(to: #selector((any CropViewControllerDelegate).cropViewController(_:didCropImageToRect:angle:))) { self.onDidCropImageToRect = {[weak self] rect, angle in guard let strongSelf = self else { return }