marinofaggiana 6 years ago
parent
commit
b278d7550d

+ 23 - 0
iOSClient/Images.xcassets/switchGridChange.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "switchGridChange.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "switchGridChange@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "switchGridChange@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
iOSClient/Images.xcassets/switchGridChange.imageset/switchGridChange.png


BIN
iOSClient/Images.xcassets/switchGridChange.imageset/switchGridChange@2x.png


BIN
iOSClient/Images.xcassets/switchGridChange.imageset/switchGridChange@3x.png


+ 2 - 1
iOSClient/Main/Layout/NCLayout.swift

@@ -68,6 +68,7 @@ class NCGridLayout: UICollectionViewFlowLayout {
     var heightLabelPlusButton: CGFloat = 45
     var preferenceWidth: CGFloat = 110
     var marginLeftRight: CGFloat = 1
+    var numItems: Int = 0
     
     override init() {
         super.init()
@@ -89,7 +90,7 @@ class NCGridLayout: UICollectionViewFlowLayout {
         get {
             if let collectionView = collectionView {
                 
-                let numItems: Int = Int(collectionView.frame.width / preferenceWidth)
+                self.numItems = Int(collectionView.frame.width / preferenceWidth)
                 let itemWidth: CGFloat = (collectionView.frame.width - (marginLeftRight * 2) - CGFloat(numItems)) / CGFloat(numItems)
                 let itemHeight: CGFloat = itemWidth + heightLabelPlusButton
                 return CGSize(width: itemWidth, height: itemHeight)

+ 16 - 6
iOSClient/Media/NCMedia.swift

@@ -49,6 +49,8 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
     private let headerMenuHeight: CGFloat = 50
     private let sectionHeaderHeight: CGFloat = 20
     private let footerHeight: CGFloat = 50
+    
+    private var addWidth: CGFloat = 10
 
     private let refreshControl = UIRefreshControl()
     
@@ -136,8 +138,20 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
     
     func tapSwitchHeader(sender: Any) {
         
+        let itemSizeStart = self.gridLayout.itemSize
+        
         UIView.animate(withDuration: 0.0, animations: {
-            self.gridLayout.preferenceWidth = self.gridLayout.preferenceWidth + 10
+            
+            if self.gridLayout.numItems == 1 && self.addWidth > 0 {
+                self.addWidth = -10
+            } else if itemSizeStart.width < 50 {
+                self.addWidth = 10
+            }
+            
+            repeat {
+                self.gridLayout.preferenceWidth = self.gridLayout.preferenceWidth + self.addWidth
+            } while (self.gridLayout.itemSize == itemSizeStart)
+            
             self.collectionView.collectionViewLayout.invalidateLayout()
         })
     }
@@ -340,11 +354,7 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
                 
                 let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as! NCSectionHeaderMenu
                 
-                if collectionView.collectionViewLayout == gridLayout {
-                    header.buttonSwitch.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "switchList"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), for: .normal)
-                } else {
-                    header.buttonSwitch.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "switchGrid"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), for: .normal)
-                }
+                header.buttonSwitch.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "switchGridChange"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), for: .normal)
                 
                 header.delegate = self