@@ -14,6 +14,7 @@ import UIKit
1414 func gridView( _ gridView: GridView , cellForRowAt indexPath: IndexPath ) -> GridViewCell
1515
1616 @objc optional func numberOfColumns( in gridView: GridView ) -> Int
17+ @objc optional func numberOfColumnsPerPage( in gridView: GridView ) -> Int
1718}
1819
1920// MARK: -
@@ -42,7 +43,7 @@ open class GridView: UIScrollView {
4243 override open class var layerClass : AnyClass {
4344 return AnimatedLayer . self
4445 }
45-
46+
4647 /// Set `false` if you don't need to loop of view. Default is `true`.
4748 open var isInfinitable = true
4849 /// Set the vertical and horizontal minimum scales. Default for x and y are 1.
@@ -179,12 +180,11 @@ open class GridView: UIScrollView {
179180 let inset = UIEdgeInsets ( top: - frame. minY, left: - frame. minX, bottom: - superview . bounds . height + frame. maxY, right: - superview . bounds . width + frame. maxX)
180181 super. scrollIndicatorInsets = inset + originScrollIndicatorInsets
181182 }
182-
183- stopScroll ( )
184-
183+
185184 columnRow. removeAll ( )
186185 currentInfo = ViewVisibleInfo ( )
187186 currentMatrix = makeMatrix ( . all( currentMatrix) )
187+ print ( " Matrix Reload = " , currentMatrix)
188188
189189 performWithoutDelegation {
190190 contentSize = currentMatrix. contentSize
@@ -196,7 +196,6 @@ open class GridView: UIScrollView {
196196 layoutToRemoveCells ( )
197197
198198 case . layout( let type) :
199- stopScroll ( )
200199
201200 currentMatrix = makeMatrix ( type)
202201
@@ -233,6 +232,41 @@ open class GridView: UIScrollView {
233232 layoutToRemoveCells ( )
234233 }
235234
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 ( )
236270 }
237271
238272 UIView . setAnimationsEnabled ( areAnimationsEnabled)
@@ -267,6 +301,10 @@ open class GridView: UIScrollView {
267301 }
268302 }
269303
304+ fileprivate func columnCountPerPage( ) -> Int {
305+ return dataSource? . numberOfColumnsPerPage ? ( in: self ) ?? 0
306+ }
307+
270308 fileprivate func rowCount( in column: Int ) -> Int {
271309 if let rowCount = columnRow [ column] {
272310 return rowCount
@@ -407,6 +445,16 @@ extension GridView {
407445 layoutIfNeeded ( )
408446 }
409447
448+ public func appendTime( ) {
449+ setNeedsLayout ( . appendVertical)
450+ layoutIfNeeded ( )
451+ }
452+
453+ public func appendChannel( ) {
454+ setNeedsLayout ( . appendHorizontal)
455+ layoutIfNeeded ( )
456+ }
457+
410458 public func invalidateContentSize( ) {
411459 setNeedsLayout ( . layout( . rotating( currentMatrix) ) )
412460 }
@@ -769,18 +817,14 @@ private extension GridView {
769817
770818 ( 0 ..< count) . forEach { column in
771819 if let widthForColumn = gridViewDelegate? . gridView ? ( self , widthForColumn: column) {
772- let horizontal = Horizontal ( x: size. width, width: widthForColumn)
773- columnHorizontals. append ( horizontal)
774820 size. width += widthForColumn
775821 }
776822
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
784828 }
785829 }
786830
@@ -796,6 +840,81 @@ private extension GridView {
796840 } else {
797841 return ViewMatrix ( horizontals: horizontals, verticals: columnRowVerticals, viewFrame: frame, contentHeight: size. height, superviewSize: superview? . bounds. size, scale: currentScale, inset: contentInset, isInfinitable: isInfinitable)
798842 }
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
799918 }
800919 }
801920}
0 commit comments