Skip to content

Commit

Permalink
Revert "TableViewHeaderFooterView should not override any font or col…
Browse files Browse the repository at this point in the history
…or provided as part of the AttributedString (#1929)" (#1945)

This reverts commit 559db71.
  • Loading branch information
joannaquu authored Dec 20, 2023
1 parent 2170a5b commit 22f70c5
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions ios/FluentUI/Table View/TableViewHeaderFooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
/// - accessoryButtonTitle: Optional accessory button title string.
/// - leadingView: An optional custom view that appears near the leading edge of the view.
@objc open func setup(style: Style, title: String, accessoryButtonTitle: String = "", leadingView: UIView? = nil) {
resolvedTitleFont = tokenSet[.textFont].uiFont
resolvedTitleColor = tokenSet[.textColor].uiColor
titleView.attributedText = NSAttributedString(string: " ") // to clear attributes
titleView.text = title
titleView.isSelectable = false
Expand All @@ -275,10 +273,6 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
titleView.attributedText = attributedTitle
titleView.isSelectable = true

let attributes = attributedTitle.attributes(at: 0, effectiveRange: nil)
resolvedTitleFont = attributes[NSAttributedString.Key.font] as? UIFont ?? tokenSet[.textFont].uiFont
resolvedTitleColor = attributes[NSAttributedString.Key.foregroundColor] as? UIColor ?? tokenSet[.textColor].uiColor

setup(style: style, accessoryButtonTitle: accessoryButtonTitle, leadingView: leadingView)
}

Expand Down Expand Up @@ -436,19 +430,18 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont

private func updateTitleViewFont() {
if let window = window {
titleView.font = resolvedTitleFont
let titleFont = tokenSet[.textFont].uiFont
titleView.font = titleFont
// offset text container to center its content
if let resolvedTitleFont = resolvedTitleFont {
let scale = window.rootViewController?.view.contentScaleFactor ?? window.screen.scale
let offset = (floor((abs(resolvedTitleFont.leading) / 2) * scale) / scale) / 2
titleView.textContainerInset.top = offset
titleView.textContainerInset.bottom = -offset
}
let scale = window.rootViewController?.view.contentScaleFactor ?? window.screen.scale
let offset = (floor((abs(titleFont.leading) / 2) * scale) / scale) / 2
titleView.textContainerInset.top = offset
titleView.textContainerInset.bottom = -offset
}
}

private func updateTitleAndBackgroundColors() {
titleView.textColor = resolvedTitleColor
titleView.textColor = tokenSet[.textColor].uiColor

if tableViewCellStyle == .grouped {
backgroundView?.backgroundColor = tokenSet[.backgroundColorGrouped].uiColor
Expand All @@ -458,7 +451,7 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
backgroundView?.backgroundColor = .clear
}

titleView.font = resolvedTitleFont
titleView.font = tokenSet[.textFont].uiFont
titleView.linkColor = tokenSet[.linkTextColor].uiColor
}

Expand Down Expand Up @@ -494,9 +487,6 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
@objc private func handleHeaderViewTapped() {
onHeaderViewTapped?()
}

private var resolvedTitleFont: UIFont?
private var resolvedTitleColor: UIColor?
}

// MARK: - TableViewHeaderFooterView: UITextViewDelegate
Expand Down

0 comments on commit 22f70c5

Please sign in to comment.