diff --git a/Normal/Shared/Components/AdaptiveStack.swift b/Normal/Shared/Components/AdaptiveStack.swift new file mode 100644 index 0000000..66a3df5 --- /dev/null +++ b/Normal/Shared/Components/AdaptiveStack.swift @@ -0,0 +1,17 @@ +import SwiftUI + +struct AdaptiveStack: View { + @Environment(\.dynamicTypeSize) private var dynamicTypeSize + + var horizontalAlignment: HorizontalAlignment = .leading + var verticalAlignment: VerticalAlignment = .center + var spacing: CGFloat? + @ViewBuilder var content: Content + + var body: some View { + let layout = dynamicTypeSize.isAccessibilitySize + ? AnyLayout(VStackLayout(alignment: horizontalAlignment, spacing: spacing)) + : AnyLayout(HStackLayout(alignment: verticalAlignment, spacing: spacing)) + layout { content } + } +} diff --git a/Normal/Shared/Components/CustomDomainsEditor.swift b/Normal/Shared/Components/CustomDomainsEditor.swift index 17264c1..5ed1245 100644 --- a/Normal/Shared/Components/CustomDomainsEditor.swift +++ b/Normal/Shared/Components/CustomDomainsEditor.swift @@ -31,7 +31,7 @@ struct CustomDomainsEditor: View { } .navigationTitle("Custom Domains") .navigationBarTitleDisplayMode(.inline) - .safeAreaInset(edge: .bottom) { + .bottomFooter { if !canRemove { FooterMessage(text: BlockedMessage.customDomains) } diff --git a/Normal/Shared/Components/FooterMessage.swift b/Normal/Shared/Components/FooterMessage.swift index d69a302..7c86e02 100644 --- a/Normal/Shared/Components/FooterMessage.swift +++ b/Normal/Shared/Components/FooterMessage.swift @@ -18,3 +18,14 @@ enum BlockedMessage { static let keys: LocalizedStringKey = "Unblock all apps to add or delete keys." static let customDomains: LocalizedStringKey = "Unblock all apps to remove custom domains." } + +extension View { + @ViewBuilder + func bottomFooter(@ViewBuilder _ footer: () -> some View) -> some View { + if #available(iOS 26.0, *) { + safeAreaBar(edge: .bottom) { footer() } + } else { + safeAreaInset(edge: .bottom) { footer() } + } + } +} diff --git a/Normal/Views/Groups/GroupFormSheet.swift b/Normal/Views/Groups/GroupFormSheet.swift index ca41822..ebc05a3 100644 --- a/Normal/Views/Groups/GroupFormSheet.swift +++ b/Normal/Views/Groups/GroupFormSheet.swift @@ -111,7 +111,7 @@ struct GroupFormSheet: View { } .navigationTitle(isReadOnly ? "Group" : (isNew ? "New Group" : "Edit Group")) .navigationBarTitleDisplayMode(.inline) - .safeAreaInset(edge: .bottom) { + .bottomFooter { if isReadOnly { FooterMessage(text: BlockedMessage.groups) } diff --git a/Normal/Views/Groups/GroupListCardView.swift b/Normal/Views/Groups/GroupListCardView.swift index 90d29c7..1af5b2d 100644 --- a/Normal/Views/Groups/GroupListCardView.swift +++ b/Normal/Views/Groups/GroupListCardView.swift @@ -132,10 +132,10 @@ struct GroupListCardView: View { } private var header: some View { - HStack(alignment: .center) { + AdaptiveStack(spacing: DS.Spacing.sm) { Text(appGroup.name) .font(.headline) - Spacer() + .frame(maxWidth: .infinity, alignment: .leading) statusBadge } } diff --git a/Normal/Views/Groups/GroupsView.swift b/Normal/Views/Groups/GroupsView.swift index 407f20e..786d29e 100644 --- a/Normal/Views/Groups/GroupsView.swift +++ b/Normal/Views/Groups/GroupsView.swift @@ -61,7 +61,7 @@ struct GroupsView: View { unblockAlert: $unblockAlert ) }, onMove: move) - .safeAreaInset(edge: .bottom) { + .bottomFooter { if isBlocked { FooterMessage(text: BlockedMessage.groups) } else if !hasGlobalKey { diff --git a/Normal/Views/Key/GroupKeysViewer.swift b/Normal/Views/Key/GroupKeysViewer.swift index ad6db1b..95bb0e1 100644 --- a/Normal/Views/Key/GroupKeysViewer.swift +++ b/Normal/Views/Key/GroupKeysViewer.swift @@ -34,7 +34,7 @@ struct GroupKeysViewer: View { } .navigationTitle("Group Keys") .navigationBarTitleDisplayMode(.inline) - .safeAreaInset(edge: .bottom) { + .bottomFooter { if isBlocked, !sections.isEmpty { FooterMessage(text: "Unblock all apps to delete keys.") } diff --git a/Normal/Views/Key/KeysView.swift b/Normal/Views/Key/KeysView.swift index 5105ac3..65ca351 100644 --- a/Normal/Views/Key/KeysView.swift +++ b/Normal/Views/Key/KeysView.swift @@ -46,7 +46,7 @@ struct KeysView: View { }, onMove: move, footer: { groupKeysRow }) } } - .safeAreaInset(edge: .bottom) { + .bottomFooter { if isBlocked { FooterMessage(text: BlockedMessage.keys) } else if keys.isEmpty, !groupKeys.isEmpty { diff --git a/Normal/Views/Schedules/ScheduleCardView.swift b/Normal/Views/Schedules/ScheduleCardView.swift index 5158134..d73a030 100644 --- a/Normal/Views/Schedules/ScheduleCardView.swift +++ b/Normal/Views/Schedules/ScheduleCardView.swift @@ -6,6 +6,7 @@ struct ScheduleCardView: View { @Environment(\.modelContext) private var modelContext @Environment(ScheduleService.self) private var scheduleService @Environment(ScreenTimeService.self) private var screenTimeService + @Environment(\.dynamicTypeSize) private var dynamicTypeSize @Query private var allSchedules: [BlockSchedule] @Query private var keys: [Key] @@ -112,16 +113,18 @@ struct ScheduleCardView: View { } private var header: some View { - HStack(alignment: .center) { + HStack(alignment: dynamicTypeSize.isAccessibilitySize ? .top : .center) { VStack(alignment: .leading, spacing: DS.Spacing.xs) { titleRow - HStack(spacing: DS.Spacing.sm - 2) { + AdaptiveStack(spacing: DS.Spacing.sm - 2) { InlineIconText( systemImage: schedule.shouldBlock ? "lock.fill" : "lock.open.fill", text: schedule.shouldBlock ? "Block" : "Unblock", tint: .blue ) - Text("\u{00B7}").foregroundStyle(.secondary) + if !dynamicTypeSize.isAccessibilitySize { + Text("\u{00B7}").foregroundStyle(.secondary) + } InlineIconText( systemImage: schedule.isTimed ? "hourglass" : "infinity", text: schedule.isTimed ? "Timed" : "Permanent", @@ -135,7 +138,7 @@ struct ScheduleCardView: View { } private var titleRow: some View { - HStack(spacing: DS.Spacing.sm) { + AdaptiveStack(spacing: DS.Spacing.sm) { Text(schedule.name).font(.headline) if !schedule.isEnabled { Text("OFF") @@ -157,7 +160,7 @@ struct ScheduleCardView: View { } private var timingRow: some View { - HStack(spacing: DS.Spacing.lg) { + AdaptiveStack(spacing: dynamicTypeSize.isAccessibilitySize ? DS.Spacing.xs : DS.Spacing.lg) { if schedule.isTimed { Label( "\(schedule.formattedStartTime) \u{2013} \(schedule.formattedEndTime)", @@ -178,10 +181,19 @@ struct ScheduleCardView: View { } private var weekdayChips: some View { - HStack(spacing: DS.Spacing.xs) { - ForEach(schedule.weekdayLabels, id: \.self) { label in - Chip(text: label) + ViewThatFits(in: .horizontal) { + HStack(spacing: DS.Spacing.xs) { + ForEach(schedule.weekdayLabels, id: \.self) { label in + Chip(text: label) + .fixedSize() + } } + .accessibilityElement(children: .contain) + .accessibilityIdentifier("schedule.weekdayChips") + + WeekdayStrip(weekdays: schedule.weekdays) + .dynamicTypeSize(...DynamicTypeSize.accessibility2) + .accessibilityIdentifier("schedule.weekdayStrip") } } diff --git a/Normal/Views/Schedules/ScheduleFormSheet.swift b/Normal/Views/Schedules/ScheduleFormSheet.swift index 1cf3337..300a3d8 100644 --- a/Normal/Views/Schedules/ScheduleFormSheet.swift +++ b/Normal/Views/Schedules/ScheduleFormSheet.swift @@ -125,7 +125,7 @@ struct ScheduleFormSheet: View { } .navigationTitle(isReadOnly ? "Schedule" : (isNew ? "New Schedule" : "Edit Schedule")) .navigationBarTitleDisplayMode(.inline) - .safeAreaInset(edge: .bottom) { + .bottomFooter { if isReadOnly { FooterMessage(text: BlockedMessage.schedules) } diff --git a/Normal/Views/Schedules/SchedulesView.swift b/Normal/Views/Schedules/SchedulesView.swift index 7b0b3db..2c4152f 100644 --- a/Normal/Views/Schedules/SchedulesView.swift +++ b/Normal/Views/Schedules/SchedulesView.swift @@ -55,7 +55,7 @@ struct SchedulesView: View { ReorderableListView(items: schedules, rowContent: { schedule in ScheduleCardView(schedule: schedule) }, onMove: move) - .safeAreaInset(edge: .bottom) { + .bottomFooter { if let message = bottomMessage { FooterMessage(text: message) } diff --git a/Normal/Views/Schedules/WeekdayStrip.swift b/Normal/Views/Schedules/WeekdayStrip.swift new file mode 100644 index 0000000..7d1df3a --- /dev/null +++ b/Normal/Views/Schedules/WeekdayStrip.swift @@ -0,0 +1,31 @@ +import SwiftUI + +struct WeekdayStrip: View { + let weekdays: Set + @ScaledMetric(relativeTo: .caption2) private var chipWidth: CGFloat = 22 + + private var accessibilityDays: String { + let names = Calendar.current.weekdaySymbols + return weekdays.sorted() + .filter { (1 ... 7).contains($0) } + .map { names[$0 - 1] } + .formatted(.list(type: .and)) + } + + var body: some View { + HStack(spacing: DS.Spacing.xs) { + ForEach(1 ... 7, id: \.self) { day in + let isOn = weekdays.contains(day) + Text(Calendar.current.veryShortWeekdaySymbols[day - 1]) + .font(.caption2.weight(.medium)) + .frame(minWidth: chipWidth) + .padding(.vertical, DS.Spacing.xs - 1) + .foregroundStyle(isOn ? Color.primary : Color.secondary) + .background(isOn ? Color.accentColor.opacity(DS.Opacity.muted) : Color(.tertiarySystemFill)) + .clipShape(Capsule()) + } + } + .accessibilityElement(children: .ignore) + .accessibilityLabel(accessibilityDays) + } +} diff --git a/NormalUITests/BlockingUITests.swift b/NormalUITests/BlockingUITests.swift index 55a834e..e58d24a 100644 --- a/NormalUITests/BlockingUITests.swift +++ b/NormalUITests/BlockingUITests.swift @@ -1,3 +1,4 @@ +import Vision import XCTest final class BlockingUITests: XCTestCase { @@ -226,6 +227,56 @@ final class BlockingUITests: XCTestCase { require(app.buttons["group.blockButton"], "Group should be unblocked again") } + func testCardsKeepWholeWordsAtTheLargestTextSize() throws { + let app = launch([ + "-uiTestSeedSchedule", "-uiTestSeedGroupKey", + "-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL", + ]) + + app.mainTab("Schedules").tap() + require(app.descendants(matching: .any)["schedule.weekdayStrip"], "The schedule card should render") + let schedule = try screenLines() + XCTAssertTrue(schedule.contains { $0.contains("Block") }, "\"Block\" should stay one word: \(schedule)") + XCTAssertTrue(schedule.contains { $0.contains("Permanent") }, "\"Permanent\" should stay one word: \(schedule)") + + app.mainTab("Groups").tap() + require(app.buttons["group.blockButton"], "The group card should render") + let group = try screenLines() + XCTAssertTrue(group.contains { $0.contains("Unblocked") }, "\"Unblocked\" should stay one word: \(group)") + } + + private func screenLines() throws -> [String] { + sleep(1) + guard let image = XCUIScreen.main.screenshot().image.cgImage else { return [] } + let request = VNRecognizeTextRequest() + request.recognitionLevel = .accurate + request.usesLanguageCorrection = false + try VNImageRequestHandler(cgImage: image).perform([request]) + return (request.results ?? []).compactMap { $0.topCandidates(1).first?.string } + } + + func testScheduleCardShowsDayChipsWhenTheyFit() { + let app = launch(["-uiTestSeedSchedule"]) + app.mainTab("Schedules").tap() + + require(app.descendants(matching: .any)["schedule.weekdayChips"], "The days should show as chips when they fit") + XCTAssertFalse(app.descendants(matching: .any)["schedule.weekdayStrip"].exists) + } + + func testScheduleCardShowsAWeekStripWhenDayChipsDontFit() { + let app = launch([ + "-uiTestSeedSchedule", + "-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL", + ]) + app.mainTab("Schedules").tap() + + let strip = app.descendants(matching: .any)["schedule.weekdayStrip"] + require(strip, "The days should switch to the week strip instead of breaking words") + let weekdays = Calendar.current.weekdaySymbols[1 ... 5] + XCTAssertEqual(strip.label, weekdays.formatted(.list(type: .and))) + XCTAssertFalse(app.descendants(matching: .any)["schedule.weekdayChips"].exists) + } + func testFailedDefaultDurationUnblockShowsError() { let app = launch(["-uiTestDefaultDuration", "900", "-uiTestTimedUnblockFails"]) blockViaBypass(app)