From 9fd8be45f8d0b0e8636ad7d2b5064d689d2cf0e6 Mon Sep 17 00:00:00 2001 From: Stephen Cooper <1970249+scooper4711@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:37:35 +0100 Subject: [PATCH 1/2] fix: Keep the iPhone on the sidebar after Back from the library --- .../ScrollkeeperUI/Views/LibraryWindow.swift | 2 +- .../ScrollkeeperUI/Views/SidebarView.swift | 28 +++++++++++++++---- ios/UITests/PhoneLayoutUITests.swift | 22 +++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Sources/ScrollkeeperUI/Views/LibraryWindow.swift b/Sources/ScrollkeeperUI/Views/LibraryWindow.swift index 3ec0a96..2863d10 100644 --- a/Sources/ScrollkeeperUI/Views/LibraryWindow.swift +++ b/Sources/ScrollkeeperUI/Views/LibraryWindow.swift @@ -50,7 +50,7 @@ struct LibraryWindow: View { var body: some View { @Bindable var store = store NavigationSplitView { - SidebarView() + SidebarView(showsOneColumn: showsOneColumn) .navigationSplitViewColumnWidth(min: 190, ideal: 220) } detail: { catalog diff --git a/Sources/ScrollkeeperUI/Views/SidebarView.swift b/Sources/ScrollkeeperUI/Views/SidebarView.swift index ef67670..be0ddf9 100644 --- a/Sources/ScrollkeeperUI/Views/SidebarView.swift +++ b/Sources/ScrollkeeperUI/Views/SidebarView.swift @@ -3,11 +3,15 @@ import SwiftUI /// The scopes of the library with their title counts. struct SidebarView: View { + /// Whether the window shows one column at a time, as on an iPhone, where the sidebar is a page of its own. + let showsOneColumn: Bool @Environment(LibraryStore.self) private var store + /// Set when Back leaves the library for the sidebar on an iPhone. The scope is kept, so the library still + /// shows it, but the list shows no selection: a selection there would open the library again. + @State private var isShowingSidebarAlone = false var body: some View { - @Bindable var store = store - List(selection: scopeSelection($store.query.scope)) { + List(selection: scopeSelection) { Section("Library") { row(.all, "All Titles", symbol: "books.vertical") row(.downloaded, "Downloaded", symbol: "arrow.down.circle") @@ -31,6 +35,8 @@ struct SidebarView: View { } } .listStyle(.sidebar) + // The layout can widen, as when an iPad leaves Slide Over, and then the list shows the scope again. + .onChange(of: showsOneColumn) { isShowingSidebarAlone = false } } private func row(_ scope: LibraryScope, _ title: String, symbol: String) -> some View { @@ -39,8 +45,20 @@ struct SidebarView: View { .tag(scope) } - /// The list needs an optional selection; an emptied selection falls back to all titles. - private func scopeSelection(_ scope: Binding) -> Binding { - Binding(get: { scope.wrappedValue }, set: { scope.wrappedValue = $0 ?? .all }) + /// The list needs an optional selection. An emptied selection means Back on an iPhone, which shows the sidebar; + /// elsewhere it falls back to all titles. + private var scopeSelection: Binding { + Binding(get: { isShowingSidebarAlone ? nil : store.query.scope }, set: choose) + } + + private func choose(_ scope: LibraryScope?) { + if let scope { + isShowingSidebarAlone = false + store.query.scope = scope + } else if showsOneColumn { + isShowingSidebarAlone = true + } else { + store.query.scope = .all + } } } diff --git a/ios/UITests/PhoneLayoutUITests.swift b/ios/UITests/PhoneLayoutUITests.swift index ed5d535..92ce585 100644 --- a/ios/UITests/PhoneLayoutUITests.swift +++ b/ios/UITests/PhoneLayoutUITests.swift @@ -34,6 +34,28 @@ final class PhoneLayoutUITests: XCTestCase { XCTAssertTrue(app.buttons["View on paizo.com"].waitForExistence(timeout: 5), app.debugDescription) } + /// Back from the library shows the sidebar and stays there, rather than bouncing back to All Titles. + @MainActor + func testBackFromTheLibraryStaysOnTheSidebar() { + launchDemo(viewMode: "covers") + + goBackToTheSidebar(from: "All Titles") + app.staticTexts["Rulebooks"].firstMatch.tap() + XCTAssertTrue(app.navigationBars["Rulebooks"].waitForExistence(timeout: 5), app.debugDescription) + goBackToTheSidebar(from: "Rulebooks") + } + + @MainActor + private func goBackToTheSidebar(from scope: String) { + let library = app.navigationBars[scope] + library.buttons["Back"].tap() + XCTAssertTrue(library.waitForNonExistence(timeout: 5), app.debugDescription) + // The bounce came a moment after the sidebar appeared, so check that the library does not come back. + XCTAssertFalse(app.navigationBars["All Titles"].waitForExistence(timeout: 3), + "went back to the library: \(app.debugDescription)") + XCTAssertTrue(app.staticTexts["Downloaded"].firstMatch.isHittable, app.debugDescription) + } + @MainActor private func launchDemo(viewMode: String?) { app = XCUIApplication() From 984fc2953f25c255136da85acdca7958b15fd027 Mon Sep 17 00:00:00 2001 From: Stephen Cooper <1970249+scooper4711@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:42:53 +0100 Subject: [PATCH 2/2] fix: Work around a Swift 6.3 compiler crash in the sidebar CI's Xcode 26.6 (Swift 6.3.3) crashed in IRGen on a method-reference setter in SidebarView. Use a closure instead. --- Sources/ScrollkeeperUI/Views/SidebarView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/ScrollkeeperUI/Views/SidebarView.swift b/Sources/ScrollkeeperUI/Views/SidebarView.swift index be0ddf9..f5a907a 100644 --- a/Sources/ScrollkeeperUI/Views/SidebarView.swift +++ b/Sources/ScrollkeeperUI/Views/SidebarView.swift @@ -48,7 +48,8 @@ struct SidebarView: View { /// The list needs an optional selection. An emptied selection means Back on an iPhone, which shows the sidebar; /// elsewhere it falls back to all titles. private var scopeSelection: Binding { - Binding(get: { isShowingSidebarAlone ? nil : store.query.scope }, set: choose) + // A closure, not `set: choose`: Swift 6.3's compiler crashes generating the method reference's thunk. + Binding(get: { isShowingSidebarAlone ? nil : store.query.scope }, set: { choose($0) }) } private func choose(_ scope: LibraryScope?) {