-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMyProfileHeaderView.swift
73 lines (58 loc) · 2.56 KB
/
MyProfileHeaderView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// MyProfileHeaderView.swift
// Commun
//
// Created by Chung Tran on 10/29/19.
// Copyright © 2019 Commun Limited. All rights reserved.
//
import Foundation
final class MyProfileHeaderView: UserProfileHeaderView {
lazy var changeAvatarButton: UIButton = {
let button = UIButton.changeAvatarButton
button.touchAreaEdgeInsets = UIEdgeInsets(top: -24, left: -24, bottom: 0, right: 0)
return button
}()
lazy var addBioButton = UIButton(height: 35,
label: String(format: "%@ %@", "add".localized().uppercaseFirst, "bio".localized()),
labelFont: .boldSystemFont(ofSize: 15),
backgroundColor: .appLightGrayColor,
textColor: .appMainColor,
cornerRadius: 35/2)
lazy var walletView = CMWalletView(forAutoLayout: ())
override func commonInit() {
super.commonInit()
// button
addSubview(changeAvatarButton)
changeAvatarButton.autoPinEdge(.bottom, to: .bottom, of: avatarImageView)
changeAvatarButton.autoPinEdge(.trailing, to: .trailing, of: avatarImageView)
// bind
bind()
}
func bind() {
descriptionLabel.rx.observe(String.self, "text")
.map {$0 == nil || $0?.isEmpty == true}
.subscribe(onNext: { (shouldHideDescription) in
self.descriptionLabel.isHidden = shouldHideDescription
self.addBioButton.isHidden = !shouldHideDescription
})
.disposed(by: disposeBag)
}
override func setUpStackView() {
super.setUpStackView()
buttonStackView.isHidden = true
setUpWalletView()
stackView.insertArrangedSubview(addBioButton, at: 1)
stackView.insertArrangedSubview(walletView, at: 3)
stackView.setCustomSpacing(16, after: addBioButton)
stackView.setCustomSpacing(28, after: walletView)
}
override func setUp(with profile: ResponseAPIContentGetProfile) {
super.setUp(with: profile)
communitiesLabel.attributedText = NSMutableAttributedString()
.text("communities".localized().uppercaseFirst + " " + "(\(profile.subscriptions?.communitiesCount ?? 0))", size: 20, weight: .bold)
statsLabel.isHidden = followersCount == 0 && followingsCount == 0
}
func setUpWalletView(withError: Bool = false) {
walletView.setUp(withError: withError)
}
}