Skip to content

Commit 8ea4e26

Browse files
committed
Added NativeProfileController .
1 parent e36503f commit 8ea4e26

File tree

4 files changed

+108
-22
lines changed

4 files changed

+108
-22
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#if canImport(UIKit) && (os(iOS))
2+
import UIKit
3+
import SparrowKit
4+
import SPDiffable
5+
6+
@available(iOS 13.0, *)
7+
open class NativeProfileController: NativeHeaderTableController {
8+
9+
// MARK: - Views
10+
11+
public let headerView = NativeProfileHeaderView()
12+
13+
// MARK: - Init
14+
15+
init() {
16+
super.init(style: .insetGrouped, headerView: headerView)
17+
}
18+
19+
public required init?(coder: NSCoder) {
20+
fatalError("init(coder:) has not been implemented")
21+
}
22+
23+
// MARK: - Lifecycle
24+
25+
open override func viewDidLoad() {
26+
super.viewDidLoad()
27+
navigationItem.title = .empty
28+
}
29+
30+
// MARK: - Public
31+
32+
open func setSpaceBetweenHeaderAndCells(_ value: CGFloat) {
33+
headerContainerView.layoutMargins.bottom = value
34+
}
35+
}
36+
#endif
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#if canImport(UIKit) && (os(iOS))
2+
import UIKit
3+
import SparrowKit
4+
5+
@available(iOS 13.0, *)
6+
open class NativeProfileHeaderView: SPView {
7+
8+
// MARK: - Public
9+
10+
public let avatarView = NativeAvatarView().do {
11+
$0.avatarAppearance = .placeholder
12+
$0.isEditable = true
13+
}
14+
15+
public let nameLabel = SPLabel().do {
16+
$0.font = UIFont.preferredFont(forTextStyle: .title2, weight: .semibold, addPoints: 2)
17+
$0.textColor = .label
18+
$0.numberOfLines = 1
19+
$0.textAlignment = .center
20+
$0.adjustsFontSizeToFitWidth = true
21+
$0.minimumScaleFactor = 0.5
22+
$0.text = .space
23+
}
24+
25+
// Add tap to clipboard
26+
public let emailButton = SPDimmedButton().do {
27+
$0.titleLabel?.font = UIFont.preferredFont(forTextStyle: .body, weight: .regular, addPoints: -2)
28+
$0.titleLabel?.adjustsFontSizeToFitWidth = true
29+
$0.titleLabel?.minimumScaleFactor = 0.5
30+
$0.setTitle(.space)
31+
$0.titleImageInset = 2
32+
}
33+
34+
// MARK: - Private
35+
36+
private var extendView = SPView()
37+
38+
// MARK: - Init
39+
40+
open override func commonInit() {
41+
super.commonInit()
42+
backgroundColor = .systemBackground
43+
extendView.backgroundColor = backgroundColor
44+
addSubviews([extendView, avatarView, nameLabel, emailButton])
45+
}
46+
47+
// MARK: - Layout
48+
49+
open override func layoutSubviews() {
50+
super.layoutSubviews()
51+
extendView.frame = .init(x: .zero, maxY: .zero, width: frame.width, height: 1000)
52+
53+
avatarView.sizeToFit()
54+
avatarView.setXCenter()
55+
avatarView.frame.origin.y = layoutMargins.top
56+
57+
nameLabel.layoutDynamicHeight(width: layoutWidth)
58+
nameLabel.setXCenter()
59+
nameLabel.frame.origin.y = avatarView.frame.maxY + 12
60+
61+
emailButton.sizeToFit()
62+
emailButton.frame.setWidth(nameLabel.frame.width)
63+
emailButton.setXCenter()
64+
emailButton.frame.origin.y = nameLabel.frame.maxY + 2
65+
}
66+
67+
open override func sizeThatFits(_ size: CGSize) -> CGSize {
68+
layoutSubviews()
69+
return .init(width: frame.width, height: emailButton.frame.maxY + layoutMargins.bottom)
70+
}
71+
}
72+
#endif

Sources/NativeUIKit/Controllers/Table/Header/NativeHeaderTableController+HeaderContainerView.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ extension NativeHeaderTableController {
3333

3434
public let contentView: UIView
3535

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-
4636
// MARK: - Init
4737

4838
public init(contentView: UIView) {
@@ -58,25 +48,13 @@ extension NativeHeaderTableController {
5848
super.commonInit()
5949
insetsLayoutMarginsFromSafeArea = false
6050
layoutMargins = .zero
61-
62-
addSubview(extendAreaView)
63-
extendAreaView.backgroundColor = backgroundColor
64-
6551
addSubview(contentView)
6652
}
6753

68-
// MARK: - Ovveride
69-
70-
open override func tintColorDidChange() {
71-
super.tintColorDidChange()
72-
extendAreaView.backgroundColor = backgroundColor
73-
}
74-
7554
// MARK: - Layout
7655

7756
public override func layoutSubviews() {
7857
super.layoutSubviews()
79-
extendAreaView.frame = .init(x: .zero, maxY: .zero, width: frame.width, height: 1000)
8058
contentView.setWidthAndFit(width: layoutWidth)
8159
contentView.frame.origin.x = layoutMargins.left
8260
contentView.frame.origin.y = layoutMargins.top

0 commit comments

Comments
 (0)