From 92887791fc32e8bca80375f4bd12de3b7e8bf887 Mon Sep 17 00:00:00 2001 From: Lakr Date: Thu, 19 Jun 2025 01:25:11 +0800 Subject: [PATCH] feat: input box menu --- .../App/Packages/Intelligents/Package.swift | 2 +- .../MainViewController+Header.swift | 2 +- .../MainViewController+Input.swift | 16 ++++++ .../Interface/Supplement/AccentColor.swift | 2 +- .../Interface/View/InputBox/InputBox.swift | 26 +++++++--- .../View/InputBox/InputBoxDelegate.swift | 5 +- .../View/InputBox/InputBoxFunctionBar.swift | 51 +++++++++++++++++-- 7 files changed, 88 insertions(+), 16 deletions(-) diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Package.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Package.swift index 16facb48c6..79502ef077 100644 --- a/packages/frontend/apps/ios/App/Packages/Intelligents/Package.swift +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Package.swift @@ -18,7 +18,7 @@ let package = Package( .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/SnapKit/SnapKit.git", from: "5.0.1"), - .package(url: "https://github.com/SwifterSwift/SwifterSwift.git", from: "6.0.0") + .package(url: "https://github.com/SwifterSwift/SwifterSwift.git", from: "6.0.0"), ], targets: [ .target(name: "Intelligents", dependencies: [ diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController+Header.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController+Header.swift index 69bc267a05..36fb59af9f 100644 --- a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController+Header.swift +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController+Header.swift @@ -1,5 +1,5 @@ // -// File.swift +// MainViewController+Header.swift // Intelligents // // Created by 秋星桥 on 6/19/25. diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController+Input.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController+Input.swift index b1b4efa52b..c43474e924 100644 --- a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController+Input.swift +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Controller/MainViewController/MainViewController+Input.swift @@ -8,6 +8,22 @@ import UIKit extension MainViewController: InputBoxDelegate { + func inputBoxDidSelectTakePhoto(_ inputBox: InputBox) { + print(#function, inputBox) + } + + func inputBoxDidSelectPhotoLibrary(_ inputBox: InputBox) { + print(#function, inputBox) + } + + func inputBoxDidSelectAttachFiles(_ inputBox: InputBox) { + print(#function, inputBox) + } + + func inputBoxDidSelectEmbedDocs(_ inputBox: InputBox) { + print(#function, inputBox) + } + func inputBoxDidSelectAttachment(_ inputBox: InputBox) { print(#function, inputBox) } diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Supplement/AccentColor.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Supplement/AccentColor.swift index 3a60a305da..eec75f6f0a 100644 --- a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Supplement/AccentColor.swift +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/Supplement/AccentColor.swift @@ -1,5 +1,5 @@ // -// File.swift +// AccentColor.swift // Intelligents // // Created by 秋星桥 on 6/19/25. diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBox.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBox.swift index 638a25c530..9e315245f0 100644 --- a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBox.swift +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBox.swift @@ -70,7 +70,7 @@ class InputBox: UIView { updateTextViewHeight() } } - + override init(frame: CGRect = .zero) { super.init(frame: frame) setupViews() @@ -164,15 +164,15 @@ class InputBox: UIView { func updateTextViewHeight() { let size = textView.sizeThatFits(CGSize(width: textView.frame.width, height: CGFloat.greatestFiniteMagnitude)) let newHeight = max(minTextViewHeight, min(maxTextViewHeight, size.height)) - + let height = textView.frame.height guard height != newHeight else { return } - + textViewHeightConstraint?.update(offset: newHeight) textView.isScrollEnabled = size.height > maxTextViewHeight - + if height == 0 || superview == nil || window == nil || isHidden { return } - + UIView.animate( withDuration: 0.5, delay: 0, @@ -231,8 +231,20 @@ class InputBox: UIView { // MARK: - InputBoxFunctionBarDelegate extension InputBox: InputBoxFunctionBarDelegate { - func functionBarDidTapAttachment(_: InputBoxFunctionBar) { - delegate?.inputBoxDidSelectAttachment(self) + func functionBarDidTapTakePhoto(_: InputBoxFunctionBar) { + delegate?.inputBoxDidSelectTakePhoto(self) + } + + func functionBarDidTapPhotoLibrary(_: InputBoxFunctionBar) { + delegate?.inputBoxDidSelectPhotoLibrary(self) + } + + func functionBarDidTapAttachFiles(_: InputBoxFunctionBar) { + delegate?.inputBoxDidSelectAttachFiles(self) + } + + func functionBarDidTapEmbedDocs(_: InputBoxFunctionBar) { + delegate?.inputBoxDidSelectEmbedDocs(self) } func functionBarDidTapTool(_: InputBoxFunctionBar) { diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBoxDelegate.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBoxDelegate.swift index f62a37df2a..636afbc918 100644 --- a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBoxDelegate.swift +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBoxDelegate.swift @@ -8,7 +8,10 @@ import UIKit protocol InputBoxDelegate: AnyObject { - func inputBoxDidSelectAttachment(_ inputBox: InputBox) + func inputBoxDidSelectTakePhoto(_ inputBox: InputBox) + func inputBoxDidSelectPhotoLibrary(_ inputBox: InputBox) + func inputBoxDidSelectAttachFiles(_ inputBox: InputBox) + func inputBoxDidSelectEmbedDocs(_ inputBox: InputBox) func inputBoxDidSend(_ inputBox: InputBox) func inputBoxTextDidChange(_ text: String) } diff --git a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBoxFunctionBar.swift b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBoxFunctionBar.swift index c643f018ce..4fd5e3b38a 100644 --- a/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBoxFunctionBar.swift +++ b/packages/frontend/apps/ios/App/Packages/Intelligents/Sources/Intelligents/Interface/View/InputBox/InputBoxFunctionBar.swift @@ -3,7 +3,10 @@ import Then import UIKit protocol InputBoxFunctionBarDelegate: AnyObject { - func functionBarDidTapAttachment(_ functionBar: InputBoxFunctionBar) + func functionBarDidTapTakePhoto(_ functionBar: InputBoxFunctionBar) + func functionBarDidTapPhotoLibrary(_ functionBar: InputBoxFunctionBar) + func functionBarDidTapAttachFiles(_ functionBar: InputBoxFunctionBar) + func functionBarDidTapEmbedDocs(_ functionBar: InputBoxFunctionBar) func functionBarDidTapTool(_ functionBar: InputBoxFunctionBar) func functionBarDidTapNetwork(_ functionBar: InputBoxFunctionBar) func functionBarDidTapDeepThinking(_ functionBar: InputBoxFunctionBar) @@ -20,7 +23,8 @@ class InputBoxFunctionBar: UIView { $0.setImage(UIImage(named: "inputbox.add.attachment", in: .module, with: nil), for: .normal) $0.tintColor = unselectedColor $0.imageView?.contentMode = .scaleAspectFit - $0.addTarget(self, action: #selector(attachmentButtonTapped), for: .touchUpInside) + $0.showsMenuAsPrimaryAction = true + $0.menu = createAttachmentMenu() } lazy var toolButton = UIButton(type: .system).then { @@ -131,12 +135,49 @@ class InputBoxFunctionBar: UIView { sendButton.alpha = canSend ? 1.0 : 0.5 } - // MARK: - Actions + // MARK: - Private Methods - @objc private func attachmentButtonTapped() { - delegate?.functionBarDidTapAttachment(self) + private func createAttachmentMenu() -> UIMenu { + let takePhotoAction = UIAction( + title: "Take Photo or Video", + image: UIImage(systemName: "camera") + ) { [weak self] _ in + guard let self else { return } + delegate?.functionBarDidTapTakePhoto(self) + } + + let photoLibraryAction = UIAction( + title: "Photo Library", + image: UIImage(systemName: "photo.on.rectangle") + ) { [weak self] _ in + guard let self else { return } + delegate?.functionBarDidTapPhotoLibrary(self) + } + + let attachFilesAction = UIAction( + title: "Attach Files (pdf, txt, csv)", + image: UIImage(systemName: "arrow.up.doc") + ) { [weak self] _ in + guard let self else { return } + delegate?.functionBarDidTapAttachFiles(self) + } + + let embedDocsAction = UIAction( + title: "Embed AFFINE Docs", + image: UIImage(systemName: "doc.text") + ) { [weak self] _ in + guard let self else { return } + delegate?.functionBarDidTapEmbedDocs(self) + } + + return UIMenu( + options: [.displayInline], + children: [takePhotoAction, photoLibraryAction, attachFilesAction, embedDocsAction].reversed() + ) } + // MARK: - Actions + @objc private func toolButtonTapped() { delegate?.functionBarDidTapTool(self) }