Skip to content

Commit

Permalink
Supports for-in loop inside block (#77)
Browse files Browse the repository at this point in the history
* 🌲 Update

* 🌲 Update
  • Loading branch information
muukii authored Sep 2, 2022
1 parent 239bc0b commit 5f00b13
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions MondrianLayout/Classic/MondrianArrayBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public struct MondrianArrayBuilder<Element> {
public static func buildEither(second component: [Element]) -> [Element] {
return component
}

public static func buildArray(_ components: [[Element]]) -> [Element] {
components.flatMap { $0 }
}

public static func buildExpression(_ element: Element?) -> [Element] {
return element.map { [$0] } ?? []
Expand Down
8 changes: 8 additions & 0 deletions MondrianLayout/Descriptors/VHStackContentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public enum VStackContentBuilder {
public static func buildEither(second component: [Component]) -> [Component] {
return component
}

public static func buildArray(_ components: [[Component]]) -> [Component] {
return components.flatMap { $0 }
}

public static func buildExpression(_ layoutGuides: [UILayoutGuide]...) -> [Component] {
return layoutGuides.flatMap { $0 }.map {
Expand Down Expand Up @@ -227,6 +231,10 @@ public enum HStackContentBuilder {
public static func buildEither(second component: [Component]) -> [Component] {
return component
}

public static func buildArray(_ components: [[Component]]) -> [Component] {
components.flatMap { $0 }
}

public static func buildExpression(_ views: [UIView]...) -> [Component] {
return views.flatMap { $0 }.map {
Expand Down
4 changes: 4 additions & 0 deletions MondrianLayout/LayoutBlocks/VGridBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public enum VGridContentBuilder {
public static func buildEither(second component: [Component]) -> [Component] {
return component
}

public static func buildArray(_ components: [[Component]]) -> [Component] {
components.flatMap { $0 }
}

public static func buildExpression(_ views: [UIView]...) -> [Component] {
return views.flatMap { $0 }.map {
Expand Down
6 changes: 5 additions & 1 deletion MondrianLayout/LayoutBlocks/ZStackBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ public enum ZStackContentBuilder {
public static func buildEither(second component: [Component]) -> [Component] {
return component
}


public static func buildArray(_ components: [[Component]]) -> [Component] {
components.flatMap { $0 }
}

public static func buildExpression(_ layoutGuides: [UILayoutGuide]...) -> [Component] {
return layoutGuides.flatMap { $0 }.map {
.init(node: .layoutGuide(.init($0)))
Expand Down

0 comments on commit 5f00b13

Please sign in to comment.