@@ -11,6 +11,22 @@ open class UKDivider: UIView, UKComponent {
11
11
}
12
12
}
13
13
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
+
14
30
// MARK: - Initializers
15
31
16
32
/// Initializer.
@@ -19,7 +35,7 @@ open class UKDivider: UIView, UKComponent {
19
35
public init ( model: DividerVM = . init( ) ) {
20
36
self . model = model
21
37
super. init ( frame: . zero)
22
- self . setup ( )
38
+ self . style ( )
23
39
}
24
40
25
41
public required init ? ( coder: NSCoder ) {
@@ -28,8 +44,10 @@ open class UKDivider: UIView, UKComponent {
28
44
29
45
// MARK: - Setup
30
46
31
- private func setup ( ) {
47
+ private func style ( ) {
32
48
self . backgroundColor = self . model. color. uiColor
49
+ self . setContentCompressionResistancePriority ( . defaultLow, for: . horizontal)
50
+ self . setContentCompressionResistancePriority ( . defaultLow, for: . vertical)
33
51
}
34
52
35
53
// MARK: - Update
@@ -39,32 +57,8 @@ open class UKDivider: UIView, UKComponent {
39
57
40
58
self . backgroundColor = self . model. color. uiColor
41
59
42
- if self . model. orientation != oldModel. orientation || self . model . size != oldModel . size {
60
+ if self . model. shouldUpdateLayout ( oldModel) {
43
61
self . invalidateIntrinsicContentSize ( )
44
62
}
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
- }
69
63
}
70
64
}
0 commit comments