Skip to content

Commit

Permalink
fix: initial visible rows
Browse files Browse the repository at this point in the history
  • Loading branch information
vcellu committed Sep 9, 2022
1 parent 2fc66b3 commit fe352e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
51 changes: 22 additions & 29 deletions ios/ContainerView.swift
Expand Up @@ -36,7 +36,7 @@ class ContainerView: UIView {
@objc var freezeFirstColumn: Bool = false
@objc var isDataView: Bool = false
@objc var isPercent: Bool = false


override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -85,12 +85,6 @@ class ContainerView: UIView {
do {
let json = try JSONSerialization.data(withJSONObject: size)
dataSize = try JSONDecoder().decode(DataSize.self, from: json)
guard let collectionView = collectionView else {
return
}
DispatchQueue.main.async {
collectionView.signalVisibleRows()
}
} catch {
print(error)
}
Expand Down Expand Up @@ -192,17 +186,25 @@ class ContainerView: UIView {
guard let dataRows = dataRows else {
return
}

if let dataColumns = dataColumns {
columnWidths.loadDefaultWidths(bounds, columnCount: dataColumns.count, dataRows: dataRows)
}

createHScrollView()
createHeaderView()
createTotalsView()
createDataCollectionView()
createGrabbers()
createTotalCellsView()
createTotalsView()

guard let collectionView = collectionView else {
return
}

DispatchQueue.main.async {
collectionView.initialSignalVisibleRows()
}
}
}

Expand All @@ -229,9 +231,6 @@ class ContainerView: UIView {
collectionView.resizeCells(withFrame: getCollectionViewFrame())
repositionGrabbers()
repositionTotalCellsView()
DispatchQueue.main.async {
collectionView.signalVisibleRows()
}
}

fileprivate func createHScrollView() {
Expand Down Expand Up @@ -290,7 +289,7 @@ class ContainerView: UIView {
guard let dataColumns = dataColumns else {
return
}

guard let cellStyle = cellStyle else {
return
}
Expand Down Expand Up @@ -350,7 +349,7 @@ class ContainerView: UIView {
guard let headerView = headerView else {
return CGRect.zero
}

let headerHeight = tableTheme?.headerHeight ?? 54
var y = headerHeight
let width = Int(headerView.frame.width)
Expand All @@ -359,23 +358,14 @@ class ContainerView: UIView {
totalHeight -= CGFloat(headerHeight)
if let totals = totals {
if totals.position != "bottom" {
y += headerHeight
y += headerHeight
}
}
}
return CGRect(x: 0, y: y, width: width, height: Int(totalHeight))
}

fileprivate func createTotalCellsView() {
guard let collectionView = collectionView else {
return
}

guard let dataSize = dataSize else {
return
}


if(totalCellsView == nil) {
guard let height = tableTheme?.headerHeight else { return }
let frame = CGRect(x: 0, y: self.frame.height - CGFloat(height), width: self.frame.width, height: CGFloat(height))
Expand All @@ -385,12 +375,15 @@ class ContainerView: UIView {
view.createTextView()
addSubview(view)
self.totalCellsView = view
collectionView.totalCellsView = view
view.totalRows = dataSize.qcy ?? 0
DispatchQueue.main.async {
collectionView.signalVisibleRows()
collectionView?.totalCellsView = view
if let dataSize = dataSize {
view.totalRows = dataSize.qcy ?? 0
if let collectionView = collectionView {
DispatchQueue.main.async {
collectionView.signalVisibleRows()
}
}
}

}
}

Expand Down
21 changes: 20 additions & 1 deletion ios/DataCollectionView.swift
Expand Up @@ -229,7 +229,7 @@ class DataCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDe
}
}
}

let arrayOfVisibleItems = childCollectionView.indexPathsForVisibleItems.sorted()
let firstItem = arrayOfVisibleItems.first;
let lastItem = arrayOfVisibleItems.last;
Expand All @@ -239,6 +239,25 @@ class DataCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDe
}
}


public func initialSignalVisibleRows() {
guard let childCollectionView = childCollectionView else {
return
}

guard let totalCellsView = totalCellsView else {
return
}

let arrayOfVisibleItems = childCollectionView.indexPathsForVisibleItems.sorted()
let firstItem = arrayOfVisibleItems.first;
let lastItem = arrayOfVisibleItems.last;

if let firstItem = firstItem, let lastItem = lastItem {
totalCellsView.updateTotals(first: firstItem, last: lastItem)
}
}

public func resizeCells (withFrame frame: CGRect) {
guard let childCollectionView = childCollectionView else {
return
Expand Down

0 comments on commit fe352e7

Please sign in to comment.