chore: update ui

This commit is contained in:
Lakr
2025-06-19 01:08:35 +08:00
parent c19ef05534
commit 1e861e54ee
10 changed files with 136 additions and 74 deletions
@@ -45,6 +45,15 @@
"version" : "1.0.4" "version" : "1.0.4"
} }
}, },
{
"identity" : "swifterswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SwifterSwift/SwifterSwift.git",
"state" : {
"revision" : "39fa28c90a3ebe3d53f80289304fd880cf2c42d0",
"version" : "6.2.0"
}
},
{ {
"identity" : "then", "identity" : "then",
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
@@ -18,12 +18,14 @@ let package = Package(
.package(url: "https://github.com/apple/swift-collections", from: "1.2.0"), .package(url: "https://github.com/apple/swift-collections", from: "1.2.0"),
.package(url: "https://github.com/devxoul/Then", from: "3.0.0"), .package(url: "https://github.com/devxoul/Then", from: "3.0.0"),
.package(url: "https://github.com/SnapKit/SnapKit.git", from: "5.0.1"), .package(url: "https://github.com/SnapKit/SnapKit.git", from: "5.0.1"),
.package(url: "https://github.com/SwifterSwift/SwifterSwift.git", from: "6.0.0")
], ],
targets: [ targets: [
.target(name: "Intelligents", dependencies: [ .target(name: "Intelligents", dependencies: [
"AffineGraphQL", "AffineGraphQL",
"SnapKit", "SnapKit",
"Then", "Then",
"SwifterSwift",
.product(name: "Apollo", package: "apollo-ios"), .product(name: "Apollo", package: "apollo-ios"),
.product(name: "OrderedCollections", package: "swift-collections"), .product(name: "OrderedCollections", package: "swift-collections"),
], resources: [ ], resources: [
@@ -0,0 +1,22 @@
//
// File.swift
// Intelligents
//
// Created by on 6/19/25.
//
import UIKit
extension MainViewController: MainHeaderViewDelegate {
func mainHeaderViewDidTapClose() {
dismiss(animated: true)
}
func mainHeaderViewDidTapDropdown() {
print(#function)
}
func mainHeaderViewDidTapMenu() {
print(#function)
}
}
@@ -0,0 +1,22 @@
//
// MainViewController+Input.swift
// Intelligents
//
// Created by on 6/19/25.
//
import UIKit
extension MainViewController: InputBoxDelegate {
func inputBoxDidSelectAttachment(_ inputBox: InputBox) {
print(#function, inputBox)
}
func inputBoxDidSend(_ inputBox: InputBox) {
print(#function, inputBox, inputBox.viewModel)
}
func inputBoxTextDidChange(_ text: String) {
print(#function, text)
}
}
@@ -23,19 +23,15 @@ class MainViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.layoutIfNeeded()
setupUI() setupUI()
view.layoutIfNeeded()
} }
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
navigationController!.setNavigationBarHidden(true, animated: animated) navigationController!.setNavigationBarHidden(true, animated: animated)
} DispatchQueue.main.async {
self.inputBox.textView.becomeFirstResponder()
override func viewDidAppear(_ animated: Bool) { }
super.viewDidAppear(animated)
inputBox.textView.becomeFirstResponder()
} }
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(_ animated: Bool) {
@@ -47,19 +43,10 @@ class MainViewController: UIViewController {
private func setupUI() { private func setupUI() {
view.backgroundColor = .systemBackground view.backgroundColor = .systemBackground
let inputBox = InputBox().then {
// InputBox frame
let inputBoxFrame = CGRect(
x: 0,
y: view.bounds.height - 150, //
width: view.bounds.width,
height: 150
)
let inputBox = InputBox(frame: inputBoxFrame).then {
$0.delegate = self $0.delegate = self
} }
self.inputBox = inputBox self.inputBox = inputBox
self.inputBox.layoutIfNeeded()
view.addSubview(headerView) view.addSubview(headerView)
view.addSubview(inputBox) view.addSubview(inputBox)
@@ -75,37 +62,3 @@ class MainViewController: UIViewController {
} }
} }
} }
// MARK: - MainHeaderViewDelegate
extension MainViewController: MainHeaderViewDelegate {
func mainHeaderViewDidTapClose() {
dismiss(animated: true)
}
func mainHeaderViewDidTapDropdown() {
// TODO:
print("Dropdown tapped")
}
func mainHeaderViewDidTapMenu() {
// TODO:
print("Menu tapped")
}
}
// MARK: - InputBoxDelegate
extension MainViewController: InputBoxDelegate {
func inputBoxDidSelectAttachment(_ inputBox: InputBox) {
print(#function, inputBox)
}
func inputBoxDidSend(_ inputBox: InputBox) {
print(#function, inputBox, inputBox.viewModel)
}
func inputBoxTextDidChange(_ text: String) {
print(#function, text)
}
}
@@ -0,0 +1,12 @@
//
// File.swift
// Intelligents
//
// Created by on 6/19/25.
//
import UIKit
extension UIColor {
static let accent: UIColor = .init(red: 30 / 255, green: 150 / 255, blue: 235 / 255, alpha: 1.0)
}
@@ -10,14 +10,19 @@ class InputBox: UIView {
var cancellables = Set<AnyCancellable>() var cancellables = Set<AnyCancellable>()
lazy var containerView = UIView().then { lazy var containerView = UIView().then {
$0.backgroundColor = .systemBackground $0.backgroundColor = UIColor(
$0.layer.cornerRadius = 12 named: "InputBoxBackground",
$0.layer.borderWidth = 0.5 in: .module,
$0.layer.borderColor = UIColor.systemGray4.cgColor compatibleWith: nil
)!
$0.layer.cornerRadius = 16
$0.layer.cornerCurve = .continuous
$0.layer.borderWidth = 1
$0.layer.borderColor = UIColor.systemGray.withAlphaComponent(0.1).cgColor
$0.layer.shadowColor = UIColor.black.cgColor $0.layer.shadowColor = UIColor.black.cgColor
$0.layer.shadowOffset = CGSize(width: 0, height: 2) $0.layer.shadowOffset = CGSize(width: 0, height: 0)
$0.layer.shadowRadius = 6 $0.layer.shadowRadius = 12
$0.layer.shadowOpacity = 0.04 $0.layer.shadowOpacity = 0.075
$0.clipsToBounds = false $0.clipsToBounds = false
} }
@@ -29,7 +34,7 @@ class InputBox: UIView {
$0.textContainer.lineFragmentPadding = 0 $0.textContainer.lineFragmentPadding = 0
$0.textContainerInset = .zero $0.textContainerInset = .zero
$0.delegate = self $0.delegate = self
$0.text = "This is AFFiNE AI" $0.text = ""
} }
lazy var placeholderLabel = UILabel().then { lazy var placeholderLabel = UILabel().then {
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "255",
"green" : "255",
"red" : "255"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "32",
"green" : "32",
"red" : "32"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -10,40 +10,41 @@ protocol InputBoxFunctionBarDelegate: AnyObject {
func functionBarDidTapSend(_ functionBar: InputBoxFunctionBar) func functionBarDidTapSend(_ functionBar: InputBoxFunctionBar)
} }
private let unselectedColor: UIColor = .secondaryLabel
private let selectedColor: UIColor = .accent
class InputBoxFunctionBar: UIView { class InputBoxFunctionBar: UIView {
weak var delegate: InputBoxFunctionBarDelegate? weak var delegate: InputBoxFunctionBarDelegate?
lazy var attachmentButton = UIButton(type: .system).then { lazy var attachmentButton = UIButton(type: .system).then {
$0.backgroundColor = .systemBackground
$0.setImage(UIImage(named: "inputbox.add.attachment", in: .module, with: nil), for: .normal) $0.setImage(UIImage(named: "inputbox.add.attachment", in: .module, with: nil), for: .normal)
$0.tintColor = .secondaryLabel $0.tintColor = unselectedColor
$0.imageView?.contentMode = .scaleAspectFit $0.imageView?.contentMode = .scaleAspectFit
$0.addTarget(self, action: #selector(attachmentButtonTapped), for: .touchUpInside) $0.addTarget(self, action: #selector(attachmentButtonTapped), for: .touchUpInside)
} }
lazy var toolButton = UIButton(type: .system).then { lazy var toolButton = UIButton(type: .system).then {
$0.setImage(UIImage(named: "inputbox.tool", in: .module, with: nil), for: .normal) $0.setImage(UIImage(named: "inputbox.tool", in: .module, with: nil), for: .normal)
$0.tintColor = .secondaryLabel $0.tintColor = unselectedColor
$0.imageView?.contentMode = .scaleAspectFit $0.imageView?.contentMode = .scaleAspectFit
$0.addTarget(self, action: #selector(toolButtonTapped), for: .touchUpInside) $0.addTarget(self, action: #selector(toolButtonTapped), for: .touchUpInside)
} }
lazy var networkButton = UIButton(type: .system).then { lazy var networkButton = UIButton(type: .system).then {
$0.setImage(UIImage(named: "inputbox.network", in: .module, with: nil), for: .normal) $0.setImage(UIImage(named: "inputbox.network", in: .module, with: nil), for: .normal)
$0.tintColor = .secondaryLabel $0.tintColor = unselectedColor
$0.imageView?.contentMode = .scaleAspectFit $0.imageView?.contentMode = .scaleAspectFit
$0.addTarget(self, action: #selector(networkButtonTapped), for: .touchUpInside) $0.addTarget(self, action: #selector(networkButtonTapped), for: .touchUpInside)
} }
lazy var deepThinkingButton = UIButton(type: .system).then { lazy var deepThinkingButton = UIButton(type: .system).then {
$0.setImage(UIImage(named: "inputbox.deep.thinking", in: .module, with: nil), for: .normal) $0.setImage(UIImage(named: "inputbox.deep.thinking", in: .module, with: nil), for: .normal)
$0.tintColor = .secondaryLabel $0.tintColor = unselectedColor
$0.imageView?.contentMode = .scaleAspectFit $0.imageView?.contentMode = .scaleAspectFit
$0.addTarget(self, action: #selector(deepThinkingButtonTapped), for: .touchUpInside) $0.addTarget(self, action: #selector(deepThinkingButtonTapped), for: .touchUpInside)
} }
lazy var sendButton = UIButton(type: .system).then { lazy var sendButton = UIButton(type: .system).then {
$0.backgroundColor = UIColor.systemBlue
$0.setImage(UIImage(named: "inputbox.send", in: .module, with: nil), for: .normal) $0.setImage(UIImage(named: "inputbox.send", in: .module, with: nil), for: .normal)
$0.tintColor = .white $0.tintColor = .white
$0.imageView?.contentMode = .scaleAspectFit $0.imageView?.contentMode = .scaleAspectFit
@@ -103,27 +104,26 @@ class InputBoxFunctionBar: UIView {
} }
} }
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
sendButton.layer.cornerRadius = sendButton.bounds.height / 2 sendButton.layer.cornerRadius = sendButton.bounds.height / 2
for button in [toolButton, networkButton, deepThinkingButton] {
button.layer.cornerRadius = button.bounds.height / 2
}
} }
// MARK: - Public Methods // MARK: - Public Methods
func updateToolState(isEnabled: Bool) { func updateToolState(isEnabled: Bool) {
toolButton.isSelected = isEnabled toolButton.tintColor = isEnabled ? selectedColor : unselectedColor
toolButton.tintColor = isEnabled ? .systemBlue : .secondaryLabel
} }
func updateNetworkState(isEnabled: Bool) { func updateNetworkState(isEnabled: Bool) {
networkButton.isSelected = isEnabled networkButton.tintColor = isEnabled ? selectedColor : unselectedColor
networkButton.tintColor = isEnabled ? .systemBlue : .secondaryLabel
} }
func updateDeepThinkingState(isEnabled: Bool) { func updateDeepThinkingState(isEnabled: Bool) {
deepThinkingButton.isSelected = isEnabled deepThinkingButton.tintColor = isEnabled ? selectedColor : unselectedColor
deepThinkingButton.tintColor = isEnabled ? .systemBlue : .secondaryLabel
} }
func updateSendState(canSend: Bool) { func updateSendState(canSend: Bool) {
@@ -22,7 +22,7 @@ class MainHeaderView: UIView {
private lazy var titleLabel = UILabel().then { private lazy var titleLabel = UILabel().then {
$0.text = "AFFiNE" $0.text = "AFFiNE"
$0.font = .systemFont(ofSize: 16, weight: .medium) $0.font = .systemFont(ofSize: 16, weight: .medium)
$0.textColor = .black $0.textColor = .label
$0.textAlignment = .center $0.textAlignment = .center
} }
@@ -68,7 +68,6 @@ class MainHeaderView: UIView {
init() { init() {
super.init(frame: .zero) super.init(frame: .zero)
backgroundColor = .white
addSubview(mainStackView) addSubview(mainStackView)
mainStackView.snp.makeConstraints { make in mainStackView.snp.makeConstraints { make in