Skip to content
Open
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
5 changes: 5 additions & 0 deletions Objective-C/TOCropViewController/TOCropViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@
*/
@property (nullable, nonatomic, strong) NSArray<TOCropViewControllerAspectRatioPreset *> *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,
Expand Down
6 changes: 6 additions & 0 deletions Objective-C/TOCropViewController/TOCropViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
25 changes: 23 additions & 2 deletions Swift/CropViewController/CropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 }
Expand Down