diff --git a/Sources/LayoutSpecBuilders/Layout/BackgroundLayout.swift b/Sources/LayoutSpecBuilders/Layout/BackgroundLayout.swift index 69895d9..db60cb0 100644 --- a/Sources/LayoutSpecBuilders/Layout/BackgroundLayout.swift +++ b/Sources/LayoutSpecBuilders/Layout/BackgroundLayout.swift @@ -13,7 +13,10 @@ public struct BackgroundLayout : _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() + ) ] } diff --git a/Sources/LayoutSpecBuilders/Layout/OverlayLayout.swift b/Sources/LayoutSpecBuilders/Layout/OverlayLayout.swift index 10b4317..c40b3c9 100644 --- a/Sources/LayoutSpecBuilders/Layout/OverlayLayout.swift +++ b/Sources/LayoutSpecBuilders/Layout/OverlayLayout.swift @@ -12,7 +12,10 @@ public struct OverlayLayout : _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() + ) ] } diff --git a/Sources/LayoutSpecBuilders/Modifiers.swift b/Sources/LayoutSpecBuilders/Modifiers.swift index 9d3e92c..2638319 100644 --- a/Sources/LayoutSpecBuilders/Modifiers.swift +++ b/Sources/LayoutSpecBuilders/Modifiers.swift @@ -138,10 +138,18 @@ extension _ASLayoutElementType { public func background(_ backgroundContent: Background) -> BackgroundLayout { BackgroundLayout(content: { self }, background: { backgroundContent }) } + + public func background(@ASLayoutSpecBuilder _ backgroundContent: () -> Background) -> BackgroundLayout { + BackgroundLayout(content: { self }, background: backgroundContent) + } public func overlay(_ overlayContent: Overlay) -> OverlayLayout { OverlayLayout(content: { self }, overlay: { overlayContent }) } + + public func overlay(@ASLayoutSpecBuilder _ overlayContent: () -> Overlay) -> OverlayLayout { + OverlayLayout(content: { self }, overlay: overlayContent) + } /// Make aspectRatio ///