From 1aca3142995f63194d86bbdaf90c90cf806d0bfe Mon Sep 17 00:00:00 2001 From: Lakr Date: Tue, 17 Jun 2025 13:58:13 +0800 Subject: [PATCH] feat: ai v2 nav bar --- .../BlurTransition.swift | 0 .../IntelligentsController.swift | 12 +- .../MainViewController.swift | 59 +++++++++ .../IntelligentsButton+Control.swift | 0 .../IntelligentsButton+Delegate.swift | 0 .../IntelligentsButton.swift | 0 .../View/MainHeaderView/MainHeaderView.swift | 118 ++++++++++++++++++ .../SupplementView/CircleImageView.swift | 0 .../SupplementView/DarkActionButton.swift | 0 9 files changed, 178 insertions(+), 11 deletions(-) rename packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/{ => Controller}/IntelligentsController/BlurTransition.swift (100%) rename packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/{ => Controller}/IntelligentsController/IntelligentsController.swift (60%) create mode 100644 packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController.swift rename packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/{ => View}/IntelligentsButton/IntelligentsButton+Control.swift (100%) rename packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/{ => View}/IntelligentsButton/IntelligentsButton+Delegate.swift (100%) rename packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/{ => View}/IntelligentsButton/IntelligentsButton.swift (100%) create mode 100644 packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/MainHeaderView/MainHeaderView.swift rename packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/{ => View}/SupplementView/CircleImageView.swift (100%) rename packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/{ => View}/SupplementView/DarkActionButton.swift (100%) diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsController/BlurTransition.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/IntelligentsController/BlurTransition.swift similarity index 100% rename from packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsController/BlurTransition.swift rename to packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/IntelligentsController/BlurTransition.swift diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsController/IntelligentsController.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/IntelligentsController/IntelligentsController.swift similarity index 60% rename from packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsController/IntelligentsController.swift rename to packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/IntelligentsController/IntelligentsController.swift index 52ef5270dc..bca2bf4c1a 100644 --- a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsController/IntelligentsController.swift +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/IntelligentsController/IntelligentsController.swift @@ -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) - } } diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController.swift new file mode 100644 index 0000000000..c95de6cfd8 --- /dev/null +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController.swift @@ -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") + } +} diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsButton/IntelligentsButton+Control.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/IntelligentsButton/IntelligentsButton+Control.swift similarity index 100% rename from packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsButton/IntelligentsButton+Control.swift rename to packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/IntelligentsButton/IntelligentsButton+Control.swift diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsButton/IntelligentsButton+Delegate.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/IntelligentsButton/IntelligentsButton+Delegate.swift similarity index 100% rename from packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsButton/IntelligentsButton+Delegate.swift rename to packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/IntelligentsButton/IntelligentsButton+Delegate.swift diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsButton/IntelligentsButton.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/IntelligentsButton/IntelligentsButton.swift similarity index 100% rename from packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/IntelligentsButton/IntelligentsButton.swift rename to packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/IntelligentsButton/IntelligentsButton.swift diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/MainHeaderView/MainHeaderView.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/MainHeaderView/MainHeaderView.swift new file mode 100644 index 0000000000..a911c6121b --- /dev/null +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/MainHeaderView/MainHeaderView.swift @@ -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() + } +} diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/SupplementView/CircleImageView.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/SupplementView/CircleImageView.swift similarity index 100% rename from packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/SupplementView/CircleImageView.swift rename to packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/SupplementView/CircleImageView.swift diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/SupplementView/DarkActionButton.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/SupplementView/DarkActionButton.swift similarity index 100% rename from packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/SupplementView/DarkActionButton.swift rename to packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/SupplementView/DarkActionButton.swift