Skip to content

Commit cb2a7f0

Browse files
committed
Added Extend Area.
1 parent a70132e commit cb2a7f0

3 files changed

Lines changed: 91 additions & 41 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
import SPDiffable
26+
27+
@available(iOS 13.0, *)
28+
extension NativeHeaderTableController {
29+
30+
open class HeaderContainerView: SPView {
31+
32+
// MARK: - Public
33+
34+
public let contentView: UIView
35+
36+
public var extendAreaToTop: Bool = true {
37+
didSet {
38+
extendAreaView.isHidden = !extendAreaToTop
39+
}
40+
}
41+
42+
// MARK: - Private
43+
44+
private var extendAreaView = SPView()
45+
46+
// MARK: - Init
47+
48+
public init(contentView: UIView) {
49+
self.contentView = contentView
50+
super.init()
51+
}
52+
53+
public required init?(coder aDecoder: NSCoder) {
54+
fatalError("init(coder:) has not been implemented")
55+
}
56+
57+
public override func commonInit() {
58+
super.commonInit()
59+
insetsLayoutMarginsFromSafeArea = false
60+
layoutMargins = .zero
61+
addSubview(extendAreaView)
62+
addSubview(contentView)
63+
}
64+
65+
// MARK: - Ovveride
66+
67+
68+
69+
// MARK: - Layout
70+
71+
public override func layoutSubviews() {
72+
super.layoutSubviews()
73+
extendAreaView.frame = .init(x: .zero, maxY: .zero, width: frame.width, height: 1000)
74+
contentView.setWidthAndFit(width: layoutWidth)
75+
contentView.frame.origin.x = layoutMargins.left
76+
contentView.frame.origin.y = layoutMargins.top
77+
}
78+
79+
public override func sizeThatFits(_ size: CGSize) -> CGSize {
80+
frame.setWidth(size.width)
81+
layoutSubviews()
82+
return .init(width: size.width, height: contentView.frame.maxY + layoutMargins.bottom)
83+
}
84+
}
85+
}
86+
#endif

Sources/NativeUIKit/Controllers/Table/NativeHeaderTableController.swift renamed to Sources/NativeUIKit/Controllers/Table/Header/NativeHeaderTableController.swift

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import SPDiffable
2626

2727
@available(iOS 13.0, *)
2828
open class NativeHeaderTableController: SPDiffableTableController {
29+
30+
// MARK: - Public
31+
32+
open var headerContainerView: HeaderContainerView
2933

3034
// MARK: - Init
3135

3236
public init(style: UITableView.Style, headerView: UIView) {
33-
super.init(style: style)
34-
tableView.tableHeaderView = HeaderContainerView(contentView: headerView)
35-
}
36-
37-
public init(style: UITableView.Style, headerContainerView: HeaderContainerView) {
37+
self.headerContainerView = HeaderContainerView(contentView: headerView)
3838
super.init(style: style)
3939
tableView.tableHeaderView = headerContainerView
4040
}
@@ -61,41 +61,5 @@ open class NativeHeaderTableController: SPDiffableTableController {
6161
}
6262

6363
private var cachedHeaderHeight: CGFloat? = nil
64-
65-
// MARK: - Views
66-
67-
open class HeaderContainerView: SPView {
68-
69-
public let contentView: UIView
70-
71-
public init(contentView: UIView) {
72-
self.contentView = contentView
73-
super.init()
74-
}
75-
76-
public required init?(coder aDecoder: NSCoder) {
77-
fatalError("init(coder:) has not been implemented")
78-
}
79-
80-
public override func commonInit() {
81-
super.commonInit()
82-
insetsLayoutMarginsFromSafeArea = false
83-
layoutMargins = .zero
84-
addSubview(contentView)
85-
}
86-
87-
public override func layoutSubviews() {
88-
super.layoutSubviews()
89-
contentView.setWidthAndFit(width: frame.width)
90-
contentView.frame.origin.x = .zero
91-
contentView.frame.origin.y = .zero
92-
}
93-
94-
public override func sizeThatFits(_ size: CGSize) -> CGSize {
95-
frame.setWidth(size.width)
96-
layoutSubviews()
97-
return .init(width: size.width, height: contentView.frame.maxY)
98-
}
99-
}
10064
}
10165
#endif

0 commit comments

Comments
 (0)