NCTrashLayout.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // NCOfflineLayout.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 29/10/2018.
  6. // Copyright © 2018 TWS. All rights reserved.
  7. //
  8. import Foundation
  9. class NCListLayoutTrash: UICollectionViewFlowLayout {
  10. let itemHeight: CGFloat = 60
  11. override init() {
  12. super.init()
  13. sectionHeadersPinToVisibleBounds = false
  14. minimumInteritemSpacing = 0
  15. minimumLineSpacing = 1
  16. self.scrollDirection = .vertical
  17. self.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
  18. }
  19. required init?(coder aDecoder: NSCoder) {
  20. fatalError("init(coder:) has not been implemented")
  21. }
  22. override var itemSize: CGSize {
  23. get {
  24. if let collectionView = collectionView {
  25. let itemWidth: CGFloat = collectionView.frame.width
  26. return CGSize(width: itemWidth, height: self.itemHeight)
  27. }
  28. // Default fallback
  29. return CGSize(width: 100, height: 100)
  30. }
  31. set {
  32. super.itemSize = newValue
  33. }
  34. }
  35. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  36. return proposedContentOffset
  37. }
  38. }
  39. class NCGridLayoutTrash: UICollectionViewFlowLayout {
  40. let heightLabelPlusButton: CGFloat = 45
  41. let preferenceWidth: CGFloat = 110
  42. let marginLeftRight: CGFloat = 5
  43. override init() {
  44. super.init()
  45. sectionHeadersPinToVisibleBounds = false
  46. minimumInteritemSpacing = 1
  47. minimumLineSpacing = 1
  48. self.scrollDirection = .vertical
  49. self.sectionInset = UIEdgeInsets(top: 10, left: marginLeftRight, bottom: 10, right: marginLeftRight)
  50. }
  51. required init?(coder aDecoder: NSCoder) {
  52. fatalError("init(coder:) has not been implemented")
  53. }
  54. override var itemSize: CGSize {
  55. get {
  56. if let collectionView = collectionView {
  57. let numItems: Int = Int(collectionView.frame.width / preferenceWidth)
  58. let itemWidth: CGFloat = (collectionView.frame.width - (marginLeftRight * 2) - CGFloat(numItems)) / CGFloat(numItems)
  59. let itemHeight: CGFloat = itemWidth + heightLabelPlusButton
  60. return CGSize(width: itemWidth, height: itemHeight)
  61. }
  62. // Default fallback
  63. return CGSize(width: 100, height: 100)
  64. }
  65. set {
  66. super.itemSize = newValue
  67. }
  68. }
  69. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  70. return proposedContentOffset
  71. }
  72. }