Skip to content

Commit

Permalink
fix: iOS bugs (#112)
Browse files Browse the repository at this point in the history
* fix: various bug fixes for ios

* fix: text wrapping

Co-authored-by: Vittorio Cellucci <vel@qlik.com>
  • Loading branch information
vcellu and vcellu committed Nov 6, 2022
1 parent d12f2e5 commit ce0ef62
Show file tree
Hide file tree
Showing 30 changed files with 697 additions and 428 deletions.
1 change: 1 addition & 0 deletions ios/CellContentStyle.swift
Expand Up @@ -13,4 +13,5 @@ struct CellContentStyle: Decodable {
var fontFamily: String?
var fontSize: Int?
var rowHeight: Int?
var wrap: Bool?
}
66 changes: 37 additions & 29 deletions ios/ColumnResizerView.swift
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
class ColumnResizerView : UIView {
class ColumnResizerView: UIView {
var pressed = false
var columnWidths: ColumnWidths
var borderColor = UIColor.gray
Expand All @@ -15,40 +15,42 @@ class ColumnResizerView : UIView {
var linePath = UIBezierPath()
weak var tableView: TableView?
weak var adjacentTable: TableView?
weak var button: UIView?
weak var button: ResizerButtonView?
weak var horizontalScrollView: UIScrollView?

weak var containerView: ContainerView?

init( _ columnWidths: ColumnWidths, index: Int, bindTo bindedTableView: TableView) {
self.columnWidths = columnWidths
self.tableView = bindedTableView
self.index = index
super.init(frame: CGRect.zero)
self.backgroundColor = .white.withAlphaComponent(0.0)
self.isUserInteractionEnabled = true
self.backgroundColor = UIColor.white.withAlphaComponent(0)
createButton()
}

fileprivate func createButton() {
let button = UIView()//UIView(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: 40, height: 40)))
let button = ResizerButtonView()
button.translatesAutoresizingMaskIntoConstraints = false
addSubview(button)
button.heightConstraint = button.heightAnchor.constraint(equalToConstant: TableTheme.DefaultCellHeight)
let constraints = [
button.topAnchor.constraint(equalTo: self.topAnchor),
button.heightAnchor.constraint(equalToConstant: TableTheme.DefaultCellHeight),
button.widthAnchor.constraint(equalToConstant: TableTheme.DefaultResizerWidth),
button.leadingAnchor.constraint(equalTo: self.leadingAnchor)
button.leadingAnchor.constraint(equalTo: self.leadingAnchor),
button.heightConstraint
]
NSLayoutConstraint.activate(constraints)
self.addConstraints(constraints)

let panGesture = UIPanGestureRecognizer(target: self, action: #selector(self.handleGesture(_:)))
panGesture.minimumNumberOfTouches = 1
panGesture.maximumNumberOfTouches = 1
button.isUserInteractionEnabled = true
button.addGestureRecognizer(panGesture)
self.button = button
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
if let touch = touches.first {
Expand Down Expand Up @@ -79,7 +81,7 @@ class ColumnResizerView : UIView {
}
return view
}

@objc func handleGesture(_ sender: UIPanGestureRecognizer) {
switch sender.state {
case .began:
Expand All @@ -105,23 +107,25 @@ class ColumnResizerView : UIView {
break
}
}

func didPan(_ translation: CGPoint) {
guard let tableView = self.tableView else { return }
guard let data = tableView.dataCollectionView else { return }
columnWidths.resize(index: index, by: translation)
self.centerConstraint.constant = self.centerConstraint.constant + translation.x

tableView.grow(by: translation.x)
if let adjacentTable = self.adjacentTable {
adjacentTable.dymaniceLeadingAnchor.constant = columnWidths.columnWidths[0]
adjacentTable.layoutIfNeeded()
if data.updateSize(translation, withColumn: index) {
columnWidths.resize(index: index, by: translation)
self.centerConstraint.constant = self.centerConstraint.constant + translation.x

tableView.grow(by: translation.x)
if let adjacentTable = self.adjacentTable {
adjacentTable.dymaniceLeadingAnchor.constant = columnWidths.columnWidths[0]
adjacentTable.layoutIfNeeded()
}
data.childCollectionView?.collectionViewLayout.invalidateLayout()
containerView?.testTruncation()
tableView.layoutIfNeeded()
}
tableView.layoutIfNeeded()
let _ = data.updateSize(translation, withColumn: index)
data.childCollectionView?.collectionViewLayout.invalidateLayout()
}

func didEndPand() {
columnWidths.saveToStorage()
if let scrollView = self.horizontalScrollView {
Expand All @@ -131,11 +135,11 @@ class ColumnResizerView : UIView {
}
}
}

func setPosition(_ x: Double) {
self.centerConstraint.constant = x
}

override func draw(_ rect: CGRect) {
let x = rect.origin.x + rect.width / 2
linePath.removeAllPoints()
Expand All @@ -147,11 +151,15 @@ class ColumnResizerView : UIView {
color.setStroke()
linePath.stroke()
}


func setHeight(_ newVal: Double) {
guard let button = button else { return }
button.heightConstraint.constant = newVal
button.layoutIfNeeded()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}




}
3 changes: 2 additions & 1 deletion ios/ConstraintCellProtocol.swift
Expand Up @@ -8,5 +8,6 @@
import Foundation
protocol ConstraintCellProtocol {
func getDynamicWidth() -> NSLayoutConstraint
func setDynamicWidth(_ newVal: NSLayoutConstraint)
func setDynamicWidth(_ newVal: NSLayoutConstraint, value: Double)
func getLineCount(columnWidth: Double) -> Int
}

0 comments on commit ce0ef62

Please sign in to comment.