Skip to content

Commit

Permalink
Use container stackView instead of spacingView
Browse files Browse the repository at this point in the history
  • Loading branch information
lokae0 committed Jan 27, 2019
1 parent dddaa52 commit 631fe8a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
33 changes: 22 additions & 11 deletions Application/Source/Detail/View/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ class DetailView: UIView {
let button = UIButton()
let selectionResult = UILabel()

private let spacingView: UIView = {
let view = UIView()
view.snp.makeConstraints { $0.height.equalTo(35) }
return view
}()

let foodListTitle = UILabel()
let foodList = UILabel()
let foodInfoButton = UIButton()

private(set) lazy var stackView: UIStackView = {
private(set) lazy var selectionStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [
title,
button,
selectionResult,
spacingView,
selectionResult
])
stackView.axis = .vertical
stackView.alignment = .center
return stackView
}()

private(set) lazy var foodStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [
foodListTitle,
foodList,
foodInfoButton
Expand All @@ -32,13 +33,23 @@ class DetailView: UIView {
return stackView
}()

private(set) lazy var containerStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [
selectionStackView,
foodStackView
])
stackView.axis = .vertical
stackView.alignment = .center
return stackView
}()

let requiresConstraintBasedLayout = true

override init(frame: CGRect) {
super.init(frame: frame)

addSubview(stackView)
stackView.snp.makeConstraints { make in
addSubview(containerStackView)
containerStackView.snp.makeConstraints { make in
make.center.equalTo(self)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import UIKit
import Core

struct DetailViewControllerStyle: Style {

let theme: Theme
let background: BackgroundViewStyle
let label: LabelStyle
Expand Down Expand Up @@ -30,7 +31,10 @@ struct DetailViewControllerStyle: Style {
button.apply(to: view.button)
button.apply(to: view.foodInfoButton)

view.stackView.spacing = theme.layout.interitemSpacing
view.selectionStackView.spacing = theme.layout.interitemSpacing
view.foodStackView.spacing = theme.layout.interitemSpacing

view.containerStackView.spacing = theme.layout.containerSpacing
}

}
12 changes: 12 additions & 0 deletions Core/Source/Themes/Themes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum Theme {
}

public extension Theme {

public var color: ColorSet {
switch self {
case .light: return ColorSet(
Expand Down Expand Up @@ -37,27 +38,38 @@ public extension Theme {
public var layout: Layout {
return Layout(
interitemSpacing: 20,
containerSpacing: 35,
buttonContentEdgeInsets: UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20),
buttonBorderWidth: 1,
buttonCornerRadius: 12,
contentLayoutMargins: UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 15))
}

}

public struct ColorSet {

public let bodyText: UIColor
public let alternateBodyText: UIColor
public let inputText: UIColor
public let actionColor: UIColor
public let viewBackground: UIColor?
public let navigationBarTint: UIColor?
public let tabBarTint: UIColor?

}

public struct Layout {

/// Spacing between elements within an inner (or single) stackView.
public let interitemSpacing: CGFloat

/// Spacing between inner stackViews within an outer container stackView.
public let containerSpacing: CGFloat

public let buttonContentEdgeInsets: UIEdgeInsets
public let buttonBorderWidth: CGFloat
public let buttonCornerRadius: CGFloat
public let contentLayoutMargins: UIEdgeInsets

}

0 comments on commit 631fe8a

Please sign in to comment.