From 19e1c99b5a1f233adfc80f39b2f9d9e200f742f4 Mon Sep 17 00:00:00 2001 From: ykisana Date: Wed, 18 Nov 2026 08:51:59 -0600 Subject: [PATCH] fix: use the system close button on iOS 26 The Location Key check showed a gray xmark.circle.fill image inside the toolbar's own glass button, and forced a solid navigation bar. On iOS 26 and later, close buttons now use the system Liquid Glass close button: Button(role: .close) in the Location Key check and Settings toolbars, and a glass circle X on the saved-key card. The Location Key check also stops forcing a bar background. iOS 17 and 18 look the same as before. Closes #124. --- Normal/App/NormalApp.swift | 4 +- Normal/App/UITestSupport.swift | 2 + Normal/Shared/Components/CloseButton.swift | 37 +++++++++++++++++++ .../KeySelect/LocationUnlockView.swift | 25 ++++++++----- Normal/Views/Key/LocationKeyInfoSheet.swift | 8 +--- Normal/Views/Settings/SettingsView.swift | 10 ++++- NormalUITests/BlockingUITests.swift | 19 ++++++++++ NormalUITests/NormalUITests.swift | 23 ++++++++++++ 8 files changed, 108 insertions(+), 20 deletions(-) create mode 100644 Normal/Shared/Components/CloseButton.swift diff --git a/Normal/App/NormalApp.swift b/Normal/App/NormalApp.swift index 2f2133c..cda645d 100644 --- a/Normal/App/NormalApp.swift +++ b/Normal/App/NormalApp.swift @@ -57,8 +57,8 @@ struct NormalApp: App { if UITestSupport.seedLocationKey { context.insert(Key( name: "Test Place", - latitude: 37.33182, - longitude: -122.03118, + latitude: UITestSupport.locationKeyFarAway ? 40.7484 : 37.33182, + longitude: UITestSupport.locationKeyFarAway ? -73.9857 : -122.03118, radiusMeters: 400, radiusKind: .unblock )) diff --git a/Normal/App/UITestSupport.swift b/Normal/App/UITestSupport.swift index 98e1ef9..656c8b2 100644 --- a/Normal/App/UITestSupport.swift +++ b/Normal/App/UITestSupport.swift @@ -32,6 +32,8 @@ enum UITestSupport { static let seedLocationKey = arguments.contains("-uiTestSeedLocationKey") + static let locationKeyFarAway = arguments.contains("-uiTestLocationKeyFarAway") + static let seedGroupID = UUID(uuidString: "6E0A1C9B-2D4F-4B7A-9C3E-5F8D1A2B3C4D")! static let skipBypassConfirm = arguments.contains("-uiTestSkipBypassConfirm") diff --git a/Normal/Shared/Components/CloseButton.swift b/Normal/Shared/Components/CloseButton.swift new file mode 100644 index 0000000..c0ee757 --- /dev/null +++ b/Normal/Shared/Components/CloseButton.swift @@ -0,0 +1,37 @@ +import SwiftUI + +struct CloseButton: View { + enum Placement { + case toolbar + case inline + } + + var placement: Placement = .toolbar + let action: () -> Void + + var body: some View { + if #available(iOS 26.0, *) { + switch placement { + case .toolbar: + Button(role: .close, action: action) + case .inline: + Button(role: .close, action: action) { + Image(systemName: "xmark") + } + .buttonStyle(.glass) + .buttonBorderShape(.circle) + .controlSize(.large) + .accessibilityLabel("Close") + } + } else { + Button(action: action) { + Image(systemName: "xmark.circle.fill") + .font(.title2) + .symbolRenderingMode(placement == .toolbar ? .hierarchical : .monochrome) + .foregroundStyle(placement == .toolbar ? .secondary : .tertiary) + } + .buttonStyle(.plain) + .accessibilityLabel("Close") + } + } +} diff --git a/Normal/Views/BlockUnblockViews/KeySelect/LocationUnlockView.swift b/Normal/Views/BlockUnblockViews/KeySelect/LocationUnlockView.swift index 963b40f..e75c747 100644 --- a/Normal/Views/BlockUnblockViews/KeySelect/LocationUnlockView.swift +++ b/Normal/Views/BlockUnblockViews/KeySelect/LocationUnlockView.swift @@ -31,17 +31,11 @@ struct LocationUnlockView: View { .navigationTitle("Location Key") .navigationBarTitleDisplayMode(.inline) .navigationBarBackButtonHidden() - .toolbarBackground(.visible, for: .navigationBar) + .opaqueNavigationBarBeforeLiquidGlass() .toolbar { - ToolbarItem(placement: .confirmationAction) { - Button(action: onClose) { - Image(systemName: "xmark.circle.fill") - .font(.title2) - .symbolRenderingMode(.hierarchical) - .foregroundStyle(.secondary) - } - .accessibilityLabel("Close") - .accessibilityIdentifier("locationUnlock.close") + ToolbarItem(placement: .topBarTrailing) { + CloseButton(action: onClose) + .accessibilityIdentifier("locationUnlock.close") } } .task { @@ -183,3 +177,14 @@ struct LocationUnlockView: View { : "Leave the highlighted area to unlock." } } + +private extension View { + @ViewBuilder + func opaqueNavigationBarBeforeLiquidGlass() -> some View { + if #available(iOS 26.0, *) { + self + } else { + toolbarBackground(.visible, for: .navigationBar) + } + } +} diff --git a/Normal/Views/Key/LocationKeyInfoSheet.swift b/Normal/Views/Key/LocationKeyInfoSheet.swift index ed4af60..cd920a8 100644 --- a/Normal/Views/Key/LocationKeyInfoSheet.swift +++ b/Normal/Views/Key/LocationKeyInfoSheet.swift @@ -32,12 +32,8 @@ struct LocationKeyInfoSheet: View { } } Spacer() - Button { dismiss() } label: { - Image(systemName: "xmark.circle.fill") - .font(.title2) - .foregroundStyle(.tertiary) - } - .buttonStyle(.plain) + CloseButton(placement: .inline) { dismiss() } + .accessibilityIdentifier("locationKeyInfo.close") } HStack(spacing: DS.Spacing.md) { diff --git a/Normal/Views/Settings/SettingsView.swift b/Normal/Views/Settings/SettingsView.swift index e06684c..7d7b109 100644 --- a/Normal/Views/Settings/SettingsView.swift +++ b/Normal/Views/Settings/SettingsView.swift @@ -32,8 +32,14 @@ struct SettingsView: View { NavigationStack { tabView .toolbar { - ToolbarItem(placement: .confirmationAction) { - Button("Close") { dismiss() } + if #available(iOS 26.0, *) { + ToolbarItem(placement: .topBarTrailing) { + Button(role: .close) { dismiss() } + } + } else { + ToolbarItem(placement: .confirmationAction) { + Button("Close") { dismiss() } + } } } .alert("Emergency Unblock", isPresented: $showConfirmation) { diff --git a/NormalUITests/BlockingUITests.swift b/NormalUITests/BlockingUITests.swift index e58d24a..7dd1a66 100644 --- a/NormalUITests/BlockingUITests.swift +++ b/NormalUITests/BlockingUITests.swift @@ -97,6 +97,25 @@ final class BlockingUITests: XCTestCase { require(app.staticTexts["No Active Blocks"], "Apps should be unblocked") } + func testLocationKeyCheckCanBeClosedWhenOutOfRange() { + let app = launch(["-uiTestSeedLocationKey", "-uiTestLocationKeyFarAway"]) + blockViaBypass(app) + + app.buttons["home.unblockAll"].tap() + let locationRow = app.buttons["keySelect.row.LOCATION"] + require(locationRow, "The picker should offer the location key") + locationRow.tap() + + require(app.staticTexts["You're not in an unlock area"], "Away from the key, the check should say so") + let close = app.buttons["locationUnlock.close"] + require(close, "The location check should have a close button") + XCTAssertEqual(close.label, "Close") + close.tap() + + require(app.buttons["keySelect.row.QR"], "Closing should return to Choose Key") + XCTAssertFalse(close.exists, "The location check should be gone") + } + func testBlockingDisablesKeysTab() { let app = launch() blockViaBypass(app) diff --git a/NormalUITests/NormalUITests.swift b/NormalUITests/NormalUITests.swift index e038b96..f4eb7bb 100644 --- a/NormalUITests/NormalUITests.swift +++ b/NormalUITests/NormalUITests.swift @@ -181,6 +181,29 @@ final class NormalUITests: XCTestCase { ) } + @MainActor + func testLocationKeyInfoClosesWithTheCloseButton() { + let app = launch(["-uiTestMode", "-uiTestSkipOnboarding", "-uiTestSeedLocationKey"]) + app.mainTab("Keys").tap() + app.buttons["keys.addButton"].tap() + let locationSegment = app.buttons["Location"] + require(locationSegment, "Location key type should be selectable") + locationSegment.tap() + app.buttons["key.locationButton"].tap() + + let map = app.otherElements["locationPicker.map"].firstMatch + require(map, "Location picker should show the map") + sleep(2) + map.tap() + + let close = app.buttons["locationKeyInfo.close"] + require(close, "Tapping a saved key's area should show its details") + XCTAssertEqual(close.label, "Close") + close.tap() + XCTAssertTrue(close.waitForNonExistence(timeout: timeout), "Close should dismiss the details") + require(map, "Closing the details should return to the map") + } + @MainActor func testCustomDomainsEditorHiddenWhenToggleOff() { let app = launch(["-uiTestMode", "-uiTestSkipOnboarding"])