Skip to content

Commit

Permalink
Configurable collapsed GridView row/column height/width
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed May 29, 2023
1 parent 1f8583c commit 4569832
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 8 additions & 6 deletions Proton/Sources/Swift/Grid/Core/Grid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ class GridRowDimension {
var currentHeight: CGFloat
var isCollapsed: Bool
let rowConfiguration: GridRowConfiguration
let collapsedHeight: CGFloat

var calculatedHeight: CGFloat {
guard !isCollapsed else { return 2 }
guard !isCollapsed else { return collapsedHeight }
return currentHeight
}

init(rowConfiguration: GridRowConfiguration, isCollapsed: Bool = false) {
init(rowConfiguration: GridRowConfiguration, isCollapsed: Bool = false, collapsedHeight: CGFloat) {
self.rowConfiguration = rowConfiguration
currentHeight = rowConfiguration.initialHeight
self.isCollapsed = isCollapsed
self.collapsedHeight = collapsedHeight
}
}

Expand Down Expand Up @@ -72,11 +74,11 @@ class Grid {
self.config = config

for column in config.columnsConfiguration {
self.columnWidths.append(GridColumnDimension(width: column.width))
self.columnWidths.append(GridColumnDimension(width: column.width, collapsedWidth: config.collapsedColumnWidth))
}

for row in config.rowsConfiguration {
self.rowHeights.append(GridRowDimension(rowConfiguration: row))
self.rowHeights.append(GridRowDimension(rowConfiguration: row, collapsedHeight: config.collapsedRowHeight))
}
self.cellStore = GridCellStore(cells: cells)
}
Expand Down Expand Up @@ -242,7 +244,7 @@ class Grid {
if sanitizedIndex < numberOfRows {
cellStore.moveCellRowIndex(from: sanitizedIndex, by: 1)
}
rowHeights.insert(GridRowDimension(rowConfiguration: config), at: sanitizedIndex)
rowHeights.insert(GridRowDimension(rowConfiguration: config, collapsedHeight: self.config.collapsedRowHeight), at: sanitizedIndex)
var cells = [GridCell]()
for c in 0..<numberOfColumns {
let cell = GridCell(
Expand Down Expand Up @@ -278,7 +280,7 @@ class Grid {
if sanitizedIndex < numberOfColumns {
cellStore.moveCellColumnIndex(from: sanitizedIndex, by: 1)
}
columnWidths.insert(GridColumnDimension(width: config.width), at: sanitizedIndex)
columnWidths.insert(GridColumnDimension(width: config.width, collapsedWidth: self.config.collapsedColumnWidth), at: sanitizedIndex)

var cells = [GridCell]()
for r in 0..<numberOfRows {
Expand Down
16 changes: 13 additions & 3 deletions Proton/Sources/Swift/Grid/Core/GridConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ import UIKit
class GridColumnDimension {
var isCollapsed: Bool
var width: GridColumnWidth
let collapsedWidth: CGFloat

init(width: GridColumnWidth, isCollapsed: Bool = false) {
init(width: GridColumnWidth, isCollapsed: Bool = false, collapsedWidth: CGFloat) {
self.isCollapsed = isCollapsed
self.width = width
self.collapsedWidth = collapsedWidth
}

func value(basedOn total: CGFloat) -> CGFloat {
guard !isCollapsed else { return 2 }
guard !isCollapsed else { return collapsedWidth }
return width.value(basedOn: total)
}
}
Expand Down Expand Up @@ -87,14 +89,22 @@ public struct GridConfiguration {
public let columnsConfiguration: [GridColumnConfiguration]
public let rowsConfiguration: [GridRowConfiguration]

public let collapsedColumnWidth: CGFloat
public let collapsedRowHeight: CGFloat

public init(columnsConfiguration: [GridColumnConfiguration],
rowsConfiguration: [GridRowConfiguration],
style: GridStyle = .default,
boundsLimitShadowColors: GradientColors = GradientColors(primary: .black, secondary: .white)) {
boundsLimitShadowColors: GradientColors = GradientColors(primary: .black, secondary: .white),
collapsedColumnWidth: CGFloat = 2,
collapsedRowHeight: CGFloat = 2
) {
self.columnsConfiguration = columnsConfiguration
self.rowsConfiguration = rowsConfiguration
self.style = style
self.boundsLimitShadowColors = boundsLimitShadowColors
self.collapsedColumnWidth = collapsedColumnWidth
self.collapsedRowHeight = collapsedRowHeight
}

public var numberOfColumns: Int {
Expand Down

0 comments on commit 4569832

Please sign in to comment.