diff --git a/ownCloudAppShared/Client/Collection Views/Cells/DriveHeaderCell.swift b/ownCloudAppShared/Client/Collection Views/Cells/DriveHeaderCell.swift index 4453d8246..37db6d233 100644 --- a/ownCloudAppShared/Client/Collection Views/Cells/DriveHeaderCell.swift +++ b/ownCloudAppShared/Client/Collection Views/Cells/DriveHeaderCell.swift @@ -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 + 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] diff --git a/ownCloudAppShared/Client/Collection Views/Cells/DriveListCell.swift b/ownCloudAppShared/Client/Collection Views/Cells/DriveListCell.swift index 18a7b0599..09d347dd7 100644 --- a/ownCloudAppShared/Client/Collection Views/Cells/DriveListCell.swift +++ b/ownCloudAppShared/Client/Collection Views/Cells/DriveListCell.swift @@ -47,6 +47,7 @@ class DriveListCell: ThemeableCollectionViewListCell { var subtitle : String? { didSet { subtitleLabel.text = subtitle?.redacted() + subtitleLabel.isHidden = (subtitle == nil) || (subtitle?.count == 0) } } @@ -139,7 +140,7 @@ extension DriveListCell { if let coverImageRequest = coverImageRequest { resourceManager?.start(coverImageRequest) } - + cell.secureView(core: collectionItemRef.ocCellConfiguration?.clientContext?.core) cell.accessories = [ .disclosureIndicator() ] diff --git a/ownCloudAppShared/UIKit Extension/UICellAccessory+Extension.swift b/ownCloudAppShared/UIKit Extension/UICellAccessory+Extension.swift index 68ba7bfd0..e98d1a1d3 100644 --- a/ownCloudAppShared/UIKit Extension/UICellAccessory+Extension.swift +++ b/ownCloudAppShared/UIKit Extension/UICellAccessory+Extension.swift @@ -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))) diff --git a/ownCloudAppShared/UIKit Extension/UIColor+Extension.swift b/ownCloudAppShared/UIKit Extension/UIColor+Extension.swift index 26aceb687..4cf2e378e 100644 --- a/ownCloudAppShared/UIKit Extension/UIColor+Extension.swift +++ b/ownCloudAppShared/UIKit Extension/UIColor+Extension.swift @@ -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 + } + }) + } } diff --git a/ownCloudAppShared/User Interface/Theme/ThemeCollection.swift b/ownCloudAppShared/User Interface/Theme/ThemeCollection.swift index 8eb609497..2f6806221 100644 --- a/ownCloudAppShared/User Interface/Theme/ThemeCollection.swift +++ b/ownCloudAppShared/User Interface/Theme/ThemeCollection.swift @@ -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 @@ -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) @@ -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 @@ -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 @@ -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))