Selaa lähdekoodia

show results and current search position

cyberta 3 vuotta sitten
vanhempi
commit
84d10b4877

+ 3 - 0
deltachat-ios/Chat/ChatViewController.swift

@@ -1801,6 +1801,7 @@ extension ChatViewController: ChatSearchDelegate {
             searchResultIndex -= 1
         }
         scrollToMessage(msgId: searchResult[searchResultIndex])
+        searchAccessoryBar.updateSearchResult(sum: self.searchMessageIds.count, position: searchResultIndex + 1)
     }
 
     func onSearchNextPressed() {
@@ -1812,6 +1813,7 @@ extension ChatViewController: ChatSearchDelegate {
             searchResultIndex += 1
         }
         scrollToMessage(msgId: searchResult[searchResultIndex])
+        searchAccessoryBar.updateSearchResult(sum: self.searchMessageIds.count, position: searchResultIndex + 1)
     }
 }
 
@@ -1830,6 +1832,7 @@ extension ChatViewController: UISearchBarDelegate {
                 if let lastId = resultIds.last {
                     self.scrollToMessage(msgId: lastId)
                 }
+                self.searchAccessoryBar.updateSearchResult(sum: self.searchMessageIds.count, position: self.searchResultIndex + 1)
             }
         }
     }

+ 28 - 9
deltachat-ios/Chat/Views/ChatSearchAccessoryBar.swift

@@ -15,7 +15,6 @@ public class ChatSearchAccessoryBar: UIView, InputItem {
     public func keyboardEditingEndsAction() {}
     public func keyboardEditingBeginsAction() {}
 
-
     public var isEnabled: Bool {
         willSet(newValue) {
             upButton.isEnabled = newValue
@@ -57,11 +56,20 @@ public class ChatSearchAccessoryBar: UIView, InputItem {
         return view
     }()
 
-    private lazy var mainContentView: UIStackView = {
+    private lazy var searchResultLabel: UILabel = {
+        let view = UILabel(frame: .zero)
+        view.font = UIFont.preferredFont(for: .body, weight: .regular)
+        view.textColor = DcColors.grayDateColor
+        view.textAlignment = .center
+        view.translatesAutoresizingMaskIntoConstraints = false
+        return view
+    }()
+
+    private lazy var buttonContainer: UIStackView = {
         let view = UIStackView(arrangedSubviews: [downButton, upButton])
         view.axis = .horizontal
-        view.distribution = .fillEqually
-        view.alignment = .center
+        view.distribution = .equalSpacing
+        view.alignment = .trailing
         view.translatesAutoresizingMaskIntoConstraints = false
         return view
     }()
@@ -82,13 +90,16 @@ public class ChatSearchAccessoryBar: UIView, InputItem {
     }
 
     public func setupSubviews() {
-        addSubview(mainContentView)
+        addSubview(searchResultLabel)
+        addSubview(buttonContainer)
 
         addConstraints([
-            mainContentView.constraintAlignTopTo(self, paddingTop: 4),
-            mainContentView.constraintAlignBottomTo(self, paddingBottom: 4),
-            mainContentView.constraintAlignLeadingTo(self),
-            mainContentView.constraintAlignTrailingTo(self),
+            searchResultLabel.constraintCenterYTo(self),
+            searchResultLabel.constraintCenterXTo(self),
+            buttonContainer.constraintAlignTopTo(self, paddingTop: 4),
+            buttonContainer.constraintAlignBottomTo(self, paddingBottom: 4),
+            buttonContainer.constraintWidthTo(100),
+            buttonContainer.constraintAlignTrailingToAnchor(self.safeAreaLayoutGuide.trailingAnchor, paddingTrailing: 23),
             upButton.constraintHeightTo(36),
             downButton.constraintHeightTo(36),
         ])
@@ -109,4 +120,12 @@ public class ChatSearchAccessoryBar: UIView, InputItem {
     @objc func onDownPressed() {
         delegate?.onSearchNextPressed()
     }
+
+    public func updateSearchResult(sum: Int, position: Int) {
+        if sum == 0 {
+            searchResultLabel.text = nil
+        } else {
+            searchResultLabel.text = "\(position) / \(sum)"
+        }
+    }
 }