@@ -14,6 +14,7 @@ import UIKit
14
14
func gridView( _ gridView: GridView , cellForRowAt indexPath: IndexPath ) -> GridViewCell
15
15
16
16
@objc optional func numberOfColumns( in gridView: GridView ) -> Int
17
+ @objc optional func numberOfColumnsPerPage( in gridView: GridView ) -> Int
17
18
}
18
19
19
20
// MARK: -
@@ -42,7 +43,7 @@ open class GridView: UIScrollView {
42
43
override open class var layerClass : AnyClass {
43
44
return AnimatedLayer . self
44
45
}
45
-
46
+
46
47
/// Set `false` if you don't need to loop of view. Default is `true`.
47
48
open var isInfinitable = true
48
49
/// Set the vertical and horizontal minimum scales. Default for x and y are 1.
@@ -179,12 +180,11 @@ open class GridView: UIScrollView {
179
180
let inset = UIEdgeInsets ( top: - frame. minY, left: - frame. minX, bottom: - superview . bounds . height + frame. maxY, right: - superview . bounds . width + frame. maxX)
180
181
super. scrollIndicatorInsets = inset + originScrollIndicatorInsets
181
182
}
182
-
183
- stopScroll ( )
184
-
183
+
185
184
columnRow. removeAll ( )
186
185
currentInfo = ViewVisibleInfo ( )
187
186
currentMatrix = makeMatrix ( . all( currentMatrix) )
187
+ print ( " Matrix Reload = " , currentMatrix)
188
188
189
189
performWithoutDelegation {
190
190
contentSize = currentMatrix. contentSize
@@ -196,7 +196,6 @@ open class GridView: UIScrollView {
196
196
layoutToRemoveCells ( )
197
197
198
198
case . layout( let type) :
199
- stopScroll ( )
200
199
201
200
currentMatrix = makeMatrix ( type)
202
201
@@ -233,6 +232,41 @@ open class GridView: UIScrollView {
233
232
layoutToRemoveCells ( )
234
233
}
235
234
235
+ case . appendVertical:
236
+ if let superview = superview {
237
+ let inset = UIEdgeInsets ( top: - frame. minY, left: - frame. minX, bottom: - superview . bounds . height + frame. maxY, right: - superview . bounds . width + frame. maxX)
238
+ super. scrollIndicatorInsets = inset + originScrollIndicatorInsets
239
+ }
240
+
241
+ columnRow. removeAll ( )
242
+ currentInfo = ViewVisibleInfo ( )
243
+ currentMatrix = makeMatrix ( . appendVertical( currentMatrix) )
244
+ print ( " Matrix Append Vertical = " , currentMatrix)
245
+
246
+ performWithoutDelegation {
247
+ contentSize = currentMatrix. contentSize
248
+ }
249
+ contentOffset = currentMatrix. convert ( lastValidityContentOffset, from: currentMatrix)
250
+ super. contentInset = currentMatrix. contentInset
251
+
252
+ infiniteIfNeeded ( )
253
+ layoutToRemoveCells ( )
254
+
255
+ case . appendHorizontal:
256
+
257
+ columnRow. removeAll ( )
258
+ currentInfo = ViewVisibleInfo ( )
259
+ currentMatrix = makeMatrix ( . appendHorizontal( currentMatrix) )
260
+ print ( " Matrix Append Horizontal = " , currentMatrix)
261
+
262
+ performWithoutDelegation {
263
+ contentSize = currentMatrix. contentSize
264
+ }
265
+ contentOffset = currentMatrix. convert ( lastValidityContentOffset, from: currentMatrix)
266
+ super. contentInset = currentMatrix. contentInset
267
+
268
+ infiniteIfNeeded ( )
269
+ layoutToRemoveCells ( )
236
270
}
237
271
238
272
UIView . setAnimationsEnabled ( areAnimationsEnabled)
@@ -267,6 +301,10 @@ open class GridView: UIScrollView {
267
301
}
268
302
}
269
303
304
+ fileprivate func columnCountPerPage( ) -> Int {
305
+ return dataSource? . numberOfColumnsPerPage ? ( in: self ) ?? 0
306
+ }
307
+
270
308
fileprivate func rowCount( in column: Int ) -> Int {
271
309
if let rowCount = columnRow [ column] {
272
310
return rowCount
@@ -407,6 +445,16 @@ extension GridView {
407
445
layoutIfNeeded ( )
408
446
}
409
447
448
+ public func appendTime( ) {
449
+ setNeedsLayout ( . appendVertical)
450
+ layoutIfNeeded ( )
451
+ }
452
+
453
+ public func appendChannel( ) {
454
+ setNeedsLayout ( . appendHorizontal)
455
+ layoutIfNeeded ( )
456
+ }
457
+
410
458
public func invalidateContentSize( ) {
411
459
setNeedsLayout ( . layout( . rotating( currentMatrix) ) )
412
460
}
@@ -769,18 +817,14 @@ private extension GridView {
769
817
770
818
( 0 ..< count) . forEach { column in
771
819
if let widthForColumn = gridViewDelegate? . gridView ? ( self , widthForColumn: column) {
772
- let horizontal = Horizontal ( x: size. width, width: widthForColumn)
773
- columnHorizontals. append ( horizontal)
774
820
size. width += widthForColumn
775
821
}
776
822
777
- if case . all = type {
778
- let columnVerticals = verticalsForRow ( in: column)
779
- columnRowVerticals. append ( columnVerticals)
780
-
781
- if let last = columnVerticals. last, let vertical = last, size. height < vertical. maxY {
782
- size. height = vertical. maxY
783
- }
823
+ let columnVerticals = verticalsForRow ( in: column)
824
+ columnRowVerticals. append ( columnVerticals)
825
+
826
+ if let last = columnVerticals. last, let vertical = last, size. height < vertical. maxY {
827
+ size. height = vertical. maxY
784
828
}
785
829
}
786
830
@@ -796,6 +840,81 @@ private extension GridView {
796
840
} else {
797
841
return ViewMatrix ( horizontals: horizontals, verticals: columnRowVerticals, viewFrame: frame, contentHeight: size. height, superviewSize: superview? . bounds. size, scale: currentScale, inset: contentInset, isInfinitable: isInfinitable)
798
842
}
843
+
844
+ case . appendVertical( let matrix) :
845
+ var copyMatrix = matrix
846
+ var size : CGSize = . zero
847
+ if let arrayHorizontal = copyMatrix. horizontals,
848
+ let lastItem = arrayHorizontal. last {
849
+ size. width = lastItem. maxX
850
+ }
851
+
852
+ let count = columnCount ( )
853
+ var columnHorizontals : [ Horizontal ] = [ ]
854
+ var columnRowVerticals : [ [ Vertical ? ] ] = [ ]
855
+
856
+ ( 0 ..< count) . forEach { column in
857
+ if let widthForColumn = gridViewDelegate? . gridView ? ( self , widthForColumn: column) {
858
+ size. width += widthForColumn
859
+ }
860
+
861
+ let columnVerticals = verticalsForRow ( in: column)
862
+ columnRowVerticals. append ( columnVerticals)
863
+
864
+ if let last = columnVerticals. last, let vertical = last, size. height < vertical. maxY {
865
+ size. height = vertical. maxY
866
+ }
867
+ }
868
+
869
+ let horizontals : [ Horizontal ] ?
870
+ if columnHorizontals. count > 0 && columnHorizontals. count == count {
871
+ horizontals = columnHorizontals
872
+ } else {
873
+ horizontals = nil
874
+ }
875
+
876
+ copyMatrix. appendVerticals ( horizontals: horizontals, verticals: columnRowVerticals, viewFrame: frame, contentHeight: size. height, superviewSize: superview? . bounds. size, scale: currentScale)
877
+
878
+ return copyMatrix
879
+
880
+ case . appendHorizontal( let matrix) :
881
+
882
+ var copyMatrix = matrix
883
+ var size : CGSize = . zero
884
+ if let arrayHorizontal = copyMatrix. horizontals,
885
+ let lastItem = arrayHorizontal. last {
886
+ size. width = lastItem. maxX
887
+ }
888
+
889
+ let count = columnCount ( )
890
+ var columnHorizontals : [ Horizontal ] = [ ]
891
+ var columnRowVerticals : [ [ Vertical ? ] ] = [ ]
892
+
893
+ ( 0 ..< count) . forEach { column in
894
+ if let widthForColumn = gridViewDelegate? . gridView ? ( self , widthForColumn: column) {
895
+ let horizontal = Horizontal ( x: size. width, width: widthForColumn)
896
+ columnHorizontals. append ( horizontal)
897
+ size. width += widthForColumn
898
+ }
899
+
900
+ let columnVerticals = verticalsForRow ( in: column)
901
+ columnRowVerticals. append ( columnVerticals)
902
+
903
+ if let last = columnVerticals. last, let vertical = last, size. height < vertical. maxY {
904
+ size. height = vertical. maxY
905
+ }
906
+ }
907
+
908
+ let horizontals : [ Horizontal ] ?
909
+ if columnHorizontals. count > 0 && columnHorizontals. count == count {
910
+ horizontals = columnHorizontals
911
+ } else {
912
+ horizontals = nil
913
+ }
914
+
915
+ copyMatrix. appendHorizontals ( horizontals: horizontals, verticals: columnRowVerticals, viewFrame: frame, contentHeight: size. height, superviewSize: superview? . bounds. size, scale: currentScale)
916
+
917
+ return copyMatrix
799
918
}
800
919
}
801
920
}
0 commit comments