Skip to content

Commit

Permalink
fix(MD-3721): respect font sizing (#118)
Browse files Browse the repository at this point in the history
* fix(MD-3721): respect font sizing

* fix: bring back totals borders

* fix: color parsing

* fix: ios url's

* fix: padding on charts

Co-authored-by: Vittorio Cellucci <vel@qlik.com>
  • Loading branch information
2 people authored and enell committed Feb 9, 2023
1 parent e4015a5 commit 9573960
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 169 deletions.
17 changes: 17 additions & 0 deletions ios/CellContentStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,20 @@ struct CellContentStyle: Decodable {
var rowHeight: Int?
var wrap: Bool?
}


class CellStyle {
var cellContentStyle: CellContentStyle?
var lineHeight = 0.0
var font: UIFont?

init(cellContentStyle: CellContentStyle?) {
self.cellContentStyle = cellContentStyle
if let cellContentStyle = self.cellContentStyle {
let fontSize = cellContentStyle.fontSize ?? 14
let sizedFont = UIFont.systemFont(ofSize: CGFloat(fontSize))
lineHeight = TableTheme.getLineHeight(sizedFont: sizedFont)
font = sizedFont
}
}
}
7 changes: 5 additions & 2 deletions ios/ColorParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class ColorParser {

static func fromCSS(cssString: String) -> UIColor {
if cssString == "none" {
return UIColor.clear
return UIColor.white
}
if cssString.isEmpty {
return .black
}
let hex = cssString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
if cssString.hasPrefix("#") {
Expand Down Expand Up @@ -75,6 +78,6 @@ class ColorParser {
}

}
return UIColor.black
return UIColor.clear
}
}
4 changes: 2 additions & 2 deletions ios/ColumnResizerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ColumnResizerView: UIView {
var headerView: HeaderView?
var totalsView: TotalsView?
var columnWidths: ColumnWidths
var borderColor = UIColor.gray
var borderColor = TableTheme.BorderColor
var centerConstraint = NSLayoutConstraint()
var index = 0
var linePath = UIBezierPath()
Expand All @@ -35,7 +35,7 @@ class ColumnResizerView: UIView {
let button = ResizerButtonView()
button.translatesAutoresizingMaskIntoConstraints = false
addSubview(button)
button.heightConstraint = button.heightAnchor.constraint(equalToConstant: TableTheme.DefaultCellHeight)
button.heightConstraint = button.heightAnchor.constraint(equalToConstant: TableTheme.CellContentHeight)
let constraints = [
button.topAnchor.constraint(equalTo: self.topAnchor),
button.widthAnchor.constraint(equalToConstant: TableTheme.DefaultResizerWidth),
Expand Down
16 changes: 10 additions & 6 deletions ios/ColumnWidths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class ColumnWidths {
return columnWidths.count
}

func loadDefaultWidths(_ frame: CGRect, columnCount: Int, dataRows: [DataRow]) {
func loadDefaultWidths(_ frame: CGRect, columnCount: Int, dataRows: [DataRow], dataCols: [DataColumn]) {
if !loadFromStorage(columnCount) {
let defaultWidth = frame.width / Double(columnCount)
let widths = [Double](repeating: defaultWidth, count: columnCount)
resetColumnWidths(widths: widths)
calculateDefaultColWidth(dataRows: dataRows, defaultWidth: defaultWidth, columnCount: columnCount, frame: frame)
calculateDefaultColWidth(dataRows: dataRows, dataCols: dataCols, defaultWidth: defaultWidth, columnCount: columnCount, frame: frame)
}
cleanUpValues()
}
Expand Down Expand Up @@ -60,17 +60,17 @@ class ColumnWidths {

fileprivate func getStorageKey() -> String {
guard let key = key else {return ""}
let prefix = UIDevice.current.orientation.isLandscape ? "landscape.3." : "portrait.3."
let prefix = UIDevice.current.orientation.isLandscape ? "landscape.4." : "portrait.4."
let storageKey = prefix + key
return storageKey
}

func calculateDefaultColWidth(dataRows: [DataRow], defaultWidth: Double, columnCount: Int, frame: CGRect) {
func calculateDefaultColWidth(dataRows: [DataRow], dataCols: [DataColumn], defaultWidth: Double, columnCount: Int, frame: CGRect) {
// get max width
var widths = [Double](repeating: defaultWidth, count: columnCount)
var totalWidth = 0.0
columnWidths.enumerated().forEach { (index, _) in
let averageWidth = getAverageWidth(dataRows: dataRows, index: index)
let averageWidth = getAverageWidth(dataRows: dataRows, dataCols: dataCols, index: index)
widths[index] = averageWidth
totalWidth += averageWidth
}
Expand All @@ -83,10 +83,14 @@ class ColumnWidths {

}

fileprivate func getAverageWidth(dataRows: [DataRow], index: Int) -> Double {
fileprivate func getAverageWidth(dataRows: [DataRow], dataCols: [DataColumn], index: Int) -> Double {
if dataRows.count == 0 {
return DataCellView.minWidth
}
let dataCol = dataCols[index]
if dataCol.representation?.type != "text" {
return DataCellView.minWidth * 1.5
}
let totalCount = dataRows.reduce(0) { partialResult, row in
return partialResult + row.cells[index].qText!.count
}
Expand Down
29 changes: 14 additions & 15 deletions ios/ContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ContainerView: UIView {
let selectionsEngine = SelectionsEngine()
let hScrollViewDelegate = HorizontalScrollViewDelegate()
var needsGrabbers = true
var cellStyle: CellContentStyle?
var headerStyle: HeaderContentStyle?
var cellStyle: CellStyle?
var headerStyle: HeaderStyle?
var defaultCalculated = false
var menuTranslations: MenuTranslations?
var horizontalScrollView: UIScrollView?
Expand Down Expand Up @@ -160,7 +160,7 @@ class ContainerView: UIView {
do {
let json = try JSONSerialization.data(withJSONObject: cellContentStyle)
let decodedCellStyle = try JSONDecoder().decode(CellContentStyle.self, from: json)
cellStyle = decodedCellStyle
cellStyle = CellStyle(cellContentStyle: decodedCellStyle)
} catch {
print(error)
}
Expand All @@ -172,7 +172,7 @@ class ContainerView: UIView {
do {
let json = try JSONSerialization.data(withJSONObject: headerContentStyle)
let decodedHeaderStyle = try JSONDecoder().decode(HeaderContentStyle.self, from: json)
headerStyle = decodedHeaderStyle
headerStyle = HeaderStyle(headerContentSyle: decodedHeaderStyle)
} catch {
print(error)
}
Expand Down Expand Up @@ -201,7 +201,7 @@ class ContainerView: UIView {
didSet {
guard let dataColumns = dataColumns else {return}
guard let dataRows = dataRows else {return}
columnWidths.loadDefaultWidths(bounds, columnCount: dataColumns.count, dataRows: dataRows)
columnWidths.loadDefaultWidths(bounds, columnCount: dataColumns.count, dataRows: dataRows, dataCols: dataColumns)

if !created {
created = true
Expand All @@ -218,8 +218,6 @@ class ContainerView: UIView {
self.firstColumnTable?.dataCollectionView?.signalVisibleRows()
self.horizontalScrollView?.setContentOffset(CGPoint(x: 0, y: 0), animated: false)
self.testTruncation()
// self.firstColumnTable?.resizeCells()
// self.multiColumnTable?.resizeCells()
}
} else {
guard let firstColumnTable = self.firstColumnTable else { return }
Expand All @@ -237,8 +235,8 @@ class ContainerView: UIView {
}

func testTruncation() {
let headerWrap = headerStyle?.wrap ?? true
let cellWrap = cellStyle?.wrap ?? true
let headerWrap = headerStyle?.headerContentStyle?.wrap ?? true
let cellWrap = cellStyle?.cellContentStyle?.wrap ?? true
if headerWrap {
testHeaders()
}
Expand All @@ -256,9 +254,9 @@ class ContainerView: UIView {

if headerLineCount != maxHeaderLineCount {
maxHeaderLineCount = headerLineCount
let height = Double(maxHeaderLineCount - 1) * TableTheme.HeaderLineHeight + TableTheme.DefaultCellHeight
firstHeader.dynamicHeightAnchor.constant = height
multiHeader.dynamicHeightAnchor.constant = height
let height = Double(maxHeaderLineCount) * (headerStyle?.lineHeight ?? 1.0)
firstHeader.dynamicHeightAnchor.constant = height + (PaddedLabel.PaddingSize * 2.0)
multiHeader.dynamicHeightAnchor.constant = height + (PaddedLabel.PaddingSize * 2.0)
firstColumnTable?.updateGrabbers(height)
multiColumnTable?.updateGrabbers(height)
firstHeader.layoutIfNeeded()
Expand All @@ -274,11 +272,12 @@ class ContainerView: UIView {
lineCount = max(firstTotal.getMaxLineCount(), lineCount)
lineCount = max(multiTotal.getMaxLineCount(), lineCount)

// uses cellcontent style for style, but header.wrap for checking wrap
if lineCount != maxTotalsLineCount {
maxTotalsLineCount = lineCount
let height = Double(maxTotalsLineCount - 1) * TableTheme.HeaderLineHeight + TableTheme.DefaultCellHeight
firstTotal.dynamicHeight.constant = height
multiTotal.dynamicHeight.constant = height
let height = Double(maxHeaderLineCount) * (cellStyle?.lineHeight ?? 1.0)
firstTotal.dynamicHeight.constant = height + (PaddedLabel.PaddingSize * 2.0)
multiTotal.dynamicHeight.constant = height + (PaddedLabel.PaddingSize * 2.0)
firstTotal.layoutIfNeeded()
multiTotal.layoutIfNeeded()
}
Expand Down

0 comments on commit 9573960

Please sign in to comment.