@@ -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,19 +817,19 @@ 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)
820+ // let horizontal = Horizontal(x: size.width, width: widthForColumn)
821+ // columnHorizontals.append(horizontal)
774822 size. width += widthForColumn
775823 }
776824
777- if case . all = type {
825+ // if case .all = type {
778826 let columnVerticals = verticalsForRow ( in: column)
779827 columnRowVerticals. append ( columnVerticals)
780828
781829 if let last = columnVerticals. last, let vertical = last, size. height < vertical. maxY {
782830 size. height = vertical. maxY
783831 }
784- }
832+ // }
785833 }
786834
787835 let horizontals : [ Horizontal ] ?
@@ -796,6 +844,86 @@ private extension GridView {
796844 } else {
797845 return ViewMatrix ( horizontals: horizontals, verticals: columnRowVerticals, viewFrame: frame, contentHeight: size. height, superviewSize: superview? . bounds. size, scale: currentScale, inset: contentInset, isInfinitable: isInfinitable)
798846 }
847+
848+ case . appendVertical( let matrix) :
849+ var copyMatrix = matrix
850+ var size : CGSize = . zero
851+ if let arrayHorizontal = copyMatrix. horizontals,
852+ let lastItem = arrayHorizontal. last {
853+ size. width = lastItem. maxX
854+ }
855+
856+ let count = columnCount ( )
857+ // var size: CGSize = .zero
858+ var columnHorizontals : [ Horizontal ] = [ ]
859+ var columnRowVerticals : [ [ Vertical ? ] ] = [ ]
860+
861+ ( 0 ..< count) . forEach { column in
862+ if let widthForColumn = gridViewDelegate? . gridView ? ( self , widthForColumn: column) {
863+ // let horizontal = Horizontal(x: size.width, width: widthForColumn)
864+ // columnHorizontals.append(horizontal)
865+ size. width += widthForColumn
866+ }
867+
868+ let columnVerticals = verticalsForRow ( in: column)
869+ columnRowVerticals. append ( columnVerticals)
870+
871+ if let last = columnVerticals. last, let vertical = last, size. height < vertical. maxY {
872+ size. height = vertical. maxY
873+ }
874+ }
875+
876+ let horizontals : [ Horizontal ] ?
877+ if columnHorizontals. count > 0 && columnHorizontals. count == count {
878+ horizontals = columnHorizontals
879+ } else {
880+ horizontals = nil
881+ }
882+
883+ copyMatrix. appendVerticals ( horizontals: horizontals, verticals: columnRowVerticals, viewFrame: frame, contentHeight: size. height, superviewSize: superview? . bounds. size, scale: currentScale)
884+
885+ return copyMatrix
886+
887+ case . appendHorizontal( let matrix) :
888+
889+ var copyMatrix = matrix
890+ var size : CGSize = . zero
891+ if let arrayHorizontal = copyMatrix. horizontals,
892+ let lastItem = arrayHorizontal. last {
893+ size. width = lastItem. maxX
894+ }
895+
896+ let count = columnCount ( )
897+ var columnHorizontals : [ Horizontal ] = [ ]
898+ var columnRowVerticals : [ [ Vertical ? ] ] = [ ]
899+
900+ ( 0 ..< count) . forEach { column in
901+ if let widthForColumn = gridViewDelegate? . gridView ? ( self , widthForColumn: column) {
902+ let horizontal = Horizontal ( x: size. width, width: widthForColumn)
903+ columnHorizontals. append ( horizontal)
904+ size. width += widthForColumn
905+ }
906+
907+ // if case .all = type {
908+ let columnVerticals = verticalsForRow ( in: column)
909+ columnRowVerticals. append ( columnVerticals)
910+
911+ if let last = columnVerticals. last, let vertical = last, size. height < vertical. maxY {
912+ size. height = vertical. maxY
913+ }
914+ // }
915+ }
916+
917+ let horizontals : [ Horizontal ] ?
918+ if columnHorizontals. count > 0 && columnHorizontals. count == count {
919+ horizontals = columnHorizontals
920+ } else {
921+ horizontals = nil
922+ }
923+
924+ copyMatrix. appendHorizontals ( horizontals: horizontals, verticals: columnRowVerticals, viewFrame: frame, contentHeight: size. height, superviewSize: superview? . bounds. size, scale: currentScale)
925+
926+ return copyMatrix
799927 }
800928 }
801929}
0 commit comments