Skip to content

Commit 5c18915

Browse files
committed
Some fix
- func setup to func style fix - added func shouldUpdateLayout - removed unused func layoutSubviews
1 parent 03ed41a commit 5c18915

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

Sources/ComponentsKit/Divider/Models/DividerVM.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ extension DividerVM {
3434
return 2.0
3535
}
3636
}
37+
38+
func shouldUpdateLayout(_ oldModel: Self) -> Bool {
39+
return self.orientation != oldModel.orientation
40+
|| self.size != oldModel.size
41+
}
3742
}

Sources/ComponentsKit/Divider/UKDivider.swift

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ open class UKDivider: UIView, UKComponent {
1111
}
1212
}
1313

14+
// MARK: - UIView methods
15+
16+
open override var intrinsicContentSize: CGSize {
17+
return self.sizeThatFits(UIView.layoutFittingExpandedSize)
18+
}
19+
20+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
21+
let lineSize = self.model.lineSize
22+
switch self.model.orientation {
23+
case .vertical:
24+
return CGSize(width: lineSize, height: size.height)
25+
case .horizontal:
26+
return CGSize(width: size.width, height: lineSize)
27+
}
28+
}
29+
1430
// MARK: - Initializers
1531

1632
/// Initializer.
@@ -19,7 +35,7 @@ open class UKDivider: UIView, UKComponent {
1935
public init(model: DividerVM = .init()) {
2036
self.model = model
2137
super.init(frame: .zero)
22-
self.setup()
38+
self.style()
2339
}
2440

2541
public required init?(coder: NSCoder) {
@@ -28,8 +44,10 @@ open class UKDivider: UIView, UKComponent {
2844

2945
// MARK: - Setup
3046

31-
private func setup() {
47+
private func style() {
3248
self.backgroundColor = self.model.color.uiColor
49+
self.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
50+
self.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
3351
}
3452

3553
// MARK: - Update
@@ -39,32 +57,8 @@ open class UKDivider: UIView, UKComponent {
3957

4058
self.backgroundColor = self.model.color.uiColor
4159

42-
if self.model.orientation != oldModel.orientation || self.model.size != oldModel.size {
60+
if self.model.shouldUpdateLayout(oldModel) {
4361
self.invalidateIntrinsicContentSize()
4462
}
45-
46-
self.setNeedsLayout()
47-
}
48-
49-
// MARK: - Layout
50-
51-
open override func layoutSubviews() {
52-
super.layoutSubviews()
53-
}
54-
55-
// MARK: - UIView Properties
56-
57-
open override var intrinsicContentSize: CGSize {
58-
return self.sizeThatFits(UIView.layoutFittingExpandedSize)
59-
}
60-
61-
open override func sizeThatFits(_ size: CGSize) -> CGSize {
62-
let lineSize = self.model.lineSize
63-
switch self.model.orientation {
64-
case .vertical:
65-
return CGSize(width: lineSize, height: size.height)
66-
case .horizontal:
67-
return CGSize(width: size.width, height: lineSize)
68-
}
6963
}
7064
}

0 commit comments

Comments
 (0)