Skip to content

Commit 2b62e3e

Browse files
committed
Updated profile controller and native layout.
1 parent 03f758e commit 2b62e3e

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

Sources/NativeUIKit/Controllers/Complex/Profile/NativeProfileHeaderView.swift

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ open class NativeProfileHeaderView: SPView {
4040
$0.textAlignment = .center
4141
$0.adjustsFontSizeToFitWidth = true
4242
$0.minimumScaleFactor = 0.5
43+
$0.text = nil
44+
}
45+
46+
public let namePlaceholderLabel = SPLabel().do {
47+
$0.font = UIFont.preferredFont(forTextStyle: .title2, weight: .semibold, addPoints: 2)
48+
$0.textColor = .secondaryLabel
49+
$0.numberOfLines = 1
50+
$0.textAlignment = .center
51+
$0.adjustsFontSizeToFitWidth = true
52+
$0.minimumScaleFactor = 0.5
4353
$0.text = .space
4454
}
4555

@@ -60,13 +70,35 @@ open class NativeProfileHeaderView: SPView {
6070

6171
open override func commonInit() {
6272
super.commonInit()
63-
backgroundColor = .systemBackground
64-
extendView.backgroundColor = backgroundColor
65-
addSubviews([extendView, avatarView, nameLabel, emailButton])
73+
backgroundColor = .clear
74+
addSubviews([extendView, avatarView, nameLabel, namePlaceholderLabel, emailButton])
75+
76+
layoutMargins = .init(
77+
top: NativeLayout.Spaces.default_half,
78+
left: NativeLayout.Spaces.default_double,
79+
bottom: NativeLayout.Spaces.default_half,
80+
right: NativeLayout.Spaces.default_double
81+
)
82+
}
83+
84+
// MARK: - Ovveride
85+
86+
open override var backgroundColor: UIColor? {
87+
didSet {
88+
extendView.backgroundColor = backgroundColor
89+
}
6690
}
6791

6892
// MARK: - Layout
6993

94+
private var usingNameLabel: SPLabel {
95+
if nameLabel.text == nil {
96+
return namePlaceholderLabel
97+
} else {
98+
return nameLabel
99+
}
100+
}
101+
70102
open override func layoutSubviews() {
71103
super.layoutSubviews()
72104
extendView.frame = .init(x: .zero, maxY: .zero, width: frame.width, height: 1000)
@@ -77,12 +109,18 @@ open class NativeProfileHeaderView: SPView {
77109

78110
nameLabel.layoutDynamicHeight(width: layoutWidth)
79111
nameLabel.setXCenter()
80-
nameLabel.frame.origin.y = avatarView.frame.maxY + 8
112+
nameLabel.frame.origin.y = avatarView.frame.maxY + NativeLayout.Spaces.default_half
113+
114+
namePlaceholderLabel.layoutDynamicHeight(width: layoutWidth)
115+
namePlaceholderLabel.setXCenter()
116+
namePlaceholderLabel.frame.origin.y = nameLabel.frame.origin.y
117+
118+
nameLabel.isHidden = !(nameLabel == usingNameLabel)
119+
namePlaceholderLabel.isHidden = !(namePlaceholderLabel == usingNameLabel)
81120

82121
emailButton.sizeToFit()
83-
emailButton.frame.setWidth(nameLabel.frame.width)
84122
emailButton.setXCenter()
85-
emailButton.frame.origin.y = nameLabel.frame.maxY + 2
123+
emailButton.frame.origin.y = usingNameLabel.frame.maxY
86124
}
87125

88126
open override func sizeThatFits(_ size: CGSize) -> CGSize {

Sources/NativeUIKit/NativeLayout.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ public enum NativeLayout {
3232

3333
public enum Spaces {
3434

35-
public static var full_screen_horizontal_margins: CGFloat { 16 }
36-
public static var modal_screen_horizontal_margins: CGFloat { 20 }
35+
public static var `default`: CGFloat { 16 }
36+
public static var default_half: CGFloat { 8 }
37+
public static var default_double: CGFloat { 32 }
38+
39+
public enum Margins {
40+
41+
public static var full_screen_horizontal: CGFloat { 16 }
42+
public static var modal_screen_horizontal: CGFloat { 20 }
43+
}
3744

3845
public enum Scroll {
3946

0 commit comments

Comments
 (0)