Skip to content
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
26 changes: 12 additions & 14 deletions App/Sources/Pickup/CallHUDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -93,17 +90,17 @@ 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;
// `.updatesFrequently` tells VoiceOver not to announce every tick (it reads the value on focus).
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)))
Expand All @@ -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)
}
}
}
Expand All @@ -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
Expand Down
37 changes: 35 additions & 2 deletions App/Sources/Pickup/CallViewComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand Down
12 changes: 5 additions & 7 deletions App/Sources/Pickup/DialerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions App/Sources/Pickup/IncomingCallBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions App/Sources/Pickup/LinkCallConfirmation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions App/Sources/Pickup/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions App/Sources/Pickup/ShortcutRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
25 changes: 25 additions & 0 deletions App/Tests/PickupAppTests/ColorContrastTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading