blob: 0de933ddcb9ded5db95746f595fb84a9c4e7b725 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import SwiftUI
/// `SwiftyCropView` is a SwiftUI view for cropping images.
///
/// You can customize the cropping behavior using a `SwiftyCropConfiguration` instance and a completion handler.
///
/// - Parameters:
/// - imageToCrop: The image to be cropped.
/// - maskShape: The shape of the mask used for cropping.
/// - 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.
public struct SwiftyCropView: View {
private let imageToCrop: UIImage
private let maskShape: MaskShape
private let configuration: SwiftyCropConfiguration
private let onComplete: (UIImage?) -> Void
public init(
imageToCrop: UIImage,
maskShape: MaskShape,
configuration: SwiftyCropConfiguration = SwiftyCropConfiguration(),
onComplete: @escaping (UIImage?) -> Void
) {
self.imageToCrop = imageToCrop
self.maskShape = maskShape
self.configuration = configuration
self.onComplete = onComplete
}
public var body: some View {
CropView(
image: imageToCrop,
maskShape: maskShape,
configuration: configuration,
onComplete: onComplete
)
}
}
|