Эх сурвалжийг харах

implment basic chat search input accessory view

cyberta 3 жил өмнө
parent
commit
96752ca5d7

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -74,6 +74,7 @@
 		30A4149724F6EFBE00EC91EB /* InfoMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A4149624F6EFBE00EC91EB /* InfoMessageCell.swift */; };
 		30B0ACFA24AB5B99004D5E29 /* SettingsEphemeralMessageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30B0ACF924AB5B99004D5E29 /* SettingsEphemeralMessageController.swift */; };
 		30C0D49D237C4908008E2A0E /* CertificateCheckController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30C0D49C237C4908008E2A0E /* CertificateCheckController.swift */; };
+		30C2BFFE27032375005505DA /* ChatSearchAccessoryBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30C2BFFD27032375005505DA /* ChatSearchAccessoryBar.swift */; };
 		30E348DF24F3F819005C93D1 /* ChatTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348DE24F3F819005C93D1 /* ChatTableView.swift */; };
 		30E348E124F53772005C93D1 /* ImageTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348E024F53772005C93D1 /* ImageTextCell.swift */; };
 		30E348E524F6647D005C93D1 /* FileTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348E424F6647D005C93D1 /* FileTextCell.swift */; };
@@ -325,6 +326,7 @@
 		30AC265E237F1807002A943F /* AvatarHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarHelper.swift; sourceTree = "<group>"; };
 		30B0ACF924AB5B99004D5E29 /* SettingsEphemeralMessageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsEphemeralMessageController.swift; sourceTree = "<group>"; };
 		30C0D49C237C4908008E2A0E /* CertificateCheckController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertificateCheckController.swift; sourceTree = "<group>"; };
+		30C2BFFD27032375005505DA /* ChatSearchAccessoryBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatSearchAccessoryBar.swift; sourceTree = "<group>"; };
 		30E348DE24F3F819005C93D1 /* ChatTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTableView.swift; sourceTree = "<group>"; };
 		30E348E024F53772005C93D1 /* ImageTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageTextCell.swift; sourceTree = "<group>"; };
 		30E348E424F6647D005C93D1 /* FileTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTextCell.swift; sourceTree = "<group>"; };
@@ -605,6 +607,7 @@
 				303492CE2587C2DC00A523D0 /* ChatInputBar.swift */,
 				3067AA4B2666310E00525036 /* ChatInputTextView.swift */,
 				307A82CB25B8D26700748B57 /* ChatEditingBar.swift */,
+				30C2BFFD27032375005505DA /* ChatSearchAccessoryBar.swift */,
 				302D54692693591700A8B271 /* ChatContactRequestBar.swift */,
 				302E1BB3252B5AB4008F4264 /* PlayButtonView.swift */,
 				30F8817524DA97DA0023780E /* BackgroundContainer.swift */,
@@ -1280,6 +1283,7 @@
 				30FDB70524D1C1000066C48D /* ChatViewController.swift in Sources */,
 				AE52EA20229EB9F000C586C9 /* EditGroupViewController.swift in Sources */,
 				AE18F294228C602A0007B1BE /* SecuritySettingsController.swift in Sources */,
+				30C2BFFE27032375005505DA /* ChatSearchAccessoryBar.swift in Sources */,
 				AE39D323249CFC1A007346A1 /* DocumentGalleryController.swift in Sources */,
 				AE8DD451249D1DFB009A4BC1 /* DocumentGalleryFileCell.swift in Sources */,
 				3095A351237DD1F700AB07F7 /* MediaPicker.swift in Sources */,

+ 131 - 0
deltachat-ios/Chat/Views/ChatSearchAccessoryBar.swift

@@ -0,0 +1,131 @@
+import UIKit
+import InputBarAccessoryView
+import DcCore
+
+public protocol ChatSearchDelegate: class {
+    func onSearchPreviousPressed()
+    func onSearchNextPressed()
+    func onCancelSearchPressed()
+}
+
+public class ChatSearchAccessoryBar: UIView, InputItem {
+    public var inputBarAccessoryView: InputBarAccessoryView?
+    public var parentStackViewPosition: InputStackView.Position?
+    public func textViewDidChangeAction(with textView: InputTextView) {}
+    public func keyboardSwipeGestureAction(with gesture: UISwipeGestureRecognizer) {}
+    public func keyboardEditingEndsAction() {}
+    public func keyboardEditingBeginsAction() {}
+
+
+    public var isEnabled: Bool {
+        willSet(newValue) {
+            upButton.isEnabled = newValue
+            downButton.isEnabled = newValue
+        }
+    }
+
+    weak var delegate: ChatSearchDelegate?
+
+    private lazy var cancelButton: UIButton = {
+        let view = UIButton()
+        view.setTitle(String.localized("cancel"), for: .normal)
+        view.setTitleColor(.systemBlue, for: .normal)
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.imageView?.contentMode = .scaleAspectFit
+        view.isUserInteractionEnabled = true
+        return view
+    }()
+
+    private lazy var upButton: UIButton = {
+        let view = UIButton()
+
+        if #available(iOS 13.0, *) {
+            view.setImage(UIImage(systemName: "chevron.up"), for: .normal)
+            view.tintColor = .systemBlue
+        } else {
+            view.setTitle(String.localized("previous"), for: .normal)
+            view.setTitleColor(.systemBlue, for: .normal)
+        }
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.isUserInteractionEnabled = true
+        view.imageView?.contentMode = .scaleAspectFit
+        return view
+    }()
+
+    private lazy var downButton: UIButton = {
+        let view = UIButton()
+        view.tintColor = .systemBlue
+        if #available(iOS 13.0, *) {
+            view.setImage(UIImage(systemName: "chevron.down"), for: .normal)
+            view.tintColor = .systemBlue
+        } else {
+            view.setTitle(String.localized("next"), for: .normal)
+            view.setTitleColor(.systemBlue, for: .normal)
+        }
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.imageView?.contentMode = .scaleAspectFit
+        view.isUserInteractionEnabled = true
+        return view
+    }()
+
+    private lazy var mainContentView: UIStackView = {
+        let view = UIStackView(arrangedSubviews: [cancelButton, downButton, upButton])
+        view.axis = .horizontal
+        view.distribution = .fillEqually
+        view.alignment = .center
+        view.translatesAutoresizingMaskIntoConstraints = false
+        return view
+    }()
+
+    convenience init() {
+        self.init(frame: .zero)
+
+    }
+
+    public override init(frame: CGRect) {
+        isEnabled = false
+        super.init(frame: frame)
+        self.setupSubviews()
+    }
+
+    required init(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    public func setupSubviews() {
+        addSubview(mainContentView)
+
+        addConstraints([
+            mainContentView.constraintAlignTopTo(self, paddingTop: 4),
+            mainContentView.constraintAlignBottomTo(self, paddingBottom: 4),
+            mainContentView.constraintAlignLeadingTo(self),
+            mainContentView.constraintAlignTrailingTo(self),
+            upButton.constraintHeightTo(36),
+            downButton.constraintHeightTo(26),
+            cancelButton.constraintHeightTo(36),
+        ])
+
+        backgroundColor = DcColors.chatBackgroundColor
+
+        let cancelGestureListener = UITapGestureRecognizer(target: self, action: #selector(onCancelPressed))
+        cancelButton.addGestureRecognizer(cancelGestureListener)
+
+        let upGestaureListener = UITapGestureRecognizer(target: self, action: #selector(onUpPressed))
+        upButton.addGestureRecognizer(upGestaureListener)
+
+        let downGestureListener = UITapGestureRecognizer(target: self, action: #selector(onDownPressed))
+        downButton.addGestureRecognizer(downGestureListener)
+    }
+
+    @objc func onCancelPressed() {
+        delegate?.onCancelSearchPressed()
+    }
+
+    @objc func onUpPressed() {
+        delegate?.onSearchPreviousPressed()
+    }
+
+    @objc func onDownPressed() {
+        delegate?.onSearchNextPressed()
+    }
+}