-
Notifications
You must be signed in to change notification settings - Fork 1
/
BaseStyles.swift
91 lines (76 loc) · 2.97 KB
/
BaseStyles.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// BaseStyles.swift
// Facestar
//
// Created by JohnP on 2/14/17.
// Copyright © 2017 JohnP. All rights reserved.
//
import Foundation
import Prelude
import Prelude_UIKit
import UIKit
public enum Styles {
public static let cornerRadius: CGFloat = 4.0
public static func grid(_ count: Int) -> CGFloat {
return 6.0 * CGFloat(count)
}
public static func gridHalf(_ count: Int) -> CGFloat {
return grid(count) / 2.0
}
}
public func baseControllerStyle <VC: UIViewControllerProtocol> () -> ((VC) -> VC) {
return VC.lens.view.backgroundColor .~ .jp_grey_200
}
/**
- parameter r: The corner radius. This parameter is optional, and will use a default value if omitted.
- returns: A view transformer that rounds corners.
*/
public func roundedStyle <V: UIViewProtocol> (cornerRadius r: CGFloat = Styles.cornerRadius) -> ((V) -> V) {
return V.lens.clipsToBounds .~ true
<> V.lens.layer.masksToBounds .~ true
<> V.lens.layer.cornerRadius .~ r
}
public func baseTableControllerStyle <TVC: UITableViewControllerProtocol>
(estimatedRowHeight: CGFloat = 44.0) -> ((TVC) -> TVC) {
let style = baseControllerStyle()
<> TVC.lens.tableView.rowHeight .~ UITableViewAutomaticDimension
<> TVC.lens.tableView.estimatedRowHeight .~ estimatedRowHeight
#if os(iOS)
return style <> TVC.lens.tableView.separatorStyle .~ .none
#else
return style
#endif
}
public let baseNavigationBarStyle =
UINavigationBar.lens.titleTextAttributes .~ [
NSForegroundColorAttributeName: UIColor.white,
NSFontAttributeName: UIFont(name: "Avenir-medium", size: 18)
]
<> UINavigationBar.lens.translucent .~ false
<> UINavigationBar.lens.barTintColor .~ .jp_primary_color
public let emptyNavigationBarStyle =
UINavigationBar.lens.hidden .~ true
public func dropShadowStyle <V: UIViewProtocol> (radius: CGFloat = 2.0,
offset: CGSize = .init(width: 0, height: 1)) -> ((V) -> V) {
return
V.lens.layer.shadowColor .~ UIColor.jp_dropShadow.cgColor
<> V.lens.layer.shadowOpacity .~ 1
<> V.lens.layer.shadowRadius .~ radius
<> V.lens.layer.masksToBounds .~ false
<> V.lens.layer.shouldRasterize .~ true
<> V.lens.layer.shadowOffset .~ offset
}
public func baseTableViewCellStyle <TVC: UITableViewCellProtocol> () -> ((TVC) -> TVC) {
return
TVC.lens.contentView.layoutMargins %~~ { _, cell in
if cell.traitCollection.isRegularRegular {
return .init(topBottom: Styles.grid(3), leftRight: Styles.grid(12))
}
return .init(topBottom: Styles.grid(1), leftRight: Styles.grid(2))
}
<> TVC.lens.backgroundColor .~ .clear
<> (TVC.lens.contentView • UIView.lens.preservesSuperviewLayoutMargins) .~ false
<> TVC.lens.layoutMargins .~ .init(all: 0.0)
<> TVC.lens.preservesSuperviewLayoutMargins .~ false
<> TVC.lens.selectionStyle .~ .none
}