Skip to content

Commit 6baa1b6

Browse files
committed
cleanup code
1 parent 4080ab7 commit 6baa1b6

File tree

5 files changed

+61
-53
lines changed

5 files changed

+61
-53
lines changed

Components/Sources/Common/Models/Styles/BakgroundStyle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010
public enum BackgroundStyle: Equatable {
1111

1212
/// Solid background filled with single color
13-
case solid(UIColor)
13+
case solid(UIColor?)
1414

1515
// TODO: - gradient, image, bezierPath, bordered
1616

Components/Sources/Common/Protocols/Editor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public struct EditorBuilder<T: Editor> {
3737

3838
// to use like if-else
3939

40-
public static func buildEither(first component: T) -> T {
40+
public static func buildEither(first component: [T]) -> [T] {
4141
return component
4242
}
4343

44-
public static func buildEither(second component: T) -> T {
44+
public static func buildEither(second component: [T]) -> [T] {
4545
return component
4646
}
4747

Components/Sources/Common/Views/LabelView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import UIKit
99
import ReactiveDataDisplayManager
1010

11+
public typealias LabelProperty = LabelView.Model.Property
12+
1113
/// Base view to implement label within cell
1214
public class LabelView: UIView {
1315

Components/Sources/Common/Views/MessageView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import UIKit
99
import ReactiveDataDisplayManager
1010

11+
public typealias MessageProperty = MessageView.Model.Property
12+
1113
/// Base view to implement label within cell
1214
public class MessageView: UIView {
1315

@@ -114,7 +116,7 @@ extension MessageView: ConfigurableItem {
114116
private(set) public var backgroundStyle: BackgroundStyle = .solid(.clear)
115117
private(set) public var alignment: Alignment = .all(.zero)
116118
private(set) public var internalEdgeInsets: UIEdgeInsets = .zero
117-
private(set) public var borderStyle: BorderStyle? = nil
119+
private(set) public var borderStyle: BorderStyle?
118120

119121
// MARK: - Mutation
120122

Example/ReactiveDataDisplayManager/Table/ComponentsOverviewTableViewController/ComponentsOverviewTableViewController.swift

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ final class ComponentsOverviewTableViewController: UIViewController {
3434
private let recievedMessageTimeStyle = TextStyle(color: .gray, font: .systemFont(ofSize: 12, weight: .light))
3535
private let recievedMessageTimeLayout = TextLayout(lineBreakMode: .byWordWrapping, numberOfLines: 0)
3636
private lazy var recievedMessageTimeModel: LabelView.Model = .build {
37-
LabelView.Model.Property.text(.string("17:05"))
38-
LabelView.Model.Property.style(recievedMessageTimeStyle)
39-
LabelView.Model.Property.layout(recievedMessageTimeLayout)
40-
LabelView.Model.Property.textAlignment(.left)
41-
LabelView.Model.Property.alignment(.leading(UIEdgeInsets(top: 12,
42-
left: 16,
43-
bottom: 12,
44-
right: 0)))
37+
LabelProperty.text(.string("17:05"))
38+
LabelProperty.style(recievedMessageTimeStyle)
39+
LabelProperty.layout(recievedMessageTimeLayout)
40+
LabelProperty.textAlignment(.left)
41+
LabelProperty.alignment(.leading(UIEdgeInsets(top: 12,
42+
left: 16,
43+
bottom: 12,
44+
right: 0)))
4545
}
4646

4747
private lazy var recievedMessageTimeGenerator = LabelView.rddm.tableGenerator(with: recievedMessageTimeModel, and: .class)
@@ -50,14 +50,14 @@ final class ComponentsOverviewTableViewController: UIViewController {
5050
private let sentTimeMessageStyle = TextStyle(color: .gray, font: .systemFont(ofSize: 12, weight: .light))
5151
private let sentTimeMessageLayout = TextLayout(lineBreakMode: .byWordWrapping, numberOfLines: 0)
5252
private lazy var sentTimeMessageModel: LabelView.Model = .build {
53-
LabelView.Model.Property.text(.string("17:32"))
54-
LabelView.Model.Property.style(sentTimeMessageStyle)
55-
LabelView.Model.Property.layout(sentTimeMessageLayout)
56-
LabelView.Model.Property.textAlignment(.right)
57-
LabelView.Model.Property.alignment(.trailing(UIEdgeInsets(top: 12,
58-
left: 0,
59-
bottom: 12,
60-
right: 16)))
53+
LabelProperty.text(.string("17:32"))
54+
LabelProperty.style(sentTimeMessageStyle)
55+
LabelProperty.layout(sentTimeMessageLayout)
56+
LabelProperty.textAlignment(.right)
57+
LabelProperty.alignment(.trailing(UIEdgeInsets(top: 12,
58+
left: 0,
59+
bottom: 12,
60+
right: 16)))
6161
}
6262

6363
private lazy var sentMessageTimeGenerator = LabelView.rddm.tableGenerator(with: sentTimeMessageModel, and: .class)
@@ -66,14 +66,14 @@ final class ComponentsOverviewTableViewController: UIViewController {
6666
private let dateStyle = TextStyle(color: .black, font: .systemFont(ofSize: 12, weight: .light))
6767
private let dateLayout = TextLayout(lineBreakMode: .byWordWrapping, numberOfLines: 0)
6868
private lazy var dateModel: LabelView.Model = .build {
69-
LabelView.Model.Property.text(.string("24 мая 2023"))
70-
LabelView.Model.Property.style(dateStyle)
71-
LabelView.Model.Property.layout(dateLayout)
72-
LabelView.Model.Property.textAlignment(.center)
73-
LabelView.Model.Property.alignment(.all(UIEdgeInsets(top: 0,
74-
left: 0,
75-
bottom: 12,
76-
right: 0)))
69+
LabelProperty.text(.string("24 мая 2023"))
70+
LabelProperty.style(dateStyle)
71+
LabelProperty.layout(dateLayout)
72+
LabelProperty.textAlignment(.center)
73+
LabelProperty.alignment(.all(UIEdgeInsets(top: 0,
74+
left: 0,
75+
bottom: 12,
76+
right: 0)))
7777
}
7878

7979
private lazy var dateGenerator = LabelView.rddm.tableGenerator(with: dateModel, and: .class)
@@ -84,20 +84,24 @@ final class ComponentsOverviewTableViewController: UIViewController {
8484
private let sentMessageBorderStyle = BorderStyle(cornerRadius: 9,
8585
maskedCorners: [.layerMinXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMinYCorner])
8686
private lazy var sentMessageModel: MessageView.Model = .build {
87-
MessageView.Model.Property.background(.solid(.systemBlue))
88-
MessageView.Model.Property.border(sentMessageBorderStyle)
89-
MessageView.Model.Property.style(sentMessageStyle)
90-
MessageView.Model.Property.textAlignment(.right)
91-
MessageView.Model.Property.alignment(.trailing(UIEdgeInsets(top: 12,
92-
left: UIScreen.main.bounds.width / 2,
93-
bottom: 12,
94-
right: 16)
95-
))
96-
MessageView.Model.Property.insets(UIEdgeInsets(top: 3,
97-
left: 5,
98-
bottom: 3,
99-
right: 5))
100-
MessageView.Model.Property.text(.string("Lorem"))
87+
if Bool.random() {
88+
MessageProperty.background(.solid(.systemBlue))
89+
} else {
90+
MessageProperty.background(.solid(.rddm))
91+
}
92+
MessageProperty.border(sentMessageBorderStyle)
93+
MessageProperty.style(sentMessageStyle)
94+
MessageProperty.textAlignment(.right)
95+
MessageProperty.alignment(.trailing(UIEdgeInsets(top: 12,
96+
left: UIScreen.main.bounds.width / 2,
97+
bottom: 12,
98+
right: 16)
99+
))
100+
MessageProperty.insets(UIEdgeInsets(top: 3,
101+
left: 5,
102+
bottom: 3,
103+
right: 5))
104+
MessageProperty.text(.string("Lorem"))
101105
}
102106

103107
private lazy var sentMessageGenerator = MessageView.rddm.tableGenerator(with: sentMessageModel, and: .class)
@@ -113,17 +117,17 @@ final class ComponentsOverviewTableViewController: UIViewController {
113117
borderWidth: 1,
114118
borderColor: UIColor.black.cgColor)
115119
private lazy var recievedMessageModel: MessageView.Model = .build {
116-
MessageView.Model.Property.border(recievedMessageBorderStyle)
117-
MessageView.Model.Property.style(recievedMessageStyle)
118-
MessageView.Model.Property.alignment(.leading(UIEdgeInsets(top: 12,
119-
left: 16,
120-
bottom: 12,
121-
right: UIScreen.main.bounds.width / 2)))
122-
MessageView.Model.Property.insets(UIEdgeInsets(top: 3,
123-
left: 5,
124-
bottom: 3,
125-
right: 5))
126-
MessageView.Model.Property.text(.string("Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"))
120+
MessageProperty.border(recievedMessageBorderStyle)
121+
MessageProperty.style(recievedMessageStyle)
122+
MessageProperty.alignment(.leading(UIEdgeInsets(top: 12,
123+
left: 16,
124+
bottom: 12,
125+
right: UIScreen.main.bounds.width / 2)))
126+
MessageProperty.insets(UIEdgeInsets(top: 3,
127+
left: 5,
128+
bottom: 3,
129+
right: 5))
130+
MessageProperty.text(.string("Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"))
127131
}
128132

129133
private lazy var recievedMessageGenerator = MessageView.rddm.tableGenerator(with: recievedMessageModel, and: .class)

0 commit comments

Comments
 (0)