Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Commit 50b860f

Browse files
nbadakhstaguer
authored andcommitted
Exposed properties in LOK classes (#221)
* Exposed properties in LOK classes Exposed properties in following classes: - LOKStackLayout - LOKInsetLayout - LOKLabelLayout - LOKButtonLayout - LOKOverlayLayout - LOKTextViewLayout
1 parent 49387c9 commit 50b860f

File tree

8 files changed

+184
-57
lines changed

8 files changed

+184
-57
lines changed

Sources/Layouts/SizeLayout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ open class SizeLayout<V: View>: BaseLayout<V>, ConfigurableLayout {
215215

216216
// MARK: - Initialization helpers
217217

218-
private static func defaultAlignment(maxWidth: CGFloat?, maxHeight: CGFloat?) -> Alignment {
218+
static func defaultAlignment(maxWidth: CGFloat?, maxHeight: CGFloat?) -> Alignment {
219219
return Alignment(vertical: maxHeight == nil ? .fill : .center,
220220
horizontal: maxWidth == nil ? .fill : .center)
221221
}

Sources/ObjCSupport/LOKButtonLayout.swift

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
import UIKit
1010

1111
@objc open class LOKButtonLayout: LOKBaseLayout {
12+
@objc public let type: LOKButtonLayoutType
13+
@objc public let title: String
14+
@objc public let image: UIImage?
15+
@objc public let imageSize: CGSize
16+
@objc public let font: UIFont?
17+
@objc public let contentEdgeInsets: NSValue?
18+
@objc public let alignment: LOKAlignment
19+
@objc public let viewClass: UIButton.Type
20+
@objc public let config: ((UIButton) -> Void)?
21+
1222
@objc public init(type: LOKButtonLayoutType,
1323
title: String?,
1424
image: UIImage?,
@@ -38,17 +48,26 @@ import UIKit
3848
} else {
3949
buttonLayoutImage = .size(imageSize)
4050
}
51+
self.type = type
52+
self.title = title ?? ""
53+
self.image = image
54+
self.imageSize = imageSize
55+
self.font = font
56+
self.contentEdgeInsets = contentEdgeInsets
57+
self.alignment = alignment ?? LOKAlignment(alignment: ButtonLayoutDefaults.defaultAlignment)
58+
self.viewClass = viewClass ?? UIButton.self
59+
self.config = config
4160
let layout = ButtonLayout(
42-
type: type.unwrapped,
43-
title: title ?? "",
61+
type: self.type.unwrapped,
62+
title: self.title,
4463
image: buttonLayoutImage,
45-
font: font,
64+
font: self.font,
4665
contentEdgeInsets: insets,
47-
alignment: alignment?.alignment ?? ButtonLayoutDefaults.defaultAlignment,
66+
alignment: self.alignment.alignment,
4867
flexibility: flexibility?.flexibility ?? ButtonLayoutDefaults.defaultFlexibility,
4968
viewReuseId: viewReuseId,
50-
viewClass: viewClass,
51-
config: config)
69+
viewClass: self.viewClass,
70+
config: self.config)
5271
super.init(layout: layout)
5372
}
5473
}

Sources/ObjCSupport/LOKInsetLayout.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,30 @@
99
import CoreGraphics
1010

1111
@objc open class LOKInsetLayout: LOKBaseLayout {
12+
@objc public let insets: EdgeInsets
13+
@objc public let alignment: LOKAlignment
14+
@objc public let viewClass: View.Type
15+
@objc public let sublayout: LOKLayout
16+
@objc public let configure: ((View) -> Void)?
17+
1218
@objc public init(insets: EdgeInsets,
1319
alignment: LOKAlignment? = nil,
1420
viewReuseId: String? = nil,
1521
viewClass: View.Type? = nil,
1622
sublayout: LOKLayout,
1723
configure: ((View) -> Void)? = nil) {
24+
self.insets = insets
25+
self.sublayout = sublayout
26+
self.alignment = alignment ?? .fill
27+
self.viewClass = viewClass ?? View.self
28+
self.configure = configure
1829
let layout = InsetLayout(
19-
insets: insets,
20-
alignment: alignment?.alignment ?? .fill,
30+
insets: self.insets,
31+
alignment: self.alignment.alignment,
2132
viewReuseId: viewReuseId,
22-
sublayout: sublayout.unwrapped,
23-
viewClass: viewClass ?? View.self,
24-
config: configure)
33+
sublayout: self.sublayout.unwrapped,
34+
viewClass: self.viewClass,
35+
config: self.configure)
2536
super.init(layout: layout)
2637
}
2738

Sources/ObjCSupport/LOKLabelLayout.swift

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
import UIKit
1010

1111
@objc open class LOKLabelLayout: LOKBaseLayout {
12+
@objc public let attributedString: NSAttributedString?
13+
@objc public let string: String?
14+
@objc public let lineHeight: CGFloat
15+
@objc public let font: UIFont
16+
@objc public let numberOfLines: Int
17+
@objc public let alignment: LOKAlignment
18+
@objc public let viewClass: UILabel.Type
19+
@objc public let configure: ((UILabel) -> Void)?
20+
1221
@objc public init(attributedString: NSAttributedString,
1322
font: UIFont?,
1423
lineHeight: CGFloat,
@@ -18,16 +27,25 @@ import UIKit
1827
viewReuseId: String?,
1928
viewClass: UILabel.Type?,
2029
configure: ((UILabel) -> Void)?) {
30+
self.attributedString = attributedString
31+
self.font = font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize)
32+
self.lineHeight = lineHeight
33+
self.numberOfLines = numberOfLines
34+
self.alignment = alignment ?? .topLeading
35+
self.viewClass = viewClass ?? UILabel.self
36+
self.configure = configure
37+
string = nil
2138
let layout = LabelLayout<UILabel>(
2239
attributedString: attributedString,
23-
font: font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize),
40+
font: self.font,
2441
lineHeight: lineHeight > 0 && lineHeight.isFinite ? lineHeight : Optional<CGFloat>.none,
25-
numberOfLines: numberOfLines,
26-
alignment: alignment?.alignment ?? .topLeading,
42+
numberOfLines: self.numberOfLines,
43+
alignment: self.alignment.alignment,
2744
flexibility: flexibility?.flexibility ?? .flexible,
2845
viewReuseId: viewReuseId,
29-
viewClass: viewClass ?? UILabel.self,
30-
config: configure)
46+
viewClass: self.viewClass,
47+
config: self.configure)
48+
3149
super.init(layout: layout)
3250
}
3351

@@ -40,16 +58,24 @@ import UIKit
4058
viewReuseId: String?,
4159
viewClass: UILabel.Type?,
4260
configure: ((UILabel) -> Void)?) {
61+
self.string = string
62+
self.font = font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize)
63+
self.lineHeight = lineHeight
64+
self.numberOfLines = numberOfLines
65+
self.alignment = alignment ?? .topLeading
66+
self.viewClass = viewClass ?? UILabel.self
67+
self.configure = configure
68+
attributedString = nil
4369
let layout = LabelLayout<UILabel>(
4470
string: string,
45-
font: font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize),
71+
font: self.font,
4672
lineHeight: lineHeight > 0 && lineHeight.isFinite ? lineHeight : Optional<CGFloat>.none,
47-
numberOfLines: numberOfLines,
48-
alignment: alignment?.alignment ?? .topLeading,
73+
numberOfLines: self.numberOfLines,
74+
alignment: self.alignment.alignment,
4975
flexibility: flexibility?.flexibility ?? .flexible,
5076
viewReuseId: viewReuseId,
51-
viewClass: viewClass ?? UILabel.self,
52-
config: configure)
77+
viewClass: self.viewClass,
78+
config: self.configure)
5379
super.init(layout: layout)
5480
}
5581
}

Sources/ObjCSupport/LOKOverlayLayout.swift

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,33 @@
99
import Foundation
1010

1111
@objc open class LOKOverlayLayout: LOKBaseLayout {
12+
@objc public let primary: LOKLayout
13+
@objc public let background: [LOKLayout]
14+
@objc public let overlay: [LOKLayout]
15+
@objc public let alignment: LOKAlignment
16+
@objc public let viewClass: View.Type
17+
@objc public let configure: ((View) -> Void)?
18+
1219
@objc public init(primary: LOKLayout,
1320
background: [LOKLayout]? = nil,
1421
overlay: [LOKLayout]? = nil,
1522
alignment: LOKAlignment? = nil,
1623
viewReuseId: String? = nil,
1724
viewClass: View.Type? = nil,
1825
configure: ((View) -> Void)? = nil) {
26+
self.primary = primary
27+
self.background = background ?? []
28+
self.overlay = overlay ?? []
29+
self.alignment = alignment ?? .fill
30+
self.viewClass = viewClass ?? View.self
31+
self.configure = configure
1932
super.init(layout: OverlayLayout(
20-
primary: primary.unwrapped,
21-
background: background?.map { $0.unwrapped } ?? [],
22-
overlay: overlay?.map { $0.unwrapped } ?? [],
23-
alignment: alignment?.alignment ?? .fill,
33+
primary: self.primary.unwrapped,
34+
background: self.background.map { $0.unwrapped },
35+
overlay: self.overlay.map { $0.unwrapped },
36+
alignment: self.alignment.alignment,
2437
viewReuseId: viewReuseId,
25-
viewClass: viewClass,
26-
config: configure))
38+
viewClass: self.viewClass,
39+
config: self.configure))
2740
}
2841
}

Sources/ObjCSupport/LOKSizeLayout.swift

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
import CoreGraphics
1010

1111
@objc open class LOKSizeLayout: LOKBaseLayout {
12+
@objc public let minWidth: CGFloat
13+
@objc public let maxWidth: CGFloat
14+
@objc public let minHeight: CGFloat
15+
@objc public let maxHeight: CGFloat
16+
@objc public let alignment: LOKAlignment
17+
@objc public let viewClass: View.Type
18+
@objc public let sublayout: LOKLayout?
19+
@objc public let configure: ((View) -> Void)?
20+
1221
@objc public init(minWidth: CGFloat,
1322
maxWidth: CGFloat,
1423
minHeight: CGFloat,
@@ -19,17 +28,26 @@ import CoreGraphics
1928
viewClass: View.Type?,
2029
sublayout: LOKLayout?,
2130
configure: ((View) -> Void)? = nil) {
31+
self.minWidth = minWidth
32+
self.minHeight = minHeight
33+
self.maxWidth = maxWidth
34+
self.maxHeight = maxHeight
35+
self.alignment = alignment ?? LOKAlignment(alignment: SizeLayout.defaultAlignment(maxWidth: maxWidth.isFinite ? maxWidth : nil,
36+
maxHeight: maxHeight.isFinite ? maxHeight : nil))
37+
self.viewClass = viewClass ?? View.self
38+
self.sublayout = sublayout
39+
self.configure = configure
2240
let layout = SizeLayout(
23-
minWidth: minWidth,
24-
maxWidth: maxWidth.isFinite ? maxWidth : nil,
25-
minHeight: minHeight,
26-
maxHeight: maxHeight.isFinite ? maxHeight : nil,
27-
alignment: alignment?.alignment,
41+
minWidth: self.minWidth,
42+
maxWidth: self.maxWidth.isFinite ? self.maxWidth : nil,
43+
minHeight: self.minHeight,
44+
maxHeight: self.maxHeight.isFinite ? self.maxHeight : nil,
45+
alignment: self.alignment.alignment,
2846
flexibility: flexibility?.flexibility,
2947
viewReuseId: viewReuseId,
30-
viewClass: viewClass,
31-
sublayout: sublayout?.unwrapped,
32-
config: configure)
48+
viewClass: self.viewClass,
49+
sublayout: self.sublayout?.unwrapped,
50+
config: self.configure)
3351
super.init(layout: layout)
3452
}
3553
}

Sources/ObjCSupport/LOKStackLayout.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ extension LOKStackLayoutDistribution {
4141
}
4242

4343
@objc open class LOKStackLayout: LOKBaseLayout {
44+
@objc public let axis: LOKAxis
45+
@objc public let spacing: CGFloat
46+
@objc public let distribution: LOKStackLayoutDistribution
47+
@objc public let alignment: LOKAlignment
48+
@objc public let viewClass: View.Type
49+
@objc public let sublayouts: [LOKLayout]
50+
@objc public let configure: ((View) -> Void)?
51+
4452
@objc public init(axis: LOKAxis = .vertical,
4553
spacing: CGFloat = 0,
4654
distribution: LOKStackLayoutDistribution = .`default`,
@@ -50,15 +58,22 @@ extension LOKStackLayoutDistribution {
5058
viewReuseId: String? = nil,
5159
sublayouts: [LOKLayout]?,
5260
configure: ((View) -> Void)? = nil) {
61+
self.axis = axis
62+
self.spacing = spacing
63+
self.distribution = distribution.distribution != nil ? distribution : .fillFlexing
64+
self.sublayouts = sublayouts ?? []
65+
self.alignment = alignment ?? .fill
66+
self.viewClass = viewClass ?? View.self
67+
self.configure = configure
5368
super.init(layout: StackLayout(
54-
axis: axis.axis,
55-
spacing: spacing,
56-
distribution: distribution.distribution ?? .fillFlexing,
57-
alignment: alignment?.alignment ?? .fill,
69+
axis: self.axis.axis,
70+
spacing: self.spacing,
71+
distribution: self.distribution.distribution ?? .fillFlexing,
72+
alignment: self.alignment.alignment,
5873
flexibility: flexibility?.flexibility,
5974
viewReuseId: viewReuseId,
60-
viewClass: viewClass,
61-
sublayouts: sublayouts?.map { $0.unwrapped } ?? [],
62-
config: configure))
75+
viewClass: self.viewClass,
76+
sublayouts: self.sublayouts.map { $0.unwrapped },
77+
config: self.configure))
6378
}
6479
}

Sources/ObjCSupport/LOKTextViewLayout.swift

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
import UIKit
1010

1111
@objc open class LOKTextViewLayout: LOKBaseLayout {
12+
@objc public let attributedText: NSAttributedString?
13+
@objc public let text: String?
14+
@objc public let font: UIFont?
15+
@objc public let lineFragmentPadding: CGFloat
16+
@objc public let textContainerInset: UIEdgeInsets
17+
@objc public let layoutAlignment: LOKAlignment
18+
@objc public let viewClass: UITextView.Type
19+
@objc public let configure: ((UITextView) -> Void)?
20+
1221
@objc public init(text: String? = nil,
1322
font: UIFont? = nil,
1423
lineFragmentPadding: CGFloat = 0,
@@ -18,16 +27,24 @@ import UIKit
1827
viewReuseId: String? = nil,
1928
viewClass: UITextView.Type? = nil,
2029
configure: ((UITextView) -> Void)? = nil) {
30+
self.text = text ?? ""
31+
self.attributedText = nil
32+
self.font = font
33+
self.lineFragmentPadding = lineFragmentPadding
34+
self.textContainerInset = textContainerInset
35+
self.layoutAlignment = layoutAlignment ?? LOKAlignment(alignment: TextViewLayoutDefaults.defaultAlignment)
36+
self.viewClass = viewClass ?? UITextView.self
37+
self.configure = configure
2138
super.init(layout: TextViewLayout(
22-
text: text ?? "",
23-
font: font,
24-
lineFragmentPadding: lineFragmentPadding,
25-
textContainerInset: textContainerInset,
26-
layoutAlignment: layoutAlignment?.alignment ?? TextViewLayoutDefaults.defaultAlignment,
39+
text: self.text ?? "",
40+
font: self.font,
41+
lineFragmentPadding: self.lineFragmentPadding,
42+
textContainerInset: self.textContainerInset,
43+
layoutAlignment: self.layoutAlignment.alignment,
2744
flexibility: flexibility?.flexibility ?? TextViewLayoutDefaults.defaultFlexibility,
2845
viewReuseId: viewReuseId,
29-
viewClass: viewClass,
30-
config: configure))
46+
viewClass: self.viewClass,
47+
config: self.configure))
3148
}
3249

3350
@objc public init(attributedText: NSAttributedString? = nil,
@@ -39,15 +56,23 @@ import UIKit
3956
viewReuseId: String? = nil,
4057
viewClass: UITextView.Type? = nil,
4158
configure: ((UITextView) -> Void)? = nil) {
59+
self.text = nil
60+
self.attributedText = attributedText ?? NSAttributedString()
61+
self.font = font
62+
self.lineFragmentPadding = lineFragmentPadding
63+
self.textContainerInset = textContainerInset
64+
self.layoutAlignment = layoutAlignment ?? LOKAlignment(alignment: TextViewLayoutDefaults.defaultAlignment)
65+
self.viewClass = viewClass ?? UITextView.self
66+
self.configure = configure
4267
super.init(layout: TextViewLayout(
43-
attributedText: attributedText ?? NSAttributedString(),
44-
font: font,
45-
lineFragmentPadding: lineFragmentPadding,
46-
textContainerInset: textContainerInset,
47-
layoutAlignment: layoutAlignment?.alignment ?? TextViewLayoutDefaults.defaultAlignment,
68+
attributedText: self.attributedText ?? NSAttributedString(),
69+
font: self.font,
70+
lineFragmentPadding: self.lineFragmentPadding,
71+
textContainerInset: self.textContainerInset,
72+
layoutAlignment: self.layoutAlignment.alignment,
4873
flexibility: flexibility?.flexibility ?? TextViewLayoutDefaults.defaultFlexibility,
4974
viewReuseId: viewReuseId,
50-
viewClass: viewClass,
51-
config: configure))
75+
viewClass: self.viewClass,
76+
config: self.configure))
5277
}
5378
}

0 commit comments

Comments
 (0)