diff --git a/ios/ContainerView.swift b/ios/ContainerView.swift index d081ad87..1cc829d4 100644 --- a/ios/ContainerView.swift +++ b/ios/ContainerView.swift @@ -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) @@ -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) } @@ -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() + } } } @@ -229,9 +231,6 @@ class ContainerView: UIView { collectionView.resizeCells(withFrame: getCollectionViewFrame()) repositionGrabbers() repositionTotalCellsView() - DispatchQueue.main.async { - collectionView.signalVisibleRows() - } } fileprivate func createHScrollView() { @@ -290,7 +289,7 @@ class ContainerView: UIView { guard let dataColumns = dataColumns else { return } - + guard let cellStyle = cellStyle else { return } @@ -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) @@ -359,7 +358,7 @@ class ContainerView: UIView { totalHeight -= CGFloat(headerHeight) if let totals = totals { if totals.position != "bottom" { - y += headerHeight + y += headerHeight } } } @@ -367,15 +366,6 @@ class ContainerView: UIView { } 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)) @@ -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() + } + } } - } } diff --git a/ios/DataCollectionView.swift b/ios/DataCollectionView.swift index 0874ea73..7bd88f11 100644 --- a/ios/DataCollectionView.swift +++ b/ios/DataCollectionView.swift @@ -229,7 +229,7 @@ class DataCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDe } } } - + let arrayOfVisibleItems = childCollectionView.indexPathsForVisibleItems.sorted() let firstItem = arrayOfVisibleItems.first; let lastItem = arrayOfVisibleItems.last; @@ -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