Skip to content

Commit

Permalink
fix: ios resize (#114)
Browse files Browse the repository at this point in the history
Co-authored-by: Vittorio Cellucci <[email protected]>
  • Loading branch information
vcellu and vcellu authored Nov 6, 2022
1 parent 1957a1c commit 6f853a1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
10 changes: 10 additions & 0 deletions ios/ColumnWidths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class ColumnWidths {
resetColumnWidths(widths: widths)
calculateDefaultColWidth(dataRows: dataRows, defaultWidth: defaultWidth, columnCount: columnCount, frame: frame)
}
cleanUpValues()
}

fileprivate func cleanUpValues() {
columnWidths = columnWidths.map{ (element) -> Double in
if element < DataCellView.minWidth {
return DataCellView.minWidth
}
return element
}
}

fileprivate func loadFromStorage(_ columnCount: Int) -> Bool {
Expand Down
7 changes: 5 additions & 2 deletions ios/ContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,13 @@ class ContainerView: UIView {
tableViewFactory.create()
firstColumnTable = tableViewFactory.firstColumnTableView
multiColumnTable = tableViewFactory.multiColumnTableView

firstColumnTable?.resizeCells()
multiColumnTable?.resizeCells()
self.testTruncation()

DispatchQueue.main.async {
self.firstColumnTable?.dataCollectionView?.signalVisibleRows()
self.testTruncation()
self.horizontalScrollView?.setContentOffset(CGPoint(x: 0, y: 0), animated: false)
}
} else {
guard let firstColumnTable = self.firstColumnTable else { return }
Expand Down
2 changes: 1 addition & 1 deletion ios/DataCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class DataCellView: UICollectionViewCell, ExpandedCellProtocol {
func updateSize(_ translation: CGPoint, forColumn index: Int) -> Bool {
let view = contentView.subviews[index]
let newWidth = view.frame.width + translation.x
if newWidth < DataCellView.minWidth {
if newWidth < DataCellView.minWidth && translation.x < 0 {
return false
}

Expand Down
10 changes: 3 additions & 7 deletions ios/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TableView: UIView {
var dymaniceLeadingAnchor = NSLayoutConstraint()
var columnWidths: ColumnWidths?
var grabbers = [() -> MultiColumnResizer?]()

var dataRange: CountableRange = 0..<1
func grow(by delta: Double) {
dynamicWidth.constant = self.frame.width + delta
}
Expand All @@ -33,7 +33,7 @@ class TableView: UIView {
guard let columnWidths = columnWidths else { return }
guard let dataCollectionView = dataCollectionView else { return }

let width = columnWidths.getTotalWidth(range: dataCollectionView.dataRange)
let width = columnWidths.getTotalWidth(range: dataRange)
setWidth(width)

if let headerView = headerView {
Expand All @@ -58,7 +58,6 @@ class TableView: UIView {
if let horizontalScrollView = horizontalScrolLView {
let totalWidth = columnWidths.getTotalWidth()
horizontalScrollView.contentSize = CGSize(width: totalWidth, height: 0)
horizontalScrollView.contentOffset.x = 0
}
}

Expand All @@ -81,11 +80,8 @@ class TableView: UIView {
}

if let lastGrabber = lastGrabber {
let width = columnWidths.getTotalWidth(range: 1..<columnWidths.count())

lastGrabber.centerConstraint.constant = width
lastGrabber.centerConstraint = lastGrabber.trailingAnchor.constraint(equalTo: self.trailingAnchor)
lastGrabber.layoutIfNeeded()

}

}
Expand Down
7 changes: 3 additions & 4 deletions ios/TableViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class TableViewFactory {
func createFirstColumn() {
let width = columnWidths.columnWidths[0]
firstColumnTableView.translatesAutoresizingMaskIntoConstraints = false

firstColumnTableView.dataRange = 0..<1
firstColumnTableView.dynamicWidth = firstColumnTableView.widthAnchor.constraint(equalToConstant: width)
firstColumnTableView.backgroundColor = .white
let leadingAnchor = containerView.freezeFirstColumn ? horizontalScrollView.frameLayoutGuide.leadingAnchor : horizontalScrollView.leadingAnchor
Expand Down Expand Up @@ -190,6 +190,7 @@ class TableViewFactory {
func createMultiColumnTable() {

let width = columnWidths.getTotalWidth(range: 1..<columnWidths.count())
multiColumnTableView.dataRange = 1..<columnWidths.count()
multiColumnTableView.translatesAutoresizingMaskIntoConstraints = false
multiColumnTableView.dynamicWidth = multiColumnTableView.widthAnchor.constraint(greaterThanOrEqualToConstant: width)
multiColumnTableView.dymaniceLeadingAnchor = multiColumnTableView.leadingAnchor.constraint(equalTo: horizontalScrollView.leadingAnchor,
Expand Down Expand Up @@ -278,9 +279,7 @@ class TableViewFactory {
resizer.containerView = containerView
grabbers.append({[weak resizer] in return resizer})
multiColumnTableView.addSubview(resizer)
let width = columnWidths.getTotalWidth(range: 1..<columnWidths.count())

resizer.centerConstraint = resizer.centerXAnchor.constraint(equalTo: multiColumnTableView.leadingAnchor, constant: width)
resizer.centerConstraint = resizer.centerXAnchor.constraint(equalTo: multiColumnTableView.trailingAnchor)
let constraints = [
resizer.topAnchor.constraint(equalTo: multiColumnTableView.topAnchor),
resizer.bottomAnchor.constraint(equalTo: multiColumnTableView.bottomAnchor),
Expand Down

0 comments on commit 6f853a1

Please sign in to comment.