From eb6c0e6e714060325fb5e3bf5bd9ca4b0bdefec0 Mon Sep 17 00:00:00 2001 From: Igor Belov Date: Thu, 27 Oct 2022 00:23:34 +0300 Subject: [PATCH] Improve the GreedyImage initializers --- Sources/GreedyKit/SwiftUI/GreedyImage.swift | 34 +++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Sources/GreedyKit/SwiftUI/GreedyImage.swift b/Sources/GreedyKit/SwiftUI/GreedyImage.swift index 0971278..33eb79e 100644 --- a/Sources/GreedyKit/SwiftUI/GreedyImage.swift +++ b/Sources/GreedyKit/SwiftUI/GreedyImage.swift @@ -19,14 +19,26 @@ public struct GreedyImage: UIViewRepresentable { private var contentGravity: AVLayerVideoGravity private let source: SourceType + private init( + source: SourceType, + preventsCapture: Bool, + contentGravity: AVLayerVideoGravity + ) { + self.source = source + self.preventsCapture = preventsCapture + self.contentGravity = contentGravity + } + public init( _ image: UIImage, preventsCapture: Bool, contentGravity: AVLayerVideoGravity = .resizeAspect ) { - self.source = .uiImage(image) - self.preventsCapture = preventsCapture - self.contentGravity = contentGravity + self.init( + source: .uiImage(image), + preventsCapture: preventsCapture, + contentGravity: contentGravity + ) } public init( @@ -34,9 +46,11 @@ public struct GreedyImage: UIViewRepresentable { preventsCapture: Bool, contentGravity: AVLayerVideoGravity = .resizeAspect ) { - self.source = .cgImage(image) - self.preventsCapture = preventsCapture - self.contentGravity = contentGravity + self.init( + source: .cgImage(image), + preventsCapture: preventsCapture, + contentGravity: contentGravity + ) } public init( @@ -44,9 +58,11 @@ public struct GreedyImage: UIViewRepresentable { preventsCapture: Bool, contentGravity: AVLayerVideoGravity = .resizeAspect ) { - self.source = .ciImage(image) - self.preventsCapture = preventsCapture - self.contentGravity = contentGravity + self.init( + source: .ciImage(image), + preventsCapture: preventsCapture, + contentGravity: contentGravity + ) } public func makeUIView(context: Context) -> GreedyImageView {