diff --git a/App/Sources/Pickup/CallHUDView.swift b/App/Sources/Pickup/CallHUDView.swift index fbcff6b..33fe2cc 100644 --- a/App/Sources/Pickup/CallHUDView.swift +++ b/App/Sources/Pickup/CallHUDView.swift @@ -34,24 +34,21 @@ struct CallHUDView: View { } } else if info.phase != .ended { Text("Call audio is on \(info.phoneName)") - .font(.caption) + .font(.callout) .foregroundStyle(.secondary) .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) } if let waiting = info.waiting { Text("Call waiting: \(waiting.primaryText ?? String(localized: "Unknown caller"))") - .font(.caption) + .font(.callout) .foregroundStyle(.secondary) .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) } if let notice = info.notice { - Text(verbatim: notice) - .font(.caption) - .foregroundStyle(.orange) + StatusMessage(text: notice) .multilineTextAlignment(.center) - .fixedSize(horizontal: false, vertical: true) .accessibilityAddTraits(.updatesFrequently) } if info.phase == .ended { @@ -93,9 +90,9 @@ struct CallHUDView: View { private var statusLine: some View { switch info.phase { case .dialing: - Text("Calling…").font(.subheadline).foregroundStyle(.secondary).accessibilityIdentifier("hud-state") + Text("Calling…").font(.body).foregroundStyle(.secondary).accessibilityIdentifier("hud-state") case .ringing: - Text("Ringing…").font(.subheadline).foregroundStyle(.secondary).accessibilityIdentifier("hud-state") + Text("Ringing…").font(.body).foregroundStyle(.secondary).accessibilityIdentifier("hud-state") case .active: if let start = info.startedAt { // Re-evaluated once a second. The text and the accessibility value are the same elapsed time; @@ -103,7 +100,7 @@ struct CallHUDView: View { TimelineView(.periodic(from: start, by: 1)) { context in let elapsed = context.date.timeIntervalSince(start) Text(verbatim: CallDurationFormat.string(elapsed)) - .font(.subheadline.monospacedDigit()) + .font(.body.monospacedDigit()) .foregroundStyle(.secondary) .accessibilityLabel(Text("Call duration")) .accessibilityValue(Text(verbatim: CallDurationFormat.spoken(elapsed))) @@ -112,13 +109,13 @@ struct CallHUDView: View { } } case .held: - Text("On hold").font(.subheadline).foregroundStyle(.secondary).accessibilityIdentifier("hud-state") + Text("On hold").font(.body).foregroundStyle(.secondary).accessibilityIdentifier("hud-state") case .ended: if let text = info.endText { - Text(verbatim: text).font(.subheadline).foregroundStyle(.secondary).accessibilityIdentifier("hud-state") + Text(verbatim: text).font(.body).foregroundStyle(.secondary).accessibilityIdentifier("hud-state") } if let duration = info.endDuration { - Text(verbatim: duration).font(.caption.monospacedDigit()).foregroundStyle(.secondary) + Text(verbatim: duration).font(.callout.monospacedDigit()).foregroundStyle(.secondary) } } } @@ -128,9 +125,10 @@ struct CallHUDView: View { AvatarView(party: info.party, size: 44) VStack(alignment: .leading, spacing: 2) { Text(verbatim: title) - .font(.headline) - .lineLimit(1) + .font(.title3.weight(.semibold)) + .lineLimit(2) .truncationMode(.middle) + .fixedSize(horizontal: false, vertical: true) .accessibilityLabel(Text("Call with \(title)")) .accessibilityIdentifier("hud-caller") statusLine diff --git a/App/Sources/Pickup/CallViewComponents.swift b/App/Sources/Pickup/CallViewComponents.swift index 9278b6b..d71d965 100644 --- a/App/Sources/Pickup/CallViewComponents.swift +++ b/App/Sources/Pickup/CallViewComponents.swift @@ -47,6 +47,39 @@ extension View { } } +extension Color { + /// Darker green and orange (Apple's increased-contrast variants of the system colors), so white + /// symbols on them reach at least 3:1 (WCAG 1.4.11); the regular system green and orange give about 2:1. + static let callGreen = Color(red: 0x24 / 255, green: 0x8A / 255, blue: 0x3D / 255) + static let warningOrange = Color(red: 0xC9 / 255, green: 0x34 / 255, blue: 0x00 / 255) +} + +/// A warning or error line. The symbol carries the meaning; the text stays in the primary label color, +/// because orange or red text on a light background stays below the 4.5:1 contrast for text. +struct StatusMessage: View { + enum Kind { case warning, error } + + let text: String + var kind: Kind = .warning + var font: Font = .callout + + var body: some View { + Label { + Text(verbatim: text) + .foregroundStyle(.primary) + .fixedSize(horizontal: false, vertical: true) + } icon: { + switch kind { + case .warning: + Image(systemName: "exclamationmark.triangle.fill").symbolRenderingMode(.multicolor) + case .error: + Image(systemName: "exclamationmark.octagon.fill").foregroundStyle(.red) + } + } + .font(font) + } +} + struct AvatarView: View { let party: CallParty var size: CGFloat @@ -100,7 +133,7 @@ struct CircleControl: View { .background(background, in: Circle()) .contentTransition(.symbolEffect(.replace)) Text(title) - .font(.caption) + .font(.subheadline) .foregroundStyle(.secondary) .lineLimit(2) .minimumScaleFactor(0.8) @@ -121,7 +154,7 @@ struct CircleControl: View { switch style { case .neutral: AnyShapeStyle(.gray.opacity(0.55)) case .toggled: AnyShapeStyle(.white) - case .accept: AnyShapeStyle(Color.green) + case .accept: AnyShapeStyle(Color.callGreen) case .destructive: AnyShapeStyle(Color.red) } } diff --git a/App/Sources/Pickup/DialerView.swift b/App/Sources/Pickup/DialerView.swift index d185e65..7ec9aa4 100644 --- a/App/Sources/Pickup/DialerView.swift +++ b/App/Sources/Pickup/DialerView.swift @@ -89,8 +89,7 @@ struct DialerView: View { GuidanceCard(guidance: guidance, model: model, openSettings: openSettings) } if let notice = model.notice { - Text(verbatim: notice).font(.caption).foregroundStyle(.orange) - .fixedSize(horizontal: false, vertical: true) + StatusMessage(text: notice) } if let reason = unavailableReason, model.guidance == nil { Text(verbatim: reason).font(.caption).foregroundStyle(.secondary) @@ -103,8 +102,7 @@ struct DialerView: View { content } if let error { - Text(verbatim: error).font(.caption).foregroundStyle(.red) - .fixedSize(horizontal: false, vertical: true) + StatusMessage(text: error, kind: .error) } } .padding([.horizontal, .top], 16) @@ -290,7 +288,7 @@ struct DialerView: View { .font(.system(size: 24)) .foregroundStyle(.white) .frame(width: 60, height: 60) - .glassEffect(.regular.tint(.green).interactive(), in: Circle()) + .glassEffect(.regular.tint(.callGreen).interactive(), in: Circle()) .contentShape(Circle()) } .buttonStyle(.plain) @@ -504,7 +502,7 @@ private struct ResultRow: View { .font(.system(size: 14)) .foregroundStyle(.white) .frame(width: 32, height: 32) - .background(row.warning ? Color.orange : Color.green, in: Circle()) + .background(row.warning ? Color.warningOrange : Color.callGreen, in: Circle()) .accessibilityHidden(true) } else if let party = row.party { AvatarView(party: party, size: 32) @@ -513,7 +511,7 @@ private struct ResultRow: View { Text(verbatim: row.title).font(.body).lineLimit(1).truncationMode(.tail) if let subtitle = row.subtitle { Text(verbatim: subtitle).font(.caption) - .foregroundStyle(row.warning ? Color.orange : Color.secondary).lineLimit(1) + .foregroundStyle(.secondary).lineLimit(1) } } Spacer(minLength: 0) diff --git a/App/Sources/Pickup/IncomingCallBannerView.swift b/App/Sources/Pickup/IncomingCallBannerView.swift index beb2b10..d2a8d23 100644 --- a/App/Sources/Pickup/IncomingCallBannerView.swift +++ b/App/Sources/Pickup/IncomingCallBannerView.swift @@ -13,25 +13,23 @@ struct IncomingCallBannerView: View { AvatarView(party: info.party, size: 48) VStack(alignment: .leading, spacing: 2) { Text(verbatim: title) - .font(.headline) - .lineLimit(1) + .font(.title3.weight(.semibold)) + .lineLimit(2) .truncationMode(.middle) + .fixedSize(horizontal: false, vertical: true) if let secondary = info.party.secondaryText { Text(verbatim: secondary) - .font(.subheadline) + .font(.body) .foregroundStyle(.secondary) .lineLimit(1) } Text("Incoming call on \(info.phoneName)") - .font(.caption) + .font(.callout) .foregroundStyle(.secondary) .lineLimit(2) .fixedSize(horizontal: false, vertical: true) if let notice = info.notice { - Text(verbatim: notice) - .font(.caption) - .foregroundStyle(.orange) - .fixedSize(horizontal: false, vertical: true) + StatusMessage(text: notice) } } .frame(maxWidth: .infinity, alignment: .leading) diff --git a/App/Sources/Pickup/LinkCallConfirmation.swift b/App/Sources/Pickup/LinkCallConfirmation.swift index 1028281..5fefe4d 100644 --- a/App/Sources/Pickup/LinkCallConfirmation.swift +++ b/App/Sources/Pickup/LinkCallConfirmation.swift @@ -69,13 +69,18 @@ struct LinkCallConfirmationView: View { Label(String(localized: "This link wants to send a service code (e.g. call forwarding) to your phone.", comment: "Strong warning in the confirmation window when a tel: link contains * or #. Such codes can change phone settings such as call forwarding."), systemImage: "exclamationmark.triangle.fill") - .foregroundStyle(.red) + .font(.body.weight(.semibold)) + .symbolRenderingMode(.multicolor) } Text(String(localized: "Pickup will place this call on \(phone).", comment: "Confirmation detail for a tel: link. %@ is the phone name, or \"your phone\".")) .foregroundStyle(.secondary) if let message = error ?? blocker { - Text(verbatim: message).font(.callout).foregroundStyle(error == nil ? Color.secondary : Color.red) + if error != nil { + StatusMessage(text: message, kind: .error) + } else { + Text(verbatim: message).font(.callout).foregroundStyle(.secondary) + } } } else { Text("This phone link cannot be used.").font(.headline) diff --git a/App/Sources/Pickup/SettingsView.swift b/App/Sources/Pickup/SettingsView.swift index d0636e0..93c2349 100644 --- a/App/Sources/Pickup/SettingsView.swift +++ b/App/Sources/Pickup/SettingsView.swift @@ -224,8 +224,7 @@ struct SettingsView: View { } private func errorLine(_ text: String) -> some View { - Text(verbatim: text).font(.caption).foregroundStyle(.red) - .fixedSize(horizontal: false, vertical: true) + StatusMessage(text: text, kind: .error, font: .caption) } } diff --git a/App/Sources/Pickup/ShortcutRecorder.swift b/App/Sources/Pickup/ShortcutRecorder.swift index 6a61c97..41108b8 100644 --- a/App/Sources/Pickup/ShortcutRecorder.swift +++ b/App/Sources/Pickup/ShortcutRecorder.swift @@ -84,13 +84,13 @@ struct ShortcutHint: View { var body: some View { if state.rejected { - line(String(localized: "Include ⌘, ⌃ or ⌥ in the shortcut.", comment: "Hint when a recorded shortcut has no ⌘, ⌃ or ⌥ modifier and was rejected."), color: .red) + line(String(localized: "Include ⌘, ⌃ or ⌥ in the shortcut.", comment: "Hint when a recorded shortcut has no ⌘, ⌃ or ⌥ modifier and was rejected."), kind: .error) } else if manager.combo?.isLikelySystemShortcut == true { - line(String(localized: "macOS may already use this combination.", comment: "Warning under the global shortcut when it matches a well-known system shortcut."), color: .orange) + line(String(localized: "macOS may already use this combination.", comment: "Warning under the global shortcut when it matches a well-known system shortcut."), kind: .warning) } } - private func line(_ text: String, color: Color) -> some View { - Text(verbatim: text).font(.caption).foregroundStyle(color).fixedSize(horizontal: false, vertical: true) + private func line(_ text: String, kind: StatusMessage.Kind) -> some View { + StatusMessage(text: text, kind: kind, font: .caption) } } diff --git a/App/Tests/PickupAppTests/ColorContrastTests.swift b/App/Tests/PickupAppTests/ColorContrastTests.swift new file mode 100644 index 0000000..be74dc0 --- /dev/null +++ b/App/Tests/PickupAppTests/ColorContrastTests.swift @@ -0,0 +1,25 @@ +import AppKit +import SwiftUI +import XCTest +@testable import Pickup + +/// White symbols on the accept/call and warning circles need at least 3:1 (WCAG 1.4.11). +final class ColorContrastTests: XCTestCase { + private func luminance(_ color: Color) throws -> Double { + let rgb = try XCTUnwrap(NSColor(color).usingColorSpace(.sRGB)) + func linear(_ c: CGFloat) -> Double { + let c = Double(c) + return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4) + } + return 0.2126 * linear(rgb.redComponent) + 0.7152 * linear(rgb.greenComponent) + 0.0722 * linear(rgb.blueComponent) + } + + private func contrastWithWhite(_ color: Color) throws -> Double { + 1.05 / (try luminance(color) + 0.05) + } + + func testWhiteSymbolsOnCallGreenAndWarningOrangeReachThreeToOne() throws { + XCTAssertGreaterThanOrEqual(try contrastWithWhite(.callGreen), 3) + XCTAssertGreaterThanOrEqual(try contrastWithWhite(.warningOrange), 3) + } +}