Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #1929 #1945

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading