From 46d936264c2d32fbce64cd8149b27d060df3a48f Mon Sep 17 00:00:00 2001 From: Benedikt Betz Date: Thu, 19 Oct 2023 13:56:09 +0200 Subject: Updated Package implementation, Tests and README --- Sources/SwiftyCrop/Models/Configuration.swift | 17 --------------- Sources/SwiftyCrop/Models/MaskShape.swift | 2 +- .../Models/SwiftyCropConfiguration.swift | 17 +++++++++++++++ Sources/SwiftyCrop/SwiftyCrop.swift | 24 ++++++++++++++++------ Sources/SwiftyCrop/View/CropView.swift | 6 +++--- 5 files changed, 39 insertions(+), 27 deletions(-) delete mode 100644 Sources/SwiftyCrop/Models/Configuration.swift create mode 100644 Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift (limited to 'Sources') diff --git a/Sources/SwiftyCrop/Models/Configuration.swift b/Sources/SwiftyCrop/Models/Configuration.swift deleted file mode 100644 index bacdab0..0000000 --- a/Sources/SwiftyCrop/Models/Configuration.swift +++ /dev/null @@ -1,17 +0,0 @@ -import CoreGraphics - -/// `SwiftyCropConfiguration` is a struct that defines the configuration for cropping behavior. -struct SwiftyCropConfiguration { - let maxMagnificationScale: CGFloat - let maskRadius: CGFloat - - /// Creates a new instance of `SwiftyCropConfiguration`. - /// - /// - Parameters: - /// - maxMagnificationScale: The maximum scale factor that the image can be magnified while cropping. Defaults to `4.0`. - /// - maskRadius: The radius of the mask used for cropping. Defaults to `130`. - init(maxMagnificationScale: CGFloat = 4.0, maskRadius: CGFloat = 130) { - self.maxMagnificationScale = maxMagnificationScale - self.maskRadius = maskRadius - } -} diff --git a/Sources/SwiftyCrop/Models/MaskShape.swift b/Sources/SwiftyCrop/Models/MaskShape.swift index c4b1538..d20e722 100644 --- a/Sources/SwiftyCrop/Models/MaskShape.swift +++ b/Sources/SwiftyCrop/Models/MaskShape.swift @@ -1,3 +1,3 @@ -enum MaskShape { +public enum MaskShape { case circle, square } diff --git a/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift b/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift new file mode 100644 index 0000000..cc3d47a --- /dev/null +++ b/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift @@ -0,0 +1,17 @@ +import CoreGraphics + +/// `SwiftyCropConfiguration` is a struct that defines the configuration for cropping behavior. +public struct SwiftyCropConfiguration { + let maxMagnificationScale: CGFloat + let maskRadius: CGFloat + + /// Creates a new instance of `SwiftyCropConfiguration`. + /// + /// - Parameters: + /// - maxMagnificationScale: The maximum scale factor that the image can be magnified while cropping. Defaults to `4.0`. + /// - maskRadius: The radius of the mask used for cropping. Defaults to `130`. + public init(maxMagnificationScale: CGFloat = 4.0, maskRadius: CGFloat = 130) { + self.maxMagnificationScale = maxMagnificationScale + self.maskRadius = maskRadius + } +} diff --git a/Sources/SwiftyCrop/SwiftyCrop.swift b/Sources/SwiftyCrop/SwiftyCrop.swift index ab252e6..0de933d 100644 --- a/Sources/SwiftyCrop/SwiftyCrop.swift +++ b/Sources/SwiftyCrop/SwiftyCrop.swift @@ -9,13 +9,25 @@ import SwiftUI /// - 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. -struct SwiftyCropView: View { - let imageToCrop: UIImage - let maskShape: MaskShape - let configuration: SwiftyCropConfiguration = SwiftyCropConfiguration() - let onComplete: (UIImage?) -> Void +public struct SwiftyCropView: View { + private let imageToCrop: UIImage + private let maskShape: MaskShape + private let configuration: SwiftyCropConfiguration + private let onComplete: (UIImage?) -> Void - var body: some View { + 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, diff --git a/Sources/SwiftyCrop/View/CropView.swift b/Sources/SwiftyCrop/View/CropView.swift index 29cfb8a..3cb453a 100644 --- a/Sources/SwiftyCrop/View/CropView.swift +++ b/Sources/SwiftyCrop/View/CropView.swift @@ -31,7 +31,7 @@ struct CropView: View { var body: some View { VStack { - Text("interaction_instructions", tableName: localizableTableName) + Text("interaction_instructions", tableName: localizableTableName, bundle: .module) .font(.system(size: 16, weight: .regular)) .foregroundColor(.white) .padding(.top, 30) @@ -100,7 +100,7 @@ struct CropView: View { Button { dismiss() } label: { - Text("cancel_button", tableName: localizableTableName) + Text("cancel_button", tableName: localizableTableName, bundle: .module) } .foregroundColor(.white) @@ -110,7 +110,7 @@ struct CropView: View { onComplete(viewModel.crop(image)) dismiss() } label: { - Text("save_button", tableName: localizableTableName) + Text("save_button", tableName: localizableTableName, bundle: .module) } .foregroundColor(.white) } -- cgit v1.2.3