Skip to content

Commit

Permalink
Merge pull request #4 from trafi/feature/optional-stacking
Browse files Browse the repository at this point in the history
Accept optional ImageModdable
  • Loading branch information
Domas Nutautas authored Jul 24, 2020
2 parents 5b81ee2 + f5497b5 commit 0f42ca0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sources/ImageMod/ImageModable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public extension ImageModable {

// MARK: Stack

func hStack(_ image: ImageModable, spacing: CGFloat = 0, alignment: UIStackView.Alignment = .center) -> ImageModable {
func hStack(_ image: ImageModable?, spacing: CGFloat = 0, alignment: UIStackView.Alignment = .center) -> ImageModable {
guard let image = image else { return self }
let rect = image.canvasSize.vAlign(in: canvasSize, alignment: alignment)
return self
.padded(right: rect.maxX + spacing)
Expand All @@ -91,7 +92,8 @@ public extension ImageModable {
)
}

func vStack(_ image: ImageModable, spacing: CGFloat = 0, alignment: UIStackView.Alignment = .center) -> ImageModable {
func vStack(_ image: ImageModable?, spacing: CGFloat = 0, alignment: UIStackView.Alignment = .center) -> ImageModable {
guard let image = image else { return self }
let rect = image.canvasSize.hAlign(in: canvasSize, alignment: alignment)
return self
.padded(bottom: rect.maxY + spacing)
Expand All @@ -103,7 +105,8 @@ public extension ImageModable {
)
}

func zStack(_ overlay: ImageModable, alignment: UIView.ContentMode = .center) -> ImageModable {
func zStack(_ overlay: ImageModable?, alignment: UIView.ContentMode = .center) -> ImageModable {
guard let overlay = overlay else { return self }
let rect = overlay.canvasSize.align(in: canvasSize, alignment: alignment)
return with(overlay
.scaled(to: rect.size)
Expand Down

0 comments on commit 0f42ca0

Please sign in to comment.