Explorar o código

MediaCategoryViewController: reloadData: Dispatch only if needed

This can lead to visual glitches if this method is called from the
main thread.
Soomin Lee %!s(int64=5) %!d(string=hai) anos
pai
achega
afff1ac973
Modificáronse 1 ficheiros con 10 adicións e 10 borrados
  1. 10 10
      Sources/MediaCategories/MediaCategoryViewController.swift

+ 10 - 10
Sources/MediaCategories/MediaCategoryViewController.swift

@@ -167,18 +167,18 @@ class MediaCategoryViewController: UICollectionViewController, UISearchBarDelega
     }
 
     @objc func reloadData() {
-        DispatchQueue.main.async {
-            [weak self] in
-            guard let self = self else {
-                return
+        guard Thread.isMainThread else {
+            DispatchQueue.main.async {
+                self.reloadData()
             }
-            self.delegate?.needsToUpdateNavigationbarIfNeeded(self)
-            self.collectionView?.reloadData()
-            self.updateUIForContent()
+            return
+        }
+        delegate?.needsToUpdateNavigationbarIfNeeded(self)
+        collectionView?.reloadData()
+        updateUIForContent()
 
-            if !self.isSearching {
-                self.popViewIfNecessary()
-            }
+        if !isSearching {
+            popViewIfNecessary()
         }
     }