feat: ai v2 nav bar

This commit is contained in:
Lakr
2025-06-17 13:58:13 +08:00
parent f6b281d12f
commit 1aca314299
9 changed files with 178 additions and 11 deletions
@@ -9,7 +9,7 @@ import UIKit
public class IntelligentsController: UINavigationController {
public init() {
super.init(nibName: nil, bundle: nil)
super.init(rootViewController: MainViewController())
modalPresentationStyle = .custom
transitioningDelegate = BlurTransitioningDelegate.shared
setNavigationBarHidden(true, animated: false)
@@ -24,14 +24,4 @@ public class IntelligentsController: UINavigationController {
super.viewDidLoad()
view.backgroundColor = .systemBackground
}
override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setNavigationBarHidden(true, animated: animated)
}
override public func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
setNavigationBarHidden(false, animated: animated)
}
}
@@ -0,0 +1,59 @@
import SnapKit
import Then
import UIKit
class MainViewController: UIViewController {
// MARK: - UI Components
private lazy var headerView = MainHeaderView().then {
$0.delegate = self
}
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController!.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController!.setNavigationBarHidden(false, animated: animated)
}
// MARK: - Setup
private func setupUI() {
view.backgroundColor = .systemBackground
view.addSubview(headerView)
headerView.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide)
make.leading.trailing.equalToSuperview()
}
}
}
// MARK: - MainHeaderViewDelegate
extension MainViewController: MainHeaderViewDelegate {
func mainHeaderViewDidTapClose() {
dismiss(animated: true)
}
func mainHeaderViewDidTapDropdown() {
// TODO:
print("Dropdown tapped")
}
func mainHeaderViewDidTapMenu() {
// TODO:
print("Menu tapped")
}
}
@@ -0,0 +1,118 @@
import SnapKit
import Then
import UIKit
protocol MainHeaderViewDelegate: AnyObject {
func mainHeaderViewDidTapClose()
func mainHeaderViewDidTapDropdown()
func mainHeaderViewDidTapMenu()
}
class MainHeaderView: UIView {
weak var delegate: MainHeaderViewDelegate?
private lazy var closeButton = UIButton(type: .system).then {
$0.imageView?.contentMode = .scaleAspectFit
$0.setImage(UIImage(systemName: "xmark"), for: .normal)
$0.tintColor = .systemGray
$0.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside)
$0.setContentHuggingPriority(.required, for: .horizontal)
}
private lazy var titleLabel = UILabel().then {
$0.text = "AFFiNE"
$0.font = .systemFont(ofSize: 16, weight: .medium)
$0.textColor = .black
$0.textAlignment = .center
}
private lazy var dropdownButton = UIButton(type: .system).then {
$0.imageView?.contentMode = .scaleAspectFit
$0.setImage(UIImage(systemName: "chevron.down"), for: .normal)
$0.tintColor = .systemGray
$0.addTarget(self, action: #selector(dropdownButtonTapped), for: .touchUpInside)
}
private lazy var centerStackView = UIStackView().then {
$0.axis = .horizontal
$0.spacing = 8
$0.alignment = .center
$0.addArrangedSubview(titleLabel)
$0.addArrangedSubview(dropdownButton)
}
private lazy var menuButton = UIButton(type: .system).then {
$0.imageView?.contentMode = .scaleAspectFit
$0.setImage(UIImage(systemName: "ellipsis"), for: .normal)
$0.tintColor = .systemGray
$0.addTarget(self, action: #selector(menuButtonTapped), for: .touchUpInside)
$0.setContentHuggingPriority(.required, for: .horizontal)
}
private lazy var leftSpacerView = UIView()
private lazy var rightSpacerView = UIView()
private lazy var mainStackView = UIStackView().then {
$0.axis = .horizontal
$0.alignment = .center
$0.distribution = .fill
$0.spacing = 16
$0.addArrangedSubview(closeButton)
$0.addArrangedSubview(leftSpacerView)
$0.addArrangedSubview(centerStackView)
$0.addArrangedSubview(rightSpacerView)
$0.addArrangedSubview(menuButton)
}
init() {
super.init(frame: .zero)
backgroundColor = .white
addSubview(mainStackView)
mainStackView.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(16)
make.centerY.equalToSuperview()
}
closeButton.snp.makeConstraints { make in
make.size.equalTo(titleLabel.font.pointSize)
}
menuButton.snp.makeConstraints { make in
make.size.equalTo(titleLabel.font.pointSize)
}
dropdownButton.snp.makeConstraints { make in
make.size.equalTo(titleLabel.font.pointSize)
}
// ensure center stack to be center
leftSpacerView.snp.makeConstraints { make in
make.width.equalTo(rightSpacerView)
}
snp.makeConstraints { make in
make.height.equalTo(52)
}
}
required init?(coder: NSCoder) {
super.init(coder: coder)
fatalError()
}
@objc private func closeButtonTapped() {
delegate?.mainHeaderViewDidTapClose()
}
@objc private func dropdownButtonTapped() {
delegate?.mainHeaderViewDidTapDropdown()
}
@objc private func menuButtonTapped() {
delegate?.mainHeaderViewDidTapMenu()
}
}