Skip to content

Commit

Permalink
Improve the GreedyImage initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
igooor-bb committed Oct 26, 2022
1 parent b2ff6c5 commit eb6c0e6
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions Sources/GreedyKit/SwiftUI/GreedyImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,50 @@ 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(
_ image: CGImage,
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(
_ image: CIImage,
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 {
Expand Down

0 comments on commit eb6c0e6

Please sign in to comment.