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

[fix/a11y-1334] Add Spaces text background color if Increase Contrast is on #1451

Merged
merged 4 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ class DriveHeaderCell: DriveListCell {
coverObservation?.invalidate()
}

override init(frame: CGRect) {
super.init(frame: frame)
setupHighContrastMode()
updateForContrastMode()
}

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

var contrastObservation: NSObjectProtocol?

func setupHighContrastMode() {
contrastObservation = NotificationCenter.default.addObserver(forName: UIAccessibility.darkerSystemColorsStatusDidChangeNotification, object: nil, queue: .main, using: { [weak self] _ in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove observer is missing on deinit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary as observers added via this method are automatically removed once the returned observation object is deallocated. As the returned contrastObservation object is released and deallocated at the time DriveHeaderCell is deinited/deallocated, the observation is automatically removed.

self?.updateForContrastMode()
})
}

func updateForContrastMode() {
if UIAccessibility.isDarkerSystemColorsEnabled {
titleLabel.backgroundColor = UIColor(white: 0, alpha: 0.8)
subtitleLabel.backgroundColor = UIColor(white: 0, alpha: 0.8)
} else {
titleLabel.backgroundColor = .clear
subtitleLabel.backgroundColor = .clear
}
}

override func configure() {
cssSelectors = [.header, .drive]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DriveListCell: ThemeableCollectionViewListCell {
var subtitle : String? {
didSet {
subtitleLabel.text = subtitle?.redacted()
subtitleLabel.isHidden = (subtitle == nil) || (subtitle?.count == 0)
}
}

Expand Down Expand Up @@ -139,7 +140,7 @@ extension DriveListCell {
if let coverImageRequest = coverImageRequest {
resourceManager?.start(coverImageRequest)
}

cell.secureView(core: collectionItemRef.ocCellConfiguration?.clientContext?.core)

cell.accessories = [ .disclosureIndicator() ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,22 @@ public extension UICellAccessory {
button.menu = menu
}

button.cssSelectors = cssSelectors

if image != nil, (title != nil || menu != nil) {
var configuration = UIButton.Configuration.borderedTinted()
var configuration = UIAccessibility.isDarkerSystemColorsEnabled ? UIButton.Configuration.bordered() : UIButton.Configuration.borderedTinted()
configuration.buttonSize = .small
configuration.imagePadding = 5
configuration.cornerStyle = .large

if UIAccessibility.isDarkerSystemColorsEnabled {
configuration.background.backgroundColor = .clear
configuration.background.strokeColor = button.getThemeCSSColor(.stroke)
}

button.configuration = configuration.updated(for: button)
}

button.cssSelectors = cssSelectors

button.applyThemeCollection(Theme.shared.activeCollection)

return (button, .customView(configuration: UICellAccessory.CustomViewConfiguration(customView: button, placement: placement)))
Expand Down
10 changes: 10 additions & 0 deletions ownCloudAppShared/UIKit Extension/UIColor+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,14 @@ extension UIColor {

return highestContrastColor
}

public func withHighContrastAlternative(_ highContrastColor: UIColor) -> UIColor {
return UIColor(dynamicProvider: { _ in
if UIAccessibility.isDarkerSystemColorsEnabled {
return highContrastColor
} else {
return self
}
})
}
}
21 changes: 10 additions & 11 deletions ownCloudAppShared/User Interface/Theme/ThemeCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ private struct ThemeColorSet {
var backgroundColor: UIColor

static func from(backgroundColor: UIColor, tintColor: UIColor, for style: UIUserInterfaceStyle) -> ThemeColorSet {
let preferredtTraitCollection = UITraitCollection(userInterfaceStyle: (style == .light) ? .light : .dark)
let preferredPrimaryLabelColor = UIColor.label.resolvedColor(with: preferredtTraitCollection)
let preferredSecondaryLabelColor = UIColor.secondaryLabel.resolvedColor(with: preferredtTraitCollection)
let preferredTraitCollection = UITraitCollection(userInterfaceStyle: (style == .light) ? .light : .dark)
let preferredPrimaryLabelColor = UIColor.label.resolvedColor(with: preferredTraitCollection)
let preferredSecondaryLabelColor = UIColor.secondaryLabel.resolvedColor(with: preferredTraitCollection).withHighContrastAlternative(.label.resolvedColor(with: preferredTraitCollection))

let alternateTraitCollection = UITraitCollection(userInterfaceStyle: (style == .light) ? .dark : .light)
let alternatePrimaryLabelColor = UIColor.label.resolvedColor(with: alternateTraitCollection)
let alternateSecondaryLabelColor = UIColor.secondaryLabel.resolvedColor(with: alternateTraitCollection)
let alternateSecondaryLabelColor = UIColor.secondaryLabel.resolvedColor(with: alternateTraitCollection).withHighContrastAlternative(.label.resolvedColor(with: alternateTraitCollection))

let labelColor = backgroundColor.preferredContrastColor(from: [preferredPrimaryLabelColor, alternatePrimaryLabelColor]) ?? preferredPrimaryLabelColor
let secondaryLabelColor = backgroundColor.preferredContrastColor(from: [preferredSecondaryLabelColor, alternateSecondaryLabelColor]) ?? preferredSecondaryLabelColor
Expand Down Expand Up @@ -317,14 +317,13 @@ public class ThemeCollection : NSObject {
lightBrandSet.secondaryLabelColor = .white
lightBrandSet.iconColor = .white

accountCellSet = lightBrandSet
sidebarAccountCellSet = ThemeColorSet.from(backgroundColor: .init(hex: 0, alpha: 0.5), tintColor: lightBrandColor, for: interfaceStyle)
accountCellSet = sidebarAccountCellSet

navigationBarSet = darkBrandSet
toolbarSet = darkBrandSet

cellSet = ThemeColorSet.from(backgroundColor: UIColor(hex: 0), tintColor: lightBrandColor, for: interfaceStyle)
cellSet = ThemeColorSet.from(backgroundColor: UIColor(hex: 0), tintColor: lightBrandColor.withHighContrastAlternative(lightBrandColor.lighter(0.3)), for: interfaceStyle)
cellStateSet = ThemeColorStateSet.from(colorSet: cellSet, for: interfaceStyle)
collectionBackgroundColor = darkBrandColor.darker(0.1)

Expand Down Expand Up @@ -382,7 +381,7 @@ public class ThemeCollection : NSObject {
navigationBarSet = ThemeColorSet.from(backgroundColor: .systemBackground.resolvedColor(with: styleTraitCollection), tintColor: lightBrandColor, for: interfaceStyle)
toolbarSet = navigationBarSet

cellSet = ThemeColorSet.from(backgroundColor: .systemBackground.resolvedColor(with: styleTraitCollection), tintColor: lightBrandColor, for: interfaceStyle)
cellSet = ThemeColorSet.from(backgroundColor: .systemBackground.resolvedColor(with: styleTraitCollection), tintColor: lightBrandColor.withHighContrastAlternative(lightBrandColor.darker(0.3)), for: interfaceStyle)
cellStateSet = ThemeColorStateSet.from(colorSet: cellSet, for: interfaceStyle)
collectionBackgroundColor = cellSet.backgroundColor

Expand All @@ -404,9 +403,9 @@ public class ThemeCollection : NSObject {
iconSymbolColor = darkBrandColor

sectionHeaderColor = .label.resolvedColor(with: styleTraitCollection)
sectionFooterColor = .secondaryLabel.resolvedColor(with: styleTraitCollection)
groupedSectionHeaderColor = .secondaryLabel.resolvedColor(with: styleTraitCollection)
groupedSectionFooterColor = .secondaryLabel.resolvedColor(with: styleTraitCollection)
sectionFooterColor = .secondaryLabel.resolvedColor(with: styleTraitCollection).withHighContrastAlternative(sectionHeaderColor) // aka "resolved system .label color" in this case
groupedSectionHeaderColor = .secondaryLabel.resolvedColor(with: styleTraitCollection).withHighContrastAlternative(sectionHeaderColor)
groupedSectionFooterColor = .secondaryLabel.resolvedColor(with: styleTraitCollection).withHighContrastAlternative(sectionHeaderColor)

moreHeaderBackgroundColor = cellSet.backgroundColor

Expand Down Expand Up @@ -619,7 +618,7 @@ public class ThemeCollection : NSObject {
ThemeCSSRecord(selectors: [.label, .warning], property: .stroke, value: UIColor(hex: 0xF2994A)),
ThemeCSSRecord(selectors: [.label, .error], property: .stroke, value: UIColor(hex: 0xEB5757)),
ThemeCSSRecord(selectors: [.label, .success], property: .stroke, value: UIColor(hex: 0x27AE60)),

// - Confidential
ThemeCSSRecord(selectors: [.confidentialLabel], property: .stroke, value: tintColor.withAlphaComponent(0.8)),
ThemeCSSRecord(selectors: [.confidentialSecondaryLabel], property: .stroke, value: tintColor.withAlphaComponent(0.4))
Expand Down