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

Commit

Permalink
Exposed properties in LOK classes (#221)
Browse files Browse the repository at this point in the history
* Exposed properties in LOK classes

Exposed properties in following classes:
- LOKStackLayout
- LOKInsetLayout
- LOKLabelLayout
- LOKButtonLayout
- LOKOverlayLayout
- LOKTextViewLayout
  • Loading branch information
nbadakh authored and staguer committed Aug 1, 2018
1 parent 49387c9 commit 50b860f
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Sources/Layouts/SizeLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ open class SizeLayout<V: View>: BaseLayout<V>, ConfigurableLayout {

// MARK: - Initialization helpers

private static func defaultAlignment(maxWidth: CGFloat?, maxHeight: CGFloat?) -> Alignment {
static func defaultAlignment(maxWidth: CGFloat?, maxHeight: CGFloat?) -> Alignment {
return Alignment(vertical: maxHeight == nil ? .fill : .center,
horizontal: maxWidth == nil ? .fill : .center)
}
Expand Down
31 changes: 25 additions & 6 deletions Sources/ObjCSupport/LOKButtonLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
import UIKit

@objc open class LOKButtonLayout: LOKBaseLayout {
@objc public let type: LOKButtonLayoutType
@objc public let title: String
@objc public let image: UIImage?
@objc public let imageSize: CGSize
@objc public let font: UIFont?
@objc public let contentEdgeInsets: NSValue?
@objc public let alignment: LOKAlignment
@objc public let viewClass: UIButton.Type
@objc public let config: ((UIButton) -> Void)?

@objc public init(type: LOKButtonLayoutType,
title: String?,
image: UIImage?,
Expand Down Expand Up @@ -38,17 +48,26 @@ import UIKit
} else {
buttonLayoutImage = .size(imageSize)
}
self.type = type
self.title = title ?? ""
self.image = image
self.imageSize = imageSize
self.font = font
self.contentEdgeInsets = contentEdgeInsets
self.alignment = alignment ?? LOKAlignment(alignment: ButtonLayoutDefaults.defaultAlignment)
self.viewClass = viewClass ?? UIButton.self
self.config = config
let layout = ButtonLayout(
type: type.unwrapped,
title: title ?? "",
type: self.type.unwrapped,
title: self.title,
image: buttonLayoutImage,
font: font,
font: self.font,
contentEdgeInsets: insets,
alignment: alignment?.alignment ?? ButtonLayoutDefaults.defaultAlignment,
alignment: self.alignment.alignment,
flexibility: flexibility?.flexibility ?? ButtonLayoutDefaults.defaultFlexibility,
viewReuseId: viewReuseId,
viewClass: viewClass,
config: config)
viewClass: self.viewClass,
config: self.config)
super.init(layout: layout)
}
}
21 changes: 16 additions & 5 deletions Sources/ObjCSupport/LOKInsetLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,30 @@
import CoreGraphics

@objc open class LOKInsetLayout: LOKBaseLayout {
@objc public let insets: EdgeInsets
@objc public let alignment: LOKAlignment
@objc public let viewClass: View.Type
@objc public let sublayout: LOKLayout
@objc public let configure: ((View) -> Void)?

@objc public init(insets: EdgeInsets,
alignment: LOKAlignment? = nil,
viewReuseId: String? = nil,
viewClass: View.Type? = nil,
sublayout: LOKLayout,
configure: ((View) -> Void)? = nil) {
self.insets = insets
self.sublayout = sublayout
self.alignment = alignment ?? .fill
self.viewClass = viewClass ?? View.self
self.configure = configure
let layout = InsetLayout(
insets: insets,
alignment: alignment?.alignment ?? .fill,
insets: self.insets,
alignment: self.alignment.alignment,
viewReuseId: viewReuseId,
sublayout: sublayout.unwrapped,
viewClass: viewClass ?? View.self,
config: configure)
sublayout: self.sublayout.unwrapped,
viewClass: self.viewClass,
config: self.configure)
super.init(layout: layout)
}

Expand Down
46 changes: 36 additions & 10 deletions Sources/ObjCSupport/LOKLabelLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
import UIKit

@objc open class LOKLabelLayout: LOKBaseLayout {
@objc public let attributedString: NSAttributedString?
@objc public let string: String?
@objc public let lineHeight: CGFloat
@objc public let font: UIFont
@objc public let numberOfLines: Int
@objc public let alignment: LOKAlignment
@objc public let viewClass: UILabel.Type
@objc public let configure: ((UILabel) -> Void)?

@objc public init(attributedString: NSAttributedString,
font: UIFont?,
lineHeight: CGFloat,
Expand All @@ -18,16 +27,25 @@ import UIKit
viewReuseId: String?,
viewClass: UILabel.Type?,
configure: ((UILabel) -> Void)?) {
self.attributedString = attributedString
self.font = font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize)
self.lineHeight = lineHeight
self.numberOfLines = numberOfLines
self.alignment = alignment ?? .topLeading
self.viewClass = viewClass ?? UILabel.self
self.configure = configure
string = nil
let layout = LabelLayout<UILabel>(
attributedString: attributedString,
font: font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize),
font: self.font,
lineHeight: lineHeight > 0 && lineHeight.isFinite ? lineHeight : Optional<CGFloat>.none,
numberOfLines: numberOfLines,
alignment: alignment?.alignment ?? .topLeading,
numberOfLines: self.numberOfLines,
alignment: self.alignment.alignment,
flexibility: flexibility?.flexibility ?? .flexible,
viewReuseId: viewReuseId,
viewClass: viewClass ?? UILabel.self,
config: configure)
viewClass: self.viewClass,
config: self.configure)

super.init(layout: layout)
}

Expand All @@ -40,16 +58,24 @@ import UIKit
viewReuseId: String?,
viewClass: UILabel.Type?,
configure: ((UILabel) -> Void)?) {
self.string = string
self.font = font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize)
self.lineHeight = lineHeight
self.numberOfLines = numberOfLines
self.alignment = alignment ?? .topLeading
self.viewClass = viewClass ?? UILabel.self
self.configure = configure
attributedString = nil
let layout = LabelLayout<UILabel>(
string: string,
font: font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize),
font: self.font,
lineHeight: lineHeight > 0 && lineHeight.isFinite ? lineHeight : Optional<CGFloat>.none,
numberOfLines: numberOfLines,
alignment: alignment?.alignment ?? .topLeading,
numberOfLines: self.numberOfLines,
alignment: self.alignment.alignment,
flexibility: flexibility?.flexibility ?? .flexible,
viewReuseId: viewReuseId,
viewClass: viewClass ?? UILabel.self,
config: configure)
viewClass: self.viewClass,
config: self.configure)
super.init(layout: layout)
}
}
25 changes: 19 additions & 6 deletions Sources/ObjCSupport/LOKOverlayLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,33 @@
import Foundation

@objc open class LOKOverlayLayout: LOKBaseLayout {
@objc public let primary: LOKLayout
@objc public let background: [LOKLayout]
@objc public let overlay: [LOKLayout]
@objc public let alignment: LOKAlignment
@objc public let viewClass: View.Type
@objc public let configure: ((View) -> Void)?

@objc public init(primary: LOKLayout,
background: [LOKLayout]? = nil,
overlay: [LOKLayout]? = nil,
alignment: LOKAlignment? = nil,
viewReuseId: String? = nil,
viewClass: View.Type? = nil,
configure: ((View) -> Void)? = nil) {
self.primary = primary
self.background = background ?? []
self.overlay = overlay ?? []
self.alignment = alignment ?? .fill
self.viewClass = viewClass ?? View.self
self.configure = configure
super.init(layout: OverlayLayout(
primary: primary.unwrapped,
background: background?.map { $0.unwrapped } ?? [],
overlay: overlay?.map { $0.unwrapped } ?? [],
alignment: alignment?.alignment ?? .fill,
primary: self.primary.unwrapped,
background: self.background.map { $0.unwrapped },
overlay: self.overlay.map { $0.unwrapped },
alignment: self.alignment.alignment,
viewReuseId: viewReuseId,
viewClass: viewClass,
config: configure))
viewClass: self.viewClass,
config: self.configure))
}
}
34 changes: 26 additions & 8 deletions Sources/ObjCSupport/LOKSizeLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
import CoreGraphics

@objc open class LOKSizeLayout: LOKBaseLayout {
@objc public let minWidth: CGFloat
@objc public let maxWidth: CGFloat
@objc public let minHeight: CGFloat
@objc public let maxHeight: CGFloat
@objc public let alignment: LOKAlignment
@objc public let viewClass: View.Type
@objc public let sublayout: LOKLayout?
@objc public let configure: ((View) -> Void)?

@objc public init(minWidth: CGFloat,
maxWidth: CGFloat,
minHeight: CGFloat,
Expand All @@ -19,17 +28,26 @@ import CoreGraphics
viewClass: View.Type?,
sublayout: LOKLayout?,
configure: ((View) -> Void)? = nil) {
self.minWidth = minWidth
self.minHeight = minHeight
self.maxWidth = maxWidth
self.maxHeight = maxHeight
self.alignment = alignment ?? LOKAlignment(alignment: SizeLayout.defaultAlignment(maxWidth: maxWidth.isFinite ? maxWidth : nil,
maxHeight: maxHeight.isFinite ? maxHeight : nil))
self.viewClass = viewClass ?? View.self
self.sublayout = sublayout
self.configure = configure
let layout = SizeLayout(
minWidth: minWidth,
maxWidth: maxWidth.isFinite ? maxWidth : nil,
minHeight: minHeight,
maxHeight: maxHeight.isFinite ? maxHeight : nil,
alignment: alignment?.alignment,
minWidth: self.minWidth,
maxWidth: self.maxWidth.isFinite ? self.maxWidth : nil,
minHeight: self.minHeight,
maxHeight: self.maxHeight.isFinite ? self.maxHeight : nil,
alignment: self.alignment.alignment,
flexibility: flexibility?.flexibility,
viewReuseId: viewReuseId,
viewClass: viewClass,
sublayout: sublayout?.unwrapped,
config: configure)
viewClass: self.viewClass,
sublayout: self.sublayout?.unwrapped,
config: self.configure)
super.init(layout: layout)
}
}
29 changes: 22 additions & 7 deletions Sources/ObjCSupport/LOKStackLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ extension LOKStackLayoutDistribution {
}

@objc open class LOKStackLayout: LOKBaseLayout {
@objc public let axis: LOKAxis
@objc public let spacing: CGFloat
@objc public let distribution: LOKStackLayoutDistribution
@objc public let alignment: LOKAlignment
@objc public let viewClass: View.Type
@objc public let sublayouts: [LOKLayout]
@objc public let configure: ((View) -> Void)?

@objc public init(axis: LOKAxis = .vertical,
spacing: CGFloat = 0,
distribution: LOKStackLayoutDistribution = .`default`,
Expand All @@ -50,15 +58,22 @@ extension LOKStackLayoutDistribution {
viewReuseId: String? = nil,
sublayouts: [LOKLayout]?,
configure: ((View) -> Void)? = nil) {
self.axis = axis
self.spacing = spacing
self.distribution = distribution.distribution != nil ? distribution : .fillFlexing
self.sublayouts = sublayouts ?? []
self.alignment = alignment ?? .fill
self.viewClass = viewClass ?? View.self
self.configure = configure
super.init(layout: StackLayout(
axis: axis.axis,
spacing: spacing,
distribution: distribution.distribution ?? .fillFlexing,
alignment: alignment?.alignment ?? .fill,
axis: self.axis.axis,
spacing: self.spacing,
distribution: self.distribution.distribution ?? .fillFlexing,
alignment: self.alignment.alignment,
flexibility: flexibility?.flexibility,
viewReuseId: viewReuseId,
viewClass: viewClass,
sublayouts: sublayouts?.map { $0.unwrapped } ?? [],
config: configure))
viewClass: self.viewClass,
sublayouts: self.sublayouts.map { $0.unwrapped },
config: self.configure))
}
}
53 changes: 39 additions & 14 deletions Sources/ObjCSupport/LOKTextViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
import UIKit

@objc open class LOKTextViewLayout: LOKBaseLayout {
@objc public let attributedText: NSAttributedString?
@objc public let text: String?
@objc public let font: UIFont?
@objc public let lineFragmentPadding: CGFloat
@objc public let textContainerInset: UIEdgeInsets
@objc public let layoutAlignment: LOKAlignment
@objc public let viewClass: UITextView.Type
@objc public let configure: ((UITextView) -> Void)?

@objc public init(text: String? = nil,
font: UIFont? = nil,
lineFragmentPadding: CGFloat = 0,
Expand All @@ -18,16 +27,24 @@ import UIKit
viewReuseId: String? = nil,
viewClass: UITextView.Type? = nil,
configure: ((UITextView) -> Void)? = nil) {
self.text = text ?? ""
self.attributedText = nil
self.font = font
self.lineFragmentPadding = lineFragmentPadding
self.textContainerInset = textContainerInset
self.layoutAlignment = layoutAlignment ?? LOKAlignment(alignment: TextViewLayoutDefaults.defaultAlignment)
self.viewClass = viewClass ?? UITextView.self
self.configure = configure
super.init(layout: TextViewLayout(
text: text ?? "",
font: font,
lineFragmentPadding: lineFragmentPadding,
textContainerInset: textContainerInset,
layoutAlignment: layoutAlignment?.alignment ?? TextViewLayoutDefaults.defaultAlignment,
text: self.text ?? "",
font: self.font,
lineFragmentPadding: self.lineFragmentPadding,
textContainerInset: self.textContainerInset,
layoutAlignment: self.layoutAlignment.alignment,
flexibility: flexibility?.flexibility ?? TextViewLayoutDefaults.defaultFlexibility,
viewReuseId: viewReuseId,
viewClass: viewClass,
config: configure))
viewClass: self.viewClass,
config: self.configure))
}

@objc public init(attributedText: NSAttributedString? = nil,
Expand All @@ -39,15 +56,23 @@ import UIKit
viewReuseId: String? = nil,
viewClass: UITextView.Type? = nil,
configure: ((UITextView) -> Void)? = nil) {
self.text = nil
self.attributedText = attributedText ?? NSAttributedString()
self.font = font
self.lineFragmentPadding = lineFragmentPadding
self.textContainerInset = textContainerInset
self.layoutAlignment = layoutAlignment ?? LOKAlignment(alignment: TextViewLayoutDefaults.defaultAlignment)
self.viewClass = viewClass ?? UITextView.self
self.configure = configure
super.init(layout: TextViewLayout(
attributedText: attributedText ?? NSAttributedString(),
font: font,
lineFragmentPadding: lineFragmentPadding,
textContainerInset: textContainerInset,
layoutAlignment: layoutAlignment?.alignment ?? TextViewLayoutDefaults.defaultAlignment,
attributedText: self.attributedText ?? NSAttributedString(),
font: self.font,
lineFragmentPadding: self.lineFragmentPadding,
textContainerInset: self.textContainerInset,
layoutAlignment: self.layoutAlignment.alignment,
flexibility: flexibility?.flexibility ?? TextViewLayoutDefaults.defaultFlexibility,
viewReuseId: viewReuseId,
viewClass: viewClass,
config: configure))
viewClass: self.viewClass,
config: self.configure))
}
}

0 comments on commit 50b860f

Please sign in to comment.