Просмотр исходного кода

set grid's itemSize only if overall size is already set

would be even better to skip too-soon-calculation completely,
but that would require some larger refactoring,
also it is unclear, where it actually comes from,
might be very hard.
B. Petersen 2 лет назад
Родитель
Сommit
4c63d9ccdc
1 измененных файлов с 6 добавлено и 4 удалено
  1. 6 4
      deltachat-ios/Helper/GridCollectionViewFlowLayout.swift

+ 6 - 4
deltachat-ios/Helper/GridCollectionViewFlowLayout.swift

@@ -64,12 +64,14 @@ class GridCollectionViewFlowLayout: UICollectionViewFlowLayout {
             self.scrollDirection = .vertical
             let spacing = CGFloat(column - 1) * minimumLineSpacing
             let optimisedWidth = (containerWidth - spacing) / CGFloat(column)
-            let height = calculateHeight(width: optimisedWidth)
-            self.itemSize = CGSize(width: optimisedWidth, height: height) // keep as square
+            if optimisedWidth > 0 {
+                self.itemSize = CGSize(width: optimisedWidth, height: calculateHeight(width: optimisedWidth))
+            }
         case .list:
             self.scrollDirection = .vertical
-            let height = calculateHeight(width: containerWidth)
-            self.itemSize = CGSize(width: containerWidth, height: height)
+            if containerWidth > 0 {
+                self.itemSize = CGSize(width: containerWidth, height: calculateHeight(width: containerWidth))
+            }
         }
     }