feat: add nativation title view

This commit is contained in:
jk234ert 2021-04-02 16:38:33 +08:00
parent b63a5ebe5f
commit 4f77688d03
2 changed files with 44 additions and 26 deletions

View File

@ -41,6 +41,8 @@ class HashtagTimelineViewController: UIViewController, NeedsDependency {
let refreshControl = UIRefreshControl() let refreshControl = UIRefreshControl()
let titleView = HashtagTimelineNavigationBarTitleView()
deinit { deinit {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s:", ((#file as NSString).lastPathComponent), #line, #function) os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s:", ((#file as NSString).lastPathComponent), #line, #function)
} }
@ -52,6 +54,9 @@ extension HashtagTimelineViewController {
super.viewDidLoad() super.viewDidLoad()
title = "#\(viewModel.hashTag)" title = "#\(viewModel.hashTag)"
titleView.updateTitle(hashtag: viewModel.hashTag, peopleNumber: nil)
navigationItem.titleView = titleView
view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color
navigationItem.rightBarButtonItem = composeBarButtonItem navigationItem.rightBarButtonItem = composeBarButtonItem
@ -133,20 +138,21 @@ extension HashtagTimelineViewController {
} }
private func updatePromptTitle() { private func updatePromptTitle() {
var subtitle: String?
defer {
titleView.updateTitle(hashtag: viewModel.hashTag, peopleNumber: subtitle)
}
guard let histories = viewModel.hashtagEntity.value?.history else { guard let histories = viewModel.hashtagEntity.value?.history else {
navigationItem.prompt = nil
return return
} }
if histories.isEmpty { if histories.isEmpty {
// No tag history, remove the prompt title // No tag history, remove the prompt title
navigationItem.prompt = nil return
} else { } else {
let sortedHistory = histories.sorted { (h1, h2) -> Bool in let sortedHistory = histories.sorted { (h1, h2) -> Bool in
return h1.day > h2.day return h1.day > h2.day
} }
if let accountsNumber = sortedHistory.first?.accounts { subtitle = sortedHistory.first?.accounts
navigationItem.prompt = L10n.Scene.Hashtag.prompt(accountsNumber)
}
} }
} }
} }

View File

@ -7,20 +7,26 @@
import UIKit import UIKit
final class HashtagTimelineTitleView: UIView { final class HashtagTimelineNavigationBarTitleView: UIView {
let containerView = UIStackView() let containerView = UIStackView()
let imageView = UIImageView() let titleLabel: UILabel = {
let button = RoundedEdgesButton() let label = UILabel()
let label = UILabel() label.font = .systemFont(ofSize: 17, weight: .semibold)
label.textColor = Asset.Colors.Label.primary.color
label.textAlignment = .center
return label
}()
// input let subtitleLabel: UILabel = {
private var blockingState: HomeTimelineNavigationBarTitleViewModel.State? let label = UILabel()
weak var delegate: HomeTimelineNavigationBarTitleViewDelegate? label.font = .systemFont(ofSize: 12)
label.textColor = Asset.Colors.Label.secondary.color
// output label.textAlignment = .center
private(set) var state: HomeTimelineNavigationBarTitleViewModel.State = .logoImage label.isHidden = true
return label
}()
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
@ -34,8 +40,11 @@ final class HashtagTimelineTitleView: UIView {
} }
extension HomeTimelineNavigationBarTitleView { extension HashtagTimelineNavigationBarTitleView {
private func _init() { private func _init() {
containerView.axis = .vertical
containerView.alignment = .center
containerView.distribution = .fill
containerView.translatesAutoresizingMaskIntoConstraints = false containerView.translatesAutoresizingMaskIntoConstraints = false
addSubview(containerView) addSubview(containerView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
@ -45,15 +54,18 @@ extension HomeTimelineNavigationBarTitleView {
containerView.bottomAnchor.constraint(equalTo: bottomAnchor), containerView.bottomAnchor.constraint(equalTo: bottomAnchor),
]) ])
containerView.addArrangedSubview(imageView) containerView.addArrangedSubview(titleLabel)
button.translatesAutoresizingMaskIntoConstraints = false containerView.addArrangedSubview(subtitleLabel)
containerView.addArrangedSubview(button) }
NSLayoutConstraint.activate([
button.heightAnchor.constraint(equalToConstant: 24).priority(.defaultHigh) func updateTitle(hashtag: String, peopleNumber: String?) {
]) titleLabel.text = "#\(hashtag)"
containerView.addArrangedSubview(label) if let peopleNumebr = peopleNumber {
subtitleLabel.text = L10n.Scene.Hashtag.prompt(peopleNumebr)
configure(state: .logoImage) subtitleLabel.isHidden = false
button.addTarget(self, action: #selector(HomeTimelineNavigationBarTitleView.buttonDidPressed(_:)), for: .touchUpInside) } else {
subtitleLabel.text = nil
subtitleLabel.isHidden = true
}
} }
} }