NCOfflineLayout.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // NCOfflineLayout.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 27/10/2018.
  6. // Copyright © 2018 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. class listLayoutOffline: UICollectionViewFlowLayout {
  25. let itemHeight: CGFloat = 60
  26. override init() {
  27. super.init()
  28. minimumInteritemSpacing = 0
  29. minimumLineSpacing = 1
  30. self.scrollDirection = .vertical
  31. self.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  32. }
  33. required init?(coder aDecoder: NSCoder) {
  34. fatalError("init(coder:) has not been implemented")
  35. }
  36. override var itemSize: CGSize {
  37. get {
  38. if let collectionView = collectionView {
  39. let itemWidth: CGFloat = collectionView.frame.width
  40. return CGSize(width: itemWidth, height: self.itemHeight)
  41. }
  42. // Default fallback
  43. return CGSize(width: 100, height: 100)
  44. }
  45. set {
  46. super.itemSize = newValue
  47. }
  48. }
  49. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  50. return proposedContentOffset
  51. }
  52. }
  53. class gridLayoutOffline: UICollectionViewFlowLayout {
  54. let heightLabelPlusButton: CGFloat = 45
  55. let preferenceWidth: CGFloat = 110
  56. let marginLeftRight: CGFloat = 5
  57. override init() {
  58. super.init()
  59. minimumInteritemSpacing = 1
  60. minimumLineSpacing = 1
  61. self.scrollDirection = .vertical
  62. self.sectionInset = UIEdgeInsets(top: 10, left: marginLeftRight, bottom: 0, right: marginLeftRight)
  63. }
  64. required init?(coder aDecoder: NSCoder) {
  65. fatalError("init(coder:) has not been implemented")
  66. }
  67. override var itemSize: CGSize {
  68. get {
  69. if let collectionView = collectionView {
  70. let numItems: Int = Int(collectionView.frame.width / preferenceWidth)
  71. let itemWidth: CGFloat = (collectionView.frame.width - (marginLeftRight * 2) - CGFloat(numItems)) / CGFloat(numItems)
  72. let itemHeight: CGFloat = itemWidth + heightLabelPlusButton
  73. return CGSize(width: itemWidth, height: itemHeight)
  74. }
  75. // Default fallback
  76. return CGSize(width: 100, height: 100)
  77. }
  78. set {
  79. super.itemSize = newValue
  80. }
  81. }
  82. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  83. return proposedContentOffset
  84. }
  85. }