Skip to content

Commit c7339d9

Browse files
committed
Update LMViewBuilder.
1 parent 2c6730c commit c7339d9

9 files changed

+56
-54
lines changed

LimaTest/ControlsViewController.swift

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ class ControlsViewController: UITableViewController {
3434

3535
sections = [
3636
Section(headerView: UITableViewHeaderFooterView(text: "Buttons"), cells: [
37-
LMTableViewCell(
37+
LMTableViewCell() {
3838
UIButton(configuration: .plain(), primaryAction: UIAction(title: "Plain") { [unowned self] _ in
3939
showGreeting()
4040
})
41-
),
42-
LMTableViewCell(
41+
},
42+
LMTableViewCell() {
4343
UIButton(configuration: .tinted(), primaryAction: UIAction(title: "Toggle") { _ in },
4444
changesSelectionAsPrimaryAction: true)
45-
),
46-
LMTableViewCell(
45+
},
46+
LMTableViewCell() {
4747
UIButton(configuration: .borderedTinted(), primaryAction: UIAction(title: "Pop-Up") { _ in },
4848
menu: UIMenu(children: [
4949
UIAction(title: "One") { _ in },
@@ -53,8 +53,8 @@ class ControlsViewController: UITableViewController {
5353
]),
5454
showsMenuAsPrimaryAction: true,
5555
tintColor: .red)
56-
),
57-
LMTableViewCell(
56+
},
57+
LMTableViewCell() {
5858
UIButton(configuration: .borderedTinted(),
5959
menu: UIMenu(children: [
6060
UIAction(title: "One") { _ in },
@@ -65,57 +65,57 @@ class ControlsViewController: UITableViewController {
6565
showsMenuAsPrimaryAction: true,
6666
changesSelectionAsPrimaryAction: true,
6767
tintColor: .green)
68-
)
68+
}
6969
]),
7070

7171
Section(headerView: UITableViewHeaderFooterView(text: "Text"), cells: [
72-
LMTableViewCell(
72+
LMTableViewCell() {
7373
UITextField(placeholder: "Default")
74-
),
75-
LMTableViewCell(
74+
},
75+
LMTableViewCell() {
7676
UITextField(placeholder: "Number", keyboardType: .numberPad)
77-
),
78-
LMTableViewCell(
77+
},
78+
LMTableViewCell() {
7979
UITextField(placeholder: "Email Address", keyboardType: .emailAddress)
80-
),
81-
LMTableViewCell(
80+
},
81+
LMTableViewCell() {
8282
UITextField(placeholder: "Password", isSecureTextEntry: true)
83-
),
84-
LMTableViewCell(
83+
},
84+
LMTableViewCell() {
8585
UITextView(height: 90) { textView in
8686
textView.textContainer.lineFragmentPadding = 0
8787

8888
textView.text = "This is a multi-line text view."
8989
}
90-
)
90+
}
9191
]),
9292

9393
Section(headerView: UITableViewHeaderFooterView(text: "Selection"), cells: [
9494
UITableViewCell(style: .default, text: "On/Off", selectionStyle: .none) { tableViewCell in
9595
tableViewCell.accessoryView = UISwitch()
9696
},
97-
LMTableViewCell(
97+
LMTableViewCell() {
9898
UISegmentedControl(items: [
9999
"One", "Two", "Three", "Four"
100100
], primaryAction: UIAction() { [unowned self] _ in
101101
segmentedControlValueChanged()
102102
}) {
103103
segmentedControl = $0
104104
}
105-
),
106-
LMTableViewCell(
105+
},
106+
LMTableViewCell() {
107107
UIDatePicker(datePickerMode: .dateAndTime)
108-
)
108+
}
109109
]),
110110

111-
Section(headerView: LMTableViewHeaderFooterView(
111+
Section(headerView: LMTableViewHeaderFooterView() {
112112
LMRowView() {
113113
UILabel(text: "Custom Header", textColor: .gray, font: .preferredFont(forTextStyle: .headline))
114114
LMSpacer()
115115
UIImageView(image: UIImage(systemName: "questionmark.circle"), contentMode: .center, tintColor: .gray)
116116
}
117-
), cells: [
118-
LMTableViewCell(
117+
}, cells: [
118+
LMTableViewCell() {
119119
LMRowView() {
120120
LMSpacer()
121121
UIStepper(primaryAction: UIAction() { [unowned self] action in
@@ -125,29 +125,29 @@ class ControlsViewController: UITableViewController {
125125
}
126126
LMSpacer()
127127
}
128-
),
129-
LMTableViewCell(
128+
},
129+
LMTableViewCell() {
130130
UISlider(primaryAction: UIAction() { [unowned self] action in
131131
sliderValueChanged()
132132
}) {
133133
slider = $0
134134
}
135-
),
136-
LMTableViewCell(
135+
},
136+
LMTableViewCell() {
137137
UIPageControl(pageIndicatorTintColor: .lightGray,
138138
currentPageIndicatorTintColor: .black) { pageControl in
139139
pageControl.numberOfPages = 11
140140

141141
self.pageControl = pageControl
142142
}
143-
),
144-
LMTableViewCell(
143+
},
144+
LMTableViewCell() {
145145
LMColumnView(topMargin: 8, bottomMargin: 8) {
146146
UIProgressView() {
147147
progressView = $0
148148
}
149149
}
150-
)
150+
}
151151
])
152152
]
153153
}

LimaTest/GreetingViewController.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ import Lima
1717

1818
class GreetingViewController: UIViewController {
1919
override func loadView() {
20-
let columnView = LMColumnView() {
21-
UIImageView(image: UIImage(named: "world.png"), contentMode: .scaleAspectFit)
22-
UILabel(text: "Hello, World!", textAlignment: .center)
20+
view = LMScrollView(isFitToWidth: true, backgroundColor: .white) {
21+
LMColumnView() {
22+
UIImageView(image: UIImage(named: "world.png"), contentMode: .scaleAspectFit)
23+
UILabel(text: "Hello, World!", textAlignment: .center)
24+
}
2325
}
24-
25-
view = LMScrollView(isFitToWidth: true,
26-
backgroundColor: .white,
27-
columnView)
2826
}
2927
}
3028

LimaTest/GridAlignmentViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GridAlignmentViewController: UIViewController {
2424

2525
let text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
2626

27-
view = LMScrollView(isFitToWidth: true, backgroundColor: .white,
27+
view = LMScrollView(isFitToWidth: true, backgroundColor: .white) {
2828
LMColumnView(margin: 16) {
2929
// Fill
3030
UILabel(text: text, numberOfLines: 0, with: cellStyle)
@@ -60,6 +60,6 @@ class GridAlignmentViewController: UIViewController {
6060
UILabel(text: text, numberOfLines: 0, weight: 1, with: cellStyle)
6161
}
6262
}
63-
)
63+
}
6464
}
6565
}

LimaTest/HorizontalAlignmentViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class HorizontalAlignmentViewController: UIViewController {
2626
cell.layer.borderColor = UIColor.lightGray.cgColor
2727
}
2828

29-
view = LMScrollView(isFitToWidth: true, backgroundColor: .white,
29+
view = LMScrollView(isFitToWidth: true, backgroundColor: .white) {
3030
LMColumnView(margin: 8) {
3131
// Leading alignment
3232
UILabel(text: "Leading", font: .systemFont(ofSize: 14))
@@ -82,6 +82,6 @@ class HorizontalAlignmentViewController: UIViewController {
8282
UIImageView(image: emailIcon, contentMode: .center, tintColor: .black, weight: 1)
8383
}
8484
}
85-
)
85+
}
8686
}
8787
}

LimaTest/VerticalAlignmentViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class VerticalAlignmentViewController: UIViewController {
2626
cell.layer.borderColor = UIColor.lightGray.cgColor
2727
}
2828

29-
view = LMScrollView(isFitToHeight: true, backgroundColor: .white,
29+
view = LMScrollView(isFitToHeight: true, backgroundColor: .white) {
3030
LMRowView(margin:8) {
3131
// Top alignment
3232
LMColumnView() {
@@ -94,6 +94,6 @@ class VerticalAlignmentViewController: UIViewController {
9494
}
9595
}
9696
}
97-
)
97+
}
9898
}
9999
}

Sources/Lima/LMScrollView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
import UIKit
1616

1717
public extension LMScrollView {
18-
// TODO
1918
convenience init(isFitToWidth: Bool = false, isFitToHeight: Bool = false,
2019
backgroundColor: UIColor? = nil,
2120
weight: CGFloat = .nan,
2221
anchor: LMAnchor = [],
23-
with: ((LMScrollView) -> Void) = { _ in }, _ content: UIView? = nil) {
22+
with: ((LMScrollView) -> Void) = { _ in },
23+
@LMViewBuilder content: () -> UIView) {
2424
self.init()
2525

2626
self.isFitToWidth = isFitToWidth
@@ -33,6 +33,6 @@ public extension LMScrollView {
3333

3434
with(self)
3535

36-
self.content = content
36+
self.content = content()
3737
}
3838
}

Sources/Lima/LMTableViewCell.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
import UIKit
1616

1717
public extension LMTableViewCell {
18-
// TODO
1918
convenience init(accessoryType: UITableViewCell.AccessoryType = .none,
2019
selectionStyle: UITableViewCell.SelectionStyle = .blue,
21-
with: ((LMTableViewCell) -> Void) = { _ in }, _ content: UIView? = nil) {
20+
with: ((LMTableViewCell) -> Void) = { _ in },
21+
@LMViewBuilder content: () -> UIView) {
2222
self.init()
2323

2424
self.accessoryType = accessoryType
2525
self.selectionStyle = selectionStyle
2626

2727
with(self)
2828

29-
setContent(content, ignoreMargins: false)
29+
setContent(content(), ignoreMargins: false)
3030
}
3131
}

Sources/Lima/LMTableViewHeaderFooterView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
import UIKit
1616

1717
public extension LMTableViewHeaderFooterView {
18-
// TODO
19-
convenience init(with: ((LMTableViewHeaderFooterView) -> Void) = { _ in }, _ content: UIView? = nil) {
18+
convenience init(with: ((LMTableViewHeaderFooterView) -> Void) = { _ in },
19+
@LMViewBuilder content: () -> UIView) {
2020
self.init()
2121

2222
with(self)
2323

24-
setContent(content, ignoreMargins: false)
24+
setContent(content(), ignoreMargins: false)
2525
}
2626
}

Sources/Lima/LMViewBuilder.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ public struct LMViewBuilder {
1919
public static func buildBlock(_ subviews: UIView...) -> [UIView] {
2020
return subviews
2121
}
22+
23+
public static func buildBlock(_ content: UIView) -> UIView {
24+
return content
25+
}
2226
}

0 commit comments

Comments
 (0)