Skip to content

Commit b86e101

Browse files
authored
allow spec builders in overlay() and background() (#77)
1 parent 14db8e3 commit b86e101

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

Sources/LayoutSpecBuilders/Layout/BackgroundLayout.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ public struct BackgroundLayout<BackgroundContnt, Content> : _ASLayoutElementType
1313

1414
public func tss_make() -> [ASLayoutElement] {
1515
[
16-
ASBackgroundLayoutSpec(child: content.tss_make().first!, background: background.tss_make().first!)
16+
ASBackgroundLayoutSpec(
17+
child: content.tss_make().first!,
18+
background: background.tss_make().first ?? ASLayoutSpec()
19+
)
1720
]
1821
}
1922

Sources/LayoutSpecBuilders/Layout/OverlayLayout.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public struct OverlayLayout<OverlayContnt, Content> : _ASLayoutElementType where
1212

1313
public func tss_make() -> [ASLayoutElement] {
1414
[
15-
ASOverlayLayoutSpec(child: content.tss_make().first!, overlay: overlay.tss_make().first!)
15+
ASOverlayLayoutSpec(
16+
child: content.tss_make().first!,
17+
overlay: overlay.tss_make().first ?? ASLayoutSpec()
18+
)
1619
]
1720
}
1821

Sources/LayoutSpecBuilders/Modifiers.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,18 @@ extension _ASLayoutElementType {
138138
public func background<Background: _ASLayoutElementType>(_ backgroundContent: Background) -> BackgroundLayout<Background, Self> {
139139
BackgroundLayout(content: { self }, background: { backgroundContent })
140140
}
141+
142+
public func background<Background: _ASLayoutElementType>(@ASLayoutSpecBuilder _ backgroundContent: () -> Background) -> BackgroundLayout<Background, Self> {
143+
BackgroundLayout(content: { self }, background: backgroundContent)
144+
}
141145

142146
public func overlay<Overlay: _ASLayoutElementType>(_ overlayContent: Overlay) -> OverlayLayout<Overlay, Self> {
143147
OverlayLayout(content: { self }, overlay: { overlayContent })
144148
}
149+
150+
public func overlay<Overlay: _ASLayoutElementType>(@ASLayoutSpecBuilder _ overlayContent: () -> Overlay) -> OverlayLayout<Overlay, Self> {
151+
OverlayLayout(content: { self }, overlay: overlayContent)
152+
}
145153

146154
/// Make aspectRatio
147155
///

0 commit comments

Comments
 (0)