From 6eb5721e84f3b18e7da4f54b469a6d9ee8005ac2 Mon Sep 17 00:00:00 2001 From: ykisana Date: Thu, 19 Nov 2026 16:06:09 -0600 Subject: [PATCH] fix: keep app icon rows on one line with a readable overflow count Home > Status > Max Daily Limits and the daily limit editor's duplicates warning stacked their app icons in a column, because the icons had no row around them. On group and schedule cards, when the icons filled the row, the "+N" count was squeezed into an empty grey pill. SelectionIconRow now owns the row: it shows as many icons as fit, then a fixed-size "+N" tile the size of an icon, which VoiceOver reads as "N more". Every icon row uses it. Closes #140. Closes #141. --- Normal/App/NormalApp.swift | 11 +++-- Normal/App/UITestSupport.swift | 13 +++++- Normal/Resources/Localizable.xcstrings | 4 ++ .../Shared/Components/SelectionIconRow.swift | 44 +++++++++++++++++++ .../Components/SelectionIconsView.swift | 10 ----- Normal/Views/Groups/GroupListCardView.swift | 12 +++-- Normal/Views/Home/StatusDetailView.swift | 2 +- Normal/Views/Schedules/ScheduleCardView.swift | 12 +++-- Normal/Views/Usage/UsageLimitEditor.swift | 2 +- Normal/Views/Usage/UsageLimitRow.swift | 4 +- NormalUITests/BlockingUITests.swift | 28 ++++++++++++ 11 files changed, 109 insertions(+), 33 deletions(-) create mode 100644 Normal/Shared/Components/SelectionIconRow.swift diff --git a/Normal/App/NormalApp.swift b/Normal/App/NormalApp.swift index 24c6ca9..8883d5a 100644 --- a/Normal/App/NormalApp.swift +++ b/Normal/App/NormalApp.swift @@ -30,7 +30,7 @@ struct NormalApp: App { if (try? context.fetchCount(descriptor)) == 0 { let settings = Settings() settings.hasCompletedOnboarding = UITestSupport.skipOnboarding - settings.enableCustomDomains = UITestSupport.customDomains + settings.enableCustomDomains = UITestSupport.customDomains || UITestSupport.crowdedSelections settings.skipBlockWithoutKeyConfirmation = UITestSupport.skipBypassConfirm settings.customUnblockDurationSeconds = UITestSupport.unblockDurationSeconds settings.defaultUnblockSeconds = UITestSupport.defaultDurationSeconds @@ -50,7 +50,8 @@ struct NormalApp: App { let group = AppGroup( id: UITestSupport.seedGroupID, name: "Test Group", - selection: UITestSupport.groupSelection + selection: UITestSupport.groupSelection, + customDomains: UITestSupport.crowdedSelections ? UITestSupport.crowdedDomains : [] ) context.insert(group) context.insert(Key(name: "Group Key", type: .qr, rawValue: "GROUP-VALUE", groupID: group.id)) @@ -76,9 +77,13 @@ struct NormalApp: App { weekdays: [2, 3, 4, 5, 6], shouldBlock: true, isTimed: false, - isEnabled: true + isEnabled: true, + customDomains: UITestSupport.crowdedSelections ? UITestSupport.crowdedDomains : [] )) } + if UITestSupport.seedUsageLimit { + context.insert(UsageLimit(selection: UITestSupport.usageLimitSelection, minutesPerDay: 45)) + } } modelContainer = container diff --git a/Normal/App/UITestSupport.swift b/Normal/App/UITestSupport.swift index 21906d6..d88294c 100644 --- a/Normal/App/UITestSupport.swift +++ b/Normal/App/UITestSupport.swift @@ -21,6 +21,15 @@ enum UITestSupport { static let customDomains = arguments.contains("-uiTestCustomDomains") + static let crowdedSelections = arguments.contains("-uiTestCrowdedSelections") + + static let seedUsageLimit = arguments.contains("-uiTestSeedUsageLimit") + + static let crowdedDomains = [ + "apple.com", "bbc.com", "cnn.com", "dropbox.com", "espn.com", + "figma.com", "github.com", "hulu.com", "imdb.com", + ] + static let websitesOnly = arguments.contains("-uiTestWebsitesOnly") static let timedUnblockFails = arguments.contains("-uiTestTimedUnblockFails") @@ -49,7 +58,9 @@ enum UITestSupport { static let mainSelection = selection(apps: websitesOnly ? [] : [1, 2, 3]) - static let mainCustomDomains = websitesOnly ? ["example.com"] : [] + static let mainCustomDomains = websitesOnly ? ["example.com"] : (crowdedSelections ? crowdedDomains : []) + + static let usageLimitSelection = selection(apps: [1, 2, 3, 4, 5, 6, 7, 8]) static let groupSelection = selection(apps: [1]) diff --git a/Normal/Resources/Localizable.xcstrings b/Normal/Resources/Localizable.xcstrings index 413d253..bfa3eb6 100644 --- a/Normal/Resources/Localizable.xcstrings +++ b/Normal/Resources/Localizable.xcstrings @@ -80,6 +80,10 @@ "comment" : "A badge displaying the number of apps selected for a group.", "isCommentAutoGenerated" : true }, + "%lld more" : { + "comment" : "VoiceOver label for the badge after a row of app and website icons, counting the ones that didn't fit.", + "isCommentAutoGenerated" : true + }, "%lld Apps" : { "comment" : "A string describing the number of selected apps. The argument is the count of selected apps.", "isCommentAutoGenerated" : true diff --git a/Normal/Shared/Components/SelectionIconRow.swift b/Normal/Shared/Components/SelectionIconRow.swift new file mode 100644 index 0000000..ae7cf46 --- /dev/null +++ b/Normal/Shared/Components/SelectionIconRow.swift @@ -0,0 +1,44 @@ +import SwiftUI + +struct SelectionIconRow: View { + let tokens: [AnyHashable] + var customDomains: [String] = [] + let maxCount: Int + + private var total: Int { + tokens.count + customDomains.count + } + + var body: some View { + ViewThatFits(in: .horizontal) { + ForEach(Array(stride(from: min(maxCount, total), through: 0, by: -1)), id: \.self) { shown in + HStack(spacing: DS.Spacing.sm) { + SelectionIconsView(tokens: tokens, customDomains: customDomains, limit: shown) + if total > shown { + SelectionOverflowBadge(count: total - shown) + } + } + } + } + .accessibilityElement(children: .contain) + .accessibilityIdentifier("selectionIcons.row") + } +} + +private struct SelectionOverflowBadge: View { + let count: Int + @ScaledMetric(relativeTo: .body) private var size: CGFloat = 24 + + var body: some View { + Text("+\(count)") + .font(.caption.weight(.semibold).monospacedDigit()) + .foregroundStyle(.secondary) + .lineLimit(1) + .padding(.horizontal, DS.Spacing.xs) + .frame(minWidth: size, minHeight: size) + .background(.quaternary, in: RoundedRectangle(cornerRadius: size / 4, style: .continuous)) + .fixedSize() + .accessibilityLabel(Text("\(count) more")) + .accessibilityIdentifier("selectionIcons.overflow") + } +} diff --git a/Normal/Shared/Components/SelectionIconsView.swift b/Normal/Shared/Components/SelectionIconsView.swift index fb9b986..d281d3b 100644 --- a/Normal/Shared/Components/SelectionIconsView.swift +++ b/Normal/Shared/Components/SelectionIconsView.swift @@ -15,7 +15,6 @@ struct SelectionIconsView: View { var body: some View { let items = tokens.sortedStably.map(Item.token) + customDomains.map(Item.domain) let shown = limit.map { Array(items.prefix($0)) } ?? items - let overflow = items.count - shown.count ForEach(shown, id: \.self) { item in Group { @@ -36,14 +35,5 @@ struct SelectionIconsView: View { } .labelStyle(.iconOnly) } - - if overflow > 0 { - Text("+\(overflow)") - .font(.caption.weight(.semibold)) - .foregroundStyle(.secondary) - .padding(.horizontal, DS.Spacing.sm) - .padding(.vertical, DS.Spacing.xs) - .background(.quaternary, in: Capsule()) - } } } diff --git a/Normal/Views/Groups/GroupListCardView.swift b/Normal/Views/Groups/GroupListCardView.swift index a95b411..16bbf1b 100644 --- a/Normal/Views/Groups/GroupListCardView.swift +++ b/Normal/Views/Groups/GroupListCardView.swift @@ -148,13 +148,11 @@ struct GroupListCardView: View { } private var tokenStrip: some View { - HStack(spacing: DS.Spacing.sm) { - SelectionIconsView( - tokens: appGroup.selection.allTokens, - customDomains: customDomains, - limit: 6 - ) - } + SelectionIconRow( + tokens: appGroup.selection.allTokens, + customDomains: customDomains, + maxCount: 6 + ) } private var reselectionBinding: Binding { diff --git a/Normal/Views/Home/StatusDetailView.swift b/Normal/Views/Home/StatusDetailView.swift index 4bb328c..636076f 100644 --- a/Normal/Views/Home/StatusDetailView.swift +++ b/Normal/Views/Home/StatusDetailView.swift @@ -81,7 +81,7 @@ struct StatusDetailView: View { private func limitRow(_ limit: UsageLimit, state: UsageLimitState, isOff: Bool, isPaused: Bool) -> some View { HStack { VStack(alignment: .leading, spacing: DS.Spacing.xs) { - SelectionIconsView(tokens: limit.selection.allTokens, limit: 5) + SelectionIconRow(tokens: limit.selection.allTokens, maxCount: 5) Text("\(limit.selection.selectedTokenCounts) ยท \(DurationFormat.compact(minutes: limit.minutesPerDay)) a day") .font(.caption) .foregroundStyle(.secondary) diff --git a/Normal/Views/Schedules/ScheduleCardView.swift b/Normal/Views/Schedules/ScheduleCardView.swift index cb75df2..5d807dd 100644 --- a/Normal/Views/Schedules/ScheduleCardView.swift +++ b/Normal/Views/Schedules/ScheduleCardView.swift @@ -200,13 +200,11 @@ struct ScheduleCardView: View { @ViewBuilder private var tokenStrip: some View { if !schedule.selection.allTokens.isEmpty || !customDomains.isEmpty { - HStack(spacing: DS.Spacing.sm) { - SelectionIconsView( - tokens: schedule.selection.allTokens, - customDomains: customDomains, - limit: 6 - ) - } + SelectionIconRow( + tokens: schedule.selection.allTokens, + customDomains: customDomains, + maxCount: 6 + ) } } diff --git a/Normal/Views/Usage/UsageLimitEditor.swift b/Normal/Views/Usage/UsageLimitEditor.swift index 6b25133..4e9b651 100644 --- a/Normal/Views/Usage/UsageLimitEditor.swift +++ b/Normal/Views/Usage/UsageLimitEditor.swift @@ -181,7 +181,7 @@ struct UsageLimitEditor: View { private var duplicatesWarning: some View { VStack(alignment: .leading, spacing: DS.Spacing.sm) { - SelectionIconsView(tokens: duplicates.allTokens, limit: 5) + SelectionIconRow(tokens: duplicates.allTokens, maxCount: 5) Text("Already in another limit. Remove them here, or change that limit instead.") .foregroundStyle(.red) } diff --git a/Normal/Views/Usage/UsageLimitRow.swift b/Normal/Views/Usage/UsageLimitRow.swift index 293ccf9..4e1601a 100644 --- a/Normal/Views/Usage/UsageLimitRow.swift +++ b/Normal/Views/Usage/UsageLimitRow.swift @@ -8,9 +8,7 @@ struct UsageLimitRow: View { var body: some View { HStack(spacing: DS.Spacing.md) { VStack(alignment: .leading, spacing: DS.Spacing.xs) { - HStack(spacing: DS.Spacing.sm) { - SelectionIconsView(tokens: limit.selection.allTokens, limit: 5) - } + SelectionIconRow(tokens: limit.selection.allTokens, maxCount: 5) Text(verbatim: limit.selection.selectedTokenCounts) .font(.caption) .foregroundStyle(.secondary) diff --git a/NormalUITests/BlockingUITests.swift b/NormalUITests/BlockingUITests.swift index f49b5eb..61053b0 100644 --- a/NormalUITests/BlockingUITests.swift +++ b/NormalUITests/BlockingUITests.swift @@ -296,6 +296,34 @@ final class BlockingUITests: XCTestCase { return (request.results ?? []).compactMap { $0.topCandidates(1).first?.string } } + func testStatusShowsDailyLimitIconsInOneRow() { + let app = launch(["-uiTestSeedUsageLimit"]) + let status = app.buttons["home.statusLink"] + require(status, "Home should link to Status") + status.tap() + + let row = app.descendants(matching: .any)["selectionIcons.row"].firstMatch + require(row, "The daily limit should show its icons") + let more = app.descendants(matching: .any)["selectionIcons.overflow"].firstMatch + require(more, "Eight apps should end in a count of the ones that don't fit") + XCTAssertLessThan(row.frame.height, more.frame.height * 1.5, "The icons should sit in one row, not a column") + } + + func testCardIconRowsKeepTheOverflowCountReadableAtTheLargestTextSize() { + let app = launch([ + "-uiTestCrowdedSelections", "-uiTestSeedGroupKey", + "-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL", + ]) + app.mainTab("Groups").tap() + + let more = app.descendants(matching: .any)["selectionIcons.overflow"].firstMatch + require(more, "Ten items should end in a count of the ones that don't fit") + XCTAssertGreaterThanOrEqual(more.frame.width, more.frame.height * 0.9, "The count should not be squeezed") + XCTAssertTrue(more.label.hasSuffix("more"), "VoiceOver should read the count: \(more.label)") + let row = app.descendants(matching: .any)["selectionIcons.row"].firstMatch + XCTAssertLessThanOrEqual(row.frame.maxX, app.windows.firstMatch.frame.maxX, "The row should fit on screen") + } + func testScheduleCardShowsDayChipsWhenTheyFit() { let app = launch(["-uiTestSeedSchedule"]) app.mainTab("Schedules").tap()