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
17 changes: 17 additions & 0 deletions Normal/Shared/Components/AdaptiveStack.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SwiftUI

struct AdaptiveStack<Content: View>: 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 }
}
}
2 changes: 1 addition & 1 deletion Normal/Shared/Components/CustomDomainsEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct CustomDomainsEditor: View {
}
.navigationTitle("Custom Domains")
.navigationBarTitleDisplayMode(.inline)
.safeAreaInset(edge: .bottom) {
.bottomFooter {
if !canRemove {
FooterMessage(text: BlockedMessage.customDomains)
}
Expand Down
11 changes: 11 additions & 0 deletions Normal/Shared/Components/FooterMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
}
}
2 changes: 1 addition & 1 deletion Normal/Views/Groups/GroupFormSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions Normal/Views/Groups/GroupListCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion Normal/Views/Groups/GroupsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct GroupsView: View {
unblockAlert: $unblockAlert
)
}, onMove: move)
.safeAreaInset(edge: .bottom) {
.bottomFooter {
if isBlocked {
FooterMessage(text: BlockedMessage.groups)
} else if !hasGlobalKey {
Expand Down
2 changes: 1 addition & 1 deletion Normal/Views/Key/GroupKeysViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
2 changes: 1 addition & 1 deletion Normal/Views/Key/KeysView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 20 additions & 8 deletions Normal/Views/Schedules/ScheduleCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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",
Expand All @@ -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")
Expand All @@ -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)",
Expand All @@ -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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion Normal/Views/Schedules/ScheduleFormSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Normal/Views/Schedules/SchedulesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
31 changes: 31 additions & 0 deletions Normal/Views/Schedules/WeekdayStrip.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import SwiftUI

struct WeekdayStrip: View {
let weekdays: Set<Int>
@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)
}
}
51 changes: 51 additions & 0 deletions NormalUITests/BlockingUITests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Vision
import XCTest

final class BlockingUITests: XCTestCase {
Expand Down Expand Up @@ -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)
Expand Down
Loading