Skip to content

Commit 65772b0

Browse files
committed
Updated spaces and diffable extensions.
1 parent 57c000a commit 65772b0

File tree

6 files changed

+76
-55
lines changed

6 files changed

+76
-55
lines changed

Sources/NativeUIKit/Collection/NativeLargeTitleCollectionViewCell.swift renamed to Sources/NativeUIKit/Collection/LargeHeader/NativeLargeHeaderCollectionView.swift

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,34 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
// SOFTWARE.
2121

22-
#if canImport(UIKit) && (os(iOS))
2322
import UIKit
2423
import SparrowKit
2524

26-
open class NativeLargeTitleCollectionViewCell: SPCollectionViewCell {
25+
open class NativeLargeHeaderCollectionView: SPCollectionReusableView {
2726

28-
// MARK: - Views
29-
30-
public let titleLabel = SPLabel().do {
31-
$0.font = UIFont.preferredFont(forTextStyle: .title1, weight: .bold, addPoints: .zero)
32-
if #available(iOS 13.0, *) {
33-
$0.textColor = .label
34-
} else {
35-
$0.textColor = .black
36-
}
37-
}
38-
39-
// MARK: - Init
27+
public let headerView = NativeLargeHeaderView()
4028

4129
open override func commonInit() {
4230
super.commonInit()
43-
contentView.layoutMargins = .init(top: 32, left: .zero, bottom: 8, right: .zero)
4431
insetsLayoutMarginsFromSafeArea = false
45-
contentView.insetsLayoutMarginsFromSafeArea = false
46-
preservesSuperviewLayoutMargins = false
47-
contentView.preservesSuperviewLayoutMargins = false
48-
addSubview(titleLabel)
49-
}
50-
51-
open override func prepareForReuse() {
52-
super.prepareForReuse()
53-
titleLabel.text = nil
54-
parentLayout = nil
32+
layoutMargins = .zero
33+
addSubview(headerView)
5534
}
5635

57-
// MARK: - Layout
58-
59-
open weak var parentLayout: UIView?
60-
6136
open override func layoutSubviews() {
6237
super.layoutSubviews()
63-
if let parentLayout = parentLayout {
64-
contentView.layoutMargins.left = parentLayout.layoutMargins.left
65-
contentView.layoutMargins.right = parentLayout.layoutMargins.right
66-
}
67-
titleLabel.layoutDynamicHeight(
68-
x: contentView.layoutMargins.left,
69-
y: contentView.layoutMargins.top,
70-
width: contentView.layoutWidth
71-
)
38+
headerView.layout(y: layoutMargins.top)
7239
}
7340

7441
open override func sizeThatFits(_ size: CGSize) -> CGSize {
7542
let superSize = super.sizeThatFits(size)
76-
layoutSubviews()
77-
return .init(width: superSize.width, height: titleLabel.frame.maxY + contentView.layoutMargins.bottom)
43+
return .init(width: superSize.width, height: headerView.frame.height + layoutMargins.bottom)
44+
}
45+
46+
static public func size(for item: NativeLargeHeaderItem, in collectionView: UICollectionView) -> CGSize {
47+
let view = NativeLargeHeaderView()
48+
view.configure(with: item)
49+
view.setWidthAndFit(width: collectionView.layoutWidth)
50+
return .init(width: collectionView.frame.width, height: view.frame.height)
7851
}
7952
}
80-
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2021 Ivan Vorobei ([email protected])
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+
import UIKit
23+
import SPDiffable
24+
25+
@available(iOS 13.0, *)
26+
extension SPDiffableCollectionDataSource.HeaderFooterProvider {
27+
28+
public static var largeHeader: SPDiffableCollectionDataSource.HeaderFooterProvider {
29+
return SPDiffableCollectionDataSource.HeaderFooterProvider.init { collectionView, kind, indexPath, item in
30+
guard let header = item as? NativeLargeHeaderItem else { return nil }
31+
let view = collectionView.dequeueReusableSupplementaryView(withCalss: NativeLargeHeaderCollectionView.self, kind: kind, for: indexPath)
32+
view.headerView.configure(with: header)
33+
return view
34+
}
35+
}
36+
}

Sources/NativeUIKit/NativeLayout.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,26 @@ public enum NativeLayout {
3232

3333
public enum Spaces {
3434

35-
public static var `default`: CGFloat { 16 }
36-
public static var default_half: CGFloat { 8 }
37-
public static var default_double: CGFloat { 32 }
35+
public static var step: CGFloat = 4
36+
37+
public static var default_less: CGFloat { step * 3 }
38+
public static var `default`: CGFloat { step * 4 }
39+
public static var default_more: CGFloat { step * 5 }
40+
41+
public static var default_half: CGFloat { self.default / 2 }
42+
public static var default_double: CGFloat { self.default * 2 }
3843

3944
public enum Margins {
4045

41-
public static var full_screen_horizontal: CGFloat { 16 }
42-
public static var modal_screen_horizontal: CGFloat { 20 }
46+
public static var full_screen_horizontal: CGFloat { Spaces.default }
47+
public static var modal_screen_horizontal: CGFloat { step * 5 }
4348
}
4449

4550
public enum Scroll {
4651

47-
public static var top_inset_transparent_navigation: CGFloat { 8 }
48-
public static var bottom_inset_reach_end: CGFloat { 36 }
49-
public static var bottom_inset_when_keyboard_can_appear: CGFloat { 32 }
52+
public static var top_inset_transparent_navigation: CGFloat { step * 2 }
53+
public static var bottom_inset_reach_end: CGFloat { step * 9 }
54+
public static var bottom_inset_when_keyboard_can_appear: CGFloat { step * 8 }
5055
}
5156
}
5257
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import SPDiffable
2626
/**
2727
SPDiffable: Native large header with button.
2828
*/
29-
open class NativeLargeHeader: SPDiffableItem, SPDiffableItemActionable {
29+
open class NativeLargeHeaderItem: SPDiffableItem, SPDiffableItemActionable {
3030

3131
open var title: String
3232
open var actionTitle: String?
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import UIKit
2+
3+
extension NativeLargeHeaderView {
4+
5+
open func configure(with item: NativeLargeHeaderItem) {
6+
titleLabel.text = item.title
7+
if let actionTitle = item.actionTitle {
8+
button.setTitle(actionTitle)
9+
}
10+
}
11+
}

Sources/NativeUIKit/Table/LargeHeader/SPDiffableTableCellProvider+LargeHeader.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ extension SPDiffableTableDataSource.HeaderFooterProvider {
2828

2929
public static var largeHeader: SPDiffableTableDataSource.HeaderFooterProvider {
3030
return SPDiffableTableDataSource.HeaderFooterProvider() { (tableView, indexPath, item) -> UIView? in
31-
guard let header = item as? NativeLargeHeader else { return nil }
31+
guard let header = item as? NativeLargeHeaderItem else { return nil }
3232
let view = NativeLargeHeaderView()
33-
view.titleLabel.text = header.title
34-
if let actionTitle = header.actionTitle {
35-
view.button.setTitle(actionTitle)
36-
}
33+
view.configure(with: header)
3734
return view
3835
}
3936
}

0 commit comments

Comments
 (0)