Skip to content

Commit 8c4b4fd

Browse files
committed
Clean diffable button. Removed menu diffable models. Added empty table cells.
1 parent 0f8a6a1 commit 8c4b4fd

8 files changed

Lines changed: 127 additions & 74 deletions

Sources/NativeUIKit/Table/Button/NativeLeftButtonTableViewCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ open class NativeLeftButtonTableViewCell: SPTableViewCell {
3535

3636
open override func commonInit() {
3737
super.commonInit()
38-
textLabel?.font = .preferredFont(forTextStyle: .body, weight: .semibold)
38+
textLabel?.font = .preferredFont(forTextStyle: .body, weight: .medium)
3939
higlightStyle = .content
4040
}
4141

Sources/NativeUIKit/Table/MenuTableViewCell/NativeMenuTableViewCell.swift renamed to Sources/NativeUIKit/Table/Empty/NativeEmptyRowItem.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@
2222
#if canImport(UIKit) && (os(iOS))
2323
import UIKit
2424
import SparrowKit
25+
import SPDiffable
2526

26-
open class NativeMenuTableViewCell: SPTableViewCell {
27+
@available(iOS 13.0, *)
28+
open class NativeEmptyRowItem: SPDiffableTableRow {
2729

28-
open override func commonInit() {
29-
super.commonInit()
30-
higlightStyle = .content
31-
}
30+
var verticalMargins: NativeEmptyTableViewCell.Margins
3231

33-
open override func sizeThatFits(_ size: CGSize) -> CGSize {
34-
let superSize = super.sizeThatFits(size)
35-
return .init(width: superSize.width, height: superSize.height + 4)
32+
public init(id: String, verticalMargins: NativeEmptyTableViewCell.Margins, text: String, detail: String?) {
33+
self.verticalMargins = verticalMargins
34+
super.init(id: id, text: text, detail: detail)
3635
}
3736
}
3837
#endif
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.by)
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
#if canImport(UIKit) && (os(iOS))
23+
import UIKit
24+
import SparrowKit
25+
26+
open class NativeEmptyTableViewCell: SPTableViewCell {
27+
28+
// MARK: - Data
29+
30+
open var verticalMargins: Margins = .medium {
31+
didSet {
32+
contentView.layoutMargins.top = self.verticalMargins.value
33+
contentView.layoutMargins.bottom = self.verticalMargins.value
34+
}
35+
}
36+
37+
// MARK: - Views
38+
39+
public let placeholderView = NativePlaceholderView().do {
40+
$0.isUserInteractionEnabled = false
41+
}
42+
43+
// MARK: - Init
44+
45+
open override func commonInit() {
46+
super.commonInit()
47+
selectionStyle = .none
48+
contentView.addSubview(placeholderView)
49+
updateBackgroundColorByParent()
50+
}
51+
52+
// MARK: - Lifecycle
53+
54+
open override func tintColorDidChange() {
55+
super.tintColorDidChange()
56+
updateBackgroundColorByParent()
57+
}
58+
59+
// MARK: - Layout
60+
61+
open override func layoutSubviews() {
62+
super.layoutSubviews()
63+
placeholderView.frame.origin.y = contentView.layoutMargins.top
64+
placeholderView.setWidthAndFit(width: contentView.layoutWidth)
65+
placeholderView.setXCenter()
66+
}
67+
68+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
69+
let superSize = super.sizeThatFits(size)
70+
layoutSubviews()
71+
let calculatedHeight = placeholderView.frame.maxY + contentView.layoutMargins.bottom
72+
let bottomInset = calculatedHeight * (1 - 0.94)
73+
return .init(width: superSize.width, height: calculatedHeight + bottomInset)
74+
}
75+
76+
// MARK: - Actions
77+
78+
private func updateBackgroundColorByParent() {
79+
if #available(iOS 13.0, *) {
80+
backgroundColor = UIColor.systemDownedGroupedBackground
81+
}
82+
/*if let superView = self.superview?.superview {
83+
let superViewBackgroundColor = superView.backgroundColor ?? .clear
84+
if superViewBackgroundColor == .systemGroupedBackground {
85+
backgroundColor = UIColor.init(
86+
light: superViewBackgroundColor.mixWithColor(.darkGray, amount: 0.09).mixWithColor(.systemBlue, amount: 0.01),
87+
dark: .secondarySystemGroupedBackground.alpha(0.7)
88+
)
89+
} else {
90+
// Here not implemented becouse not using never for now.
91+
backgroundColor = .red
92+
}
93+
}*/
94+
}
95+
96+
// MARK: - Models
97+
98+
public enum Margins {
99+
100+
case small
101+
case medium
102+
case large
103+
104+
var value: CGFloat {
105+
switch self {
106+
case .small: return 16
107+
case .medium: return 32
108+
case .large: return 48
109+
}
110+
}
111+
}
112+
}
113+
#endif

Sources/NativeUIKit/Table/MenuTableViewCell/SPDiffableTableCellProvider+Menu.swift renamed to Sources/NativeUIKit/Table/Empty/SPDiffableTableCellProvider+Empty.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ import SPDiffable
2626
@available(iOS 13.0, *)
2727
extension SPDiffableTableCellProvider {
2828

29-
public static var menu: SPDiffableTableCellProvider {
29+
public static var empty: SPDiffableTableCellProvider {
3030
return SPDiffableTableCellProvider() { (tableView, indexPath, item) -> UITableViewCell? in
31-
guard let item = item as? NativeDiffableMenuTableRow else { return nil }
32-
let cell = tableView.dequeueReusableCell(withClass: NativeMenuTableViewCell.self, for: indexPath)
33-
cell.textLabel?.text = item.text
34-
cell.textLabel?.textColor = item.textColor
35-
cell.detailTextLabel?.text = item.detail
36-
cell.detailTextLabel?.textColor = item.detailColor
37-
cell.imageView?.image = item.icon
38-
cell.accessoryType = item.accessoryType
31+
guard let item = item as? NativeEmptyRowItem else { return nil }
32+
let cell = tableView.dequeueReusableCell(withClass: NativeEmptyTableViewCell.self, for: indexPath)
33+
cell.placeholderView.headerLabel.text = item.text
34+
cell.placeholderView.descriptionLabel.text = item.detail
35+
cell.verticalMargins = item.verticalMargins
3936
return cell
4037
}
4138
}

Sources/NativeUIKit/Table/LargeHeaderView/NativeLargeHeader.swift renamed to Sources/NativeUIKit/Table/LargeHeader/NativeLargeHeader.swift

File renamed without changes.

Sources/NativeUIKit/Table/LargeHeaderView/NativeLargeHeaderView.swift renamed to Sources/NativeUIKit/Table/LargeHeader/NativeLargeHeaderView.swift

File renamed without changes.

Sources/NativeUIKit/Table/LargeHeaderView/SPDiffableTableCellProvider+LargeHeader.swift renamed to Sources/NativeUIKit/Table/LargeHeader/SPDiffableTableCellProvider+LargeHeader.swift

File renamed without changes.

Sources/NativeUIKit/Table/MenuTableViewCell/NativeDiffableMenuTableRow.swift

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)