Browse Source

Merge pull request #2568 from dogra25130/bug/transition-fix

Transition bug fix
Marino Faggiana 1 year ago
parent
commit
0bb7a90c48
1 changed files with 8 additions and 6 deletions
  1. 8 6
      iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

+ 8 - 6
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -68,7 +68,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     private var pushed: Bool = false
 
     private var tipView: EasyTipView?
-
+    private var isTransitioning: Bool = false
     // DECLARE
     internal var layoutKey = ""
     internal var titleCurrentFolder = ""
@@ -788,9 +788,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     func accountRequestAddAccount() {
         appDelegate.openLogin(viewController: self, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
     }
-
+    
     func tapButtonSwitch(_ sender: Any) {
-
+        
+        guard isTransitioning == false else { return }
+        isTransitioning = true
+        
         if layoutForView?.layout == NCGlobal.shared.layoutGrid {
 
             // list layout
@@ -804,8 +807,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
             self.collectionView.reloadData()
             self.collectionView.collectionViewLayout.invalidateLayout()
-            self.collectionView.setCollectionViewLayout(self.listLayout, animated: true)
-
+            self.collectionView.setCollectionViewLayout(self.listLayout, animated: true) {_ in self.isTransitioning = false }
         } else {
 
             // grid layout
@@ -823,7 +825,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
             self.collectionView.reloadData()
             self.collectionView.collectionViewLayout.invalidateLayout()
-            self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true)
+            self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true) {_ in self.isTransitioning = false }
         }
     }