Skip to content

Commit

Permalink
fix: selection band (#128)
Browse files Browse the repository at this point in the history
* fix: resizing selection band

* fix: resize selection band

Co-authored-by: Vittorio Cellucci <vel@qlik.com>
  • Loading branch information
vcellu and vcellu committed Nov 11, 2022
1 parent 62af452 commit 636c0b7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 14 deletions.
16 changes: 11 additions & 5 deletions ios/ContainerView.swift
Expand Up @@ -216,7 +216,7 @@ class ContainerView: UIView {
setNeedsLayout()
DispatchQueue.main.async {
self.horizontalScrollView?.setContentOffset(CGPoint(x: 0, y: 0), animated: false)
self.firstColumnTable?.dataCollectionView?.postSignalVisibleRows()
self.firstColumnTable?.dataCollectionView?.postSignalVisibleRows(scrollsToTop: true)
self.testTruncation()
}
} else {
Expand All @@ -228,7 +228,7 @@ class ContainerView: UIView {
DispatchQueue.main.async {
if let horizontalScrollView = self.horizontalScrollView {
horizontalScrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: false)
self.firstColumnTable?.dataCollectionView?.postSignalVisibleRows()
self.firstColumnTable?.dataCollectionView?.postSignalVisibleRows(scrollsToTop: true)
}
}
}
Expand Down Expand Up @@ -263,6 +263,9 @@ class ContainerView: UIView {
firstHeader.layoutIfNeeded()
multiHeader.layoutIfNeeded()
layoutIfNeeded()
DispatchQueue.main.async {
self.firstColumnTable?.dataCollectionView?.postSignalVisibleRows(scrollsToTop: false)
}
}
testTotals()
}
Expand All @@ -283,6 +286,9 @@ class ContainerView: UIView {
firstTotal.layoutIfNeeded()
multiTotal.layoutIfNeeded()
layoutIfNeeded()
DispatchQueue.main.async {
self.firstColumnTable?.dataCollectionView?.postSignalVisibleRows(scrollsToTop: false)
}
}
}

Expand All @@ -296,6 +302,9 @@ class ContainerView: UIView {
maxCollectionViewsLineCount = lineCount
first.setMaxLineCount(maxCollectionViewsLineCount)
multi.setMaxLineCount(maxCollectionViewsLineCount)
DispatchQueue.main.async {
self.firstColumnTable?.dataCollectionView?.postSignalVisibleRows(scrollsToTop: false)
}
layoutIfNeeded()
}
}
Expand All @@ -308,12 +317,9 @@ class ContainerView: UIView {
func updateVScrollPos() {
let totalWidth = columnWidths.getTotalWidth()
let rawX = firstColumnTable?.horizontalScrolLView?.contentOffset.x ?? 0.0
// let scroll
let right = max(abs(self.frame.width - totalWidth) - rawX, 0)
multiColumnTable?.dataCollectionView?.childCollectionView?.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: right)
multiColumnTable?.dataCollectionView?.childCollectionView?.showsVerticalScrollIndicator = true
}



}
8 changes: 6 additions & 2 deletions ios/DataCellView.swift
Expand Up @@ -125,6 +125,8 @@ class DataCellView: UICollectionViewCell, ExpandedCellProtocol {
} else {
imageView.backgroundColor = .clear
}
imageView.delegate = self
imageView.menuTranslations = menuTranslations
imageView.setData(data: element, representedAs: representation, index: index)
imageView.setNeedsDisplay()
}
Expand All @@ -143,15 +145,17 @@ class DataCellView: UICollectionViewCell, ExpandedCellProtocol {
label.menuTranslations = self.menuTranslations
label.delegate = self
label.font = cellStyle?.font ?? UIFont.systemFont(ofSize: 14)
label.numberOfLines = self.numberOfLines

if representation.type == "indicator", let indicator = element.indicator, let uniChar = DataCellView.iconMap[indicator.icon ?? "m"] {
label.textColor = getForegroundColor(col: col, element: element, withStyle: styleInfo[index])
label.setAttributedText(element.qText ?? "", withIcon: uniChar, element: element)
} else if representation.type == "url" {
let index = col.stylingInfo?.firstIndex(of: "url")
label.setupUrl(col, cell: element, index: index)
} else {
label.text = element.qText
label.textColor = getForgroundColor(col: col, element: element, withStyle: styleInfo[index])
label.textColor = getForegroundColor(col: col, element: element, withStyle: styleInfo[index])
}
}
}
Expand Down Expand Up @@ -188,7 +192,7 @@ class DataCellView: UICollectionViewCell, ExpandedCellProtocol {
return .clear
}

fileprivate func getForgroundColor(col: DataColumn, element: DataCell, withStyle styleInfo: StylingInfo) -> UIColor {
fileprivate func getForegroundColor(col: DataColumn, element: DataCell, withStyle styleInfo: StylingInfo) -> UIColor {
if isDataView {
return cellColor!
}
Expand Down
8 changes: 5 additions & 3 deletions ios/DataCollectionView.swift
Expand Up @@ -220,12 +220,14 @@ class DataCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDe
}
}

func postSignalVisibleRows() {
func postSignalVisibleRows(scrollsToTop: Bool) {
DispatchQueue.main.async {
self.childCollectionView?.performBatchUpdates({
self.childCollectionView?.reloadData()
self.signalVisibleRows()
self.scrollToTop()
if(scrollsToTop) {
self.scrollToTop()
}
})
}
}
Expand All @@ -241,7 +243,7 @@ class DataCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDe
cell.backgroundColor = isDataView ? indexPath.row % 2 == 0 ? .white : UIColor(red: 0.97, green: 0.97, blue: 0.97, alpha: 1.0) : .white
cell.cellColor = cellColor
cell.onExpandedCellEvent = onExpandedCell
cell.numberOfLines = cellStyle?.cellContentStyle?.rowHeight ?? 1
cell.numberOfLines = maxRowLineCount
if let data = dataRows, let columnWidths = columnWidths, let dataColumns = dataColumns {
let dataRow = data[indexPath.row]
cell.selectionsEngine = self.selectionsEngine
Expand Down
48 changes: 45 additions & 3 deletions ios/ImageCell.swift
Expand Up @@ -10,19 +10,27 @@ import Foundation
class ImageCell: UIView, ConstraintCellProtocol {

var dynamicWidth = NSLayoutConstraint()
let contextMenu = ContextMenu()
weak var imageView: UIImageView?
weak var delegate: ExpandedCellProtocol?
var imagedata: Data?
var representation: Representation?
var menuTranslations: MenuTranslations?
var cell: DataCell?

init() {
super.init(frame: CGRect.zero)

showMenus()
}

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

override var canBecomeFirstResponder: Bool {
return true
}

func getDynamicWidth() -> NSLayoutConstraint {
return dynamicWidth
}
Expand All @@ -35,8 +43,42 @@ class ImageCell: UIView, ConstraintCellProtocol {
return 1
}


func showMenus() {
isUserInteractionEnabled = true
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(showMenu))
self.addGestureRecognizer(longPress)
}

@objc func showMenu(_ sender: UILongPressGestureRecognizer) {
self.becomeFirstResponder()
contextMenu.menuTranslations = self.menuTranslations
contextMenu.cell = self.cell
contextMenu.showMenu(sender, view: self)
}

@objc func handleCopy(_ controller: UIMenuController) {

let format = UIGraphicsImageRendererFormat()
format.scale = UIScreen.main.scale
if let img = imageView?.image {
let board = UIPasteboard.general
board.image = img
}
controller.setMenuVisible(false, animated: true)
self.resignFirstResponder()
}

@objc func handleExpand(_ controller: UIMenuController) {
guard let cell = self.cell else { return }
guard let delegate = self.delegate else { return }
delegate.onExpandedCell(cell: cell)
self.resignFirstResponder()
}

func setData(data: DataCell, representedAs rep: Representation, index: Int?) {
self.representation = rep
self.cell = data
guard let qAttrExps = data.qAttrExps else {return}
guard let qValues = qAttrExps.qValues else {return}
guard let attrIndex = index else { return }
Expand All @@ -45,8 +87,8 @@ class ImageCell: UIView, ConstraintCellProtocol {
guard let url = URL(string: urlString) else {return}
DispatchQueue.global(qos: .background).async {
do {
let data = try Data.init(contentsOf: url)
self.imagedata = data
let imageData = try Data.init(contentsOf: url)
self.imagedata = imageData
DispatchQueue.main.async {
self.setNeedsLayout()
}
Expand Down
1 change: 0 additions & 1 deletion ios/PaddedLabel.swift
Expand Up @@ -330,7 +330,6 @@ class PaddedLabel: UILabel, SelectionsListener, ConstraintCellProtocol {
}

func getLineCount(_ update: Bool, columnWidth: Double) -> Int {
layoutIfNeeded()
if let font = self.font, let myText = text {
let width = columnWidth - (PaddedLabel.PaddingSize * 2)
let rect = CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)
Expand Down

0 comments on commit 636c0b7

Please sign in to comment.