Skip to content

Commit

Permalink
Add functions for didFinish and didCancel (#176)
Browse files Browse the repository at this point in the history
Implement distinct callback functions onDone() and onCancel() for SwiftUIPhotosCropView which will be called from cropViewController on didFinish and didCancel
  • Loading branch information
andre0805 committed Aug 21, 2022
1 parent 3c67856 commit 62737a4
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ public struct SwiftUIPhotosCropView: UIViewControllerRepresentable {
public typealias UIViewControllerType = PhotosCropViewController

private let editingStack: EditingStack
private let onCompleted: () -> Void

public init(editingStack: EditingStack, onCompleted: @escaping () -> Void) {
private let onDone: () -> Void
private let onCancel: () -> Void

public init(editingStack: EditingStack, onDone: @escaping () -> Void, onCancel: @escaping () -> Void) {
self.editingStack = editingStack
self.onCompleted = onCompleted
self.onDone = onDone
self.onCancel = onCancel
editingStack.start()
}

public func makeUIViewController(context: Context) -> PhotosCropViewController {
let cropViewController = PhotosCropViewController(editingStack: editingStack)
cropViewController.handlers.didFinish = { _ in
onCompleted()
onDone()
}
cropViewController.handlers.didCancel = { _ in
onCompleted()
onCancel()
}
return cropViewController
}
Expand Down

0 comments on commit 62737a4

Please sign in to comment.