Skip to content

Commit

Permalink
allow spec builders in overlay() and background() (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnEstropia authored Feb 10, 2022
1 parent 14db8e3 commit b86e101
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Sources/LayoutSpecBuilders/Layout/BackgroundLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public struct BackgroundLayout<BackgroundContnt, Content> : _ASLayoutElementType

public func tss_make() -> [ASLayoutElement] {
[
ASBackgroundLayoutSpec(child: content.tss_make().first!, background: background.tss_make().first!)
ASBackgroundLayoutSpec(
child: content.tss_make().first!,
background: background.tss_make().first ?? ASLayoutSpec()
)
]
}

Expand Down
5 changes: 4 additions & 1 deletion Sources/LayoutSpecBuilders/Layout/OverlayLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public struct OverlayLayout<OverlayContnt, Content> : _ASLayoutElementType where

public func tss_make() -> [ASLayoutElement] {
[
ASOverlayLayoutSpec(child: content.tss_make().first!, overlay: overlay.tss_make().first!)
ASOverlayLayoutSpec(
child: content.tss_make().first!,
overlay: overlay.tss_make().first ?? ASLayoutSpec()
)
]
}

Expand Down
8 changes: 8 additions & 0 deletions Sources/LayoutSpecBuilders/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,18 @@ extension _ASLayoutElementType {
public func background<Background: _ASLayoutElementType>(_ backgroundContent: Background) -> BackgroundLayout<Background, Self> {
BackgroundLayout(content: { self }, background: { backgroundContent })
}

public func background<Background: _ASLayoutElementType>(@ASLayoutSpecBuilder _ backgroundContent: () -> Background) -> BackgroundLayout<Background, Self> {
BackgroundLayout(content: { self }, background: backgroundContent)
}

public func overlay<Overlay: _ASLayoutElementType>(_ overlayContent: Overlay) -> OverlayLayout<Overlay, Self> {
OverlayLayout(content: { self }, overlay: { overlayContent })
}

public func overlay<Overlay: _ASLayoutElementType>(@ASLayoutSpecBuilder _ overlayContent: () -> Overlay) -> OverlayLayout<Overlay, Self> {
OverlayLayout(content: { self }, overlay: overlayContent)
}

/// Make aspectRatio
///
Expand Down

0 comments on commit b86e101

Please sign in to comment.