marinofaggiana 4 years ago
parent
commit
c093775e9b
2 changed files with 11 additions and 9 deletions
  1. 2 2
      iOSClient/Favorites/NCFavorite.swift
  2. 9 7
      iOSClient/Main/NCCollectionCommon.swift

+ 2 - 2
iOSClient/Favorites/NCFavorite.swift

@@ -100,7 +100,7 @@ class NCFavorite: NCCollectionViewCommon  {
         
         (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey)
         
-        if searchController?.isActive ?? false == false {
+        if !isSearching {
        
             if serverUrl == "" {
                 metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND favorite == true", appDelegate.account))
@@ -117,7 +117,7 @@ class NCFavorite: NCCollectionViewCommon  {
     
     override func reloadDataSourceNetwork() {
        
-        if searchController?.isActive ?? false {
+        if isSearching {
         
             if literalSearch == nil || literalSearch?.count ?? 0 < 2 {
                 self.reloadDataSource()

+ 9 - 7
iOSClient/Main/NCCollectionCommon.swift

@@ -676,10 +676,11 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         if enableSearchBar {
             searchController = UISearchController(searchResultsController: nil)
-            searchController!.searchResultsUpdater = self
+            searchController?.searchResultsUpdater = self
             self.navigationItem.searchController = searchController
-            searchController!.delegate = self
-            searchController!.searchBar.delegate = self
+            searchController?.dimsBackgroundDuringPresentation = false
+            searchController?.delegate = self
+            searchController?.searchBar.delegate = self
         }
         
         // Cell
@@ -951,12 +952,13 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     
     func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
         
-        dataSource = NCDataSource.init()
-        collectionView.reloadData()
+        isSearching = true
+        metadatasSource.removeAll()
+        reloadDataSource()
     }
     
-    func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
-        
+    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
+        isSearching = false
         literalSearch = ""
         reloadDataSource()
     }