TOCropViewController icon indicating copy to clipboard operation
TOCropViewController copied to clipboard

fix: double calling of delegate

Open Ans3301 opened this issue 1 year ago • 3 comments

I encountered a bug: I created a custom class that inherited from CropViewController and made an extension for this class, which implemented the CropViewControllerDelegate. When I initialized the delegate in the class constructor with a reference to the class itself, the delegate methods started executing twice. This pull request is a fix.

Ans3301 avatar Nov 29 '24 17:11 Ans3301

Hey @Ans3301! Thanks for the PR!

Hmm, the idea was to in fact allow the delegate and the blocks to execute at the same time in case the user wanted it, so I feel like changing the logic to choose between the two might break expectations for a lot of people. Are you sure you can't fix this some other way?

TimOliver avatar Dec 10 '24 13:12 TimOliver

Hi @TimOliver! Thanks for your response! I understand that this is a breaking change, but I don't quite understand in what use case two calls might be needed. Could you please provide an example of such usage?

Ans3301 avatar Dec 18 '24 13:12 Ans3301

If I have to pick an example, my old favorite is 'logging'. :)

The main concern I have is this might break existing implementations. This wasn't a great pattern for me to choose originally. Next time I'll probably only stick to delegates. 😅

Maybe a good way to solve this is add a new enum, like TOCropViewControllerCallbackType and then give it options like TOCropViewControllerCallbackTypeDefault, TOCropViewControllerCallbackTypeDelegate, and TOCropViewControllerCallbackBlock so it's possible to control externally this behavior. :)

Let me know what you think!

TimOliver avatar Feb 26 '25 13:02 TimOliver

Closing this off for now. If you'd like to pick it back up, let me know. Thanks! :)

TimOliver avatar Sep 23 '25 08:09 TimOliver