diff --git a/AGENTS.md b/AGENTS.md index 74d68545b..fb182acd7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -278,6 +278,7 @@ Services = where product-level opinions live (Rust SDK stays spec-faithful). - Need 2+ from it? Pass `userSession` down. Need 1? Pass that one direct. - Receiver may store only pieces it need (e.g. `clientProxy`, `userSettings`). - Never pass `userSession` plus value it already owns (e.g. `userSession` + `userSettings`). +- Singletons (`static let shared`) last resort. --- diff --git a/ElementX/Sources/Other/SwiftUI/Views/RoomHeaderView.swift b/ElementX/Sources/Other/SwiftUI/Views/RoomHeaderView.swift index 8c48d5622..a10752487 100644 --- a/ElementX/Sources/Other/SwiftUI/Views/RoomHeaderView.swift +++ b/ElementX/Sources/Other/SwiftUI/Views/RoomHeaderView.swift @@ -9,6 +9,7 @@ import Combine import Compound import SwiftUI +import SwiftUIIntrospect struct RoomHeaderView: View { struct DMRecipientDetails { @@ -126,6 +127,70 @@ private extension View { } } +extension View { + // TODO: Remove this workaround once Apple fixes the bug. + /// Works around an iOS 26+ bug where cancelling the interactive pop gesture leaves the `RoomHeaderView` + /// at its full width, covering the trailing toolbar items. Apply it to every screen using the header as its title. + @ViewBuilder + func fixesTitleViewOnCancelledPop() -> some View { + if #available(iOS 26, *) { + modifier(CancelledPopTitleViewFixModifier()) + } else { + self + } + } +} + +@available(iOS 26, *) +private struct CancelledPopTitleViewFixModifier: ViewModifier { + // Gesture recognizers don't retain their targets, so the view keeps the fix alive. + @State private var fix = CancelledPopTitleViewFix() + + func body(content: Content) -> some View { + content + .introspect(.navigationStack, on: .supportedVersions, scope: .ancestor) { [fix] navigationController in + fix.observe(navigationController) + } + } +} + +@available(iOS 26, *) +private final class CancelledPopTitleViewFix: NSObject { + private weak var navigationController: UINavigationController? + + isolated deinit { + stopObserving() + } + + func observe(_ navigationController: UINavigationController) { + guard navigationController !== self.navigationController else { return } + + stopObserving() + self.navigationController = navigationController + navigationController.interactivePopGestureRecognizer?.addTarget(self, action: #selector(popGestureChanged)) + navigationController.interactiveContentPopGestureRecognizer?.addTarget(self, action: #selector(popGestureChanged)) + } + + @objc private func popGestureChanged(_ gesture: UIGestureRecognizer) { + guard gesture.state == .began, + let navigationController, + let transitionCoordinator = navigationController.transitionCoordinator else { + return + } + + transitionCoordinator.animate(alongsideTransition: nil) { context in + guard context.isCancelled else { return } + // UIKit restores the title view's container but never lays the title view out inside it again. + navigationController.navigationBar.topItem?.titleView?.superview?.setNeedsLayout() + } + } + + private func stopObserving() { + navigationController?.interactivePopGestureRecognizer?.removeTarget(self, action: #selector(popGestureChanged)) + navigationController?.interactiveContentPopGestureRecognizer?.removeTarget(self, action: #selector(popGestureChanged)) + } +} + // MARK: - Previews struct RoomHeaderView_Previews: PreviewProvider, TestablePreview { diff --git a/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift b/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift index 02940f891..05d9f773a 100644 --- a/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift +++ b/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift @@ -41,6 +41,7 @@ struct JoinRoomScreen: View { .background() .backgroundStyle(.compound.bgCanvasDefault) .toolbarRole(RoomHeaderView.toolbarRole) + .fixesTitleViewOnCancelledPop() .navigationBarTitleDisplayMode(.inline) .toolbar { toolbar } .shouldScrollOnKeyboardDidShow(focus == .knockMessage, to: Focus.knockMessage) diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift index f07f01770..9dcdfd284 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift @@ -119,6 +119,7 @@ struct RoomScreen: View { } .navigationBarBackButtonHidden(isMessageSelectionActive) .toolbarRole(RoomHeaderView.toolbarRole) + .fixesTitleViewOnCancelledPop() .navigationTitle(L10n.screenRoomTitle) // Hidden but used for back button text. .navigationBarTitleDisplayMode(.inline) .toolbar { toolbar } diff --git a/ElementX/Sources/Screens/Spaces/SpaceScreen/View/SpaceScreen.swift b/ElementX/Sources/Screens/Spaces/SpaceScreen/View/SpaceScreen.swift index 9426d8bfb..9e864a122 100644 --- a/ElementX/Sources/Screens/Spaces/SpaceScreen/View/SpaceScreen.swift +++ b/ElementX/Sources/Screens/Spaces/SpaceScreen/View/SpaceScreen.swift @@ -34,6 +34,7 @@ struct SpaceScreen: View { .environment(\.editMode, .constant(context.viewState.editMode)) .background(Color.compound.bgCanvasDefault.ignoresSafeArea()) .toolbarRole(RoomHeaderView.toolbarRole) + .fixesTitleViewOnCancelledPop() .navigationTitle(context.viewState.space.name) .navigationBarTitleDisplayMode(.inline) .navigationBarBackButtonHidden(isEditModeActive) diff --git a/ElementX/Sources/Screens/ThreadTimelineScreen/View/ThreadTimelineScreen.swift b/ElementX/Sources/Screens/ThreadTimelineScreen/View/ThreadTimelineScreen.swift index 99012d421..eba01b8ff 100644 --- a/ElementX/Sources/Screens/ThreadTimelineScreen/View/ThreadTimelineScreen.swift +++ b/ElementX/Sources/Screens/ThreadTimelineScreen/View/ThreadTimelineScreen.swift @@ -26,6 +26,7 @@ struct ThreadTimelineScreen: View { TimelineView(timelineContext: timelineContext) .background(.compound.bgCanvasDefault) .toolbarRole(RoomHeaderView.toolbarRole) + .fixesTitleViewOnCancelledPop() .navigationTitle(L10n.commonThread) .navigationBarTitleDisplayMode(.inline) .toolbar { toolbar } diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.Managing-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.Managing-iPad-en-GB.png index cc3d7581f..e6528e77d 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.Managing-iPad-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.Managing-iPad-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:85113d4366fe0a216b13f93d81b9cd0cb05c3b57f01c2448fdecae274208c3f9 -size 136916 +oid sha256:adc5894a3f81afad0d0aae4da68ec830dc04fa642c4c106ef2916bc0bb35accf +size 138773 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.Managing-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.Managing-iPad-pseudo.png index 83b5f0538..9caa7507d 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.Managing-iPad-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.Managing-iPad-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:635a9c95bb85a57b2bfa61a311003cb3c126d08c0e1312b563924a03dd429bf5 -size 153028 +oid sha256:2c3b66df7286ecfb96002b82b19b545bdf924f8363beaba882157ca11719610c +size 153534 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPad-en-GB.png index 7f186e75c..77d22c820 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPad-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPad-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:aea34376a5f654c81e617afc9dde8db2b937dd6ad5c5325cf57595aaa5badae7 -size 139039 +oid sha256:ff7bc72fa95d4cea38b41795a891f7714dbbfab6d67b46766e0c6320d6ba13b5 +size 139115 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPad-pseudo.png index 684111862..0f99c1026 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPad-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPad-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f3588bb282fb61e1a23e7724dff228d5356085fff7365e39cd8479e88e9e900f -size 146835 +oid sha256:6358e49c5b4d74e8d8ad2371c6b08056693f263bc7066d077c5c9f7b16281e54 +size 143920 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPhone-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPhone-en-GB.png index 6514d5eb0..01fdbfc55 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPhone-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPhone-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8deb8cc0ccdc283a17e3d48fdb024426b21f51b793076f0732c69c877a38cbd9 -size 92528 +oid sha256:ec36e9f75c5967ce57ae49490605a76efbba765cfa59cf383bf3379bf72d5e9a +size 92159 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPhone-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPhone-pseudo.png index 47d0a67df..99b348998 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPhone-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.New-Space-iPhone-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d70a5c7a99ae93495b05fdd5f6edba02f063a55b08de9e1b04ac633f21e218f -size 105212 +oid sha256:7170c60bfe684b34bccdc3f6c183f830312b2064ff0b5965f623944671519553 +size 104896 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPad-en-GB-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPad-en-GB-0.png index 7944af69d..a5d9eb262 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPad-en-GB-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPad-en-GB-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4d891d0e77b960bc225dd22e6949ad4948249057c587b93ff5af338d0eefb03c -size 235058 +oid sha256:cd484d0701e7e574c406edd7c94dead0ac7986ab8a34f3bfa9c469edf494db22 +size 235204 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPad-pseudo-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPad-pseudo-0.png index 08777f82f..c48f377cc 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPad-pseudo-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPad-pseudo-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0824909c9063d94e2b9fa212f25c1e6132cb3e73388fb7f0d85a035b3a4061f1 -size 266916 +oid sha256:a24d75b529762a00b3df4ccb3dca9d9ec1c88b4a8b5d1b031977ea1998e1662c +size 260942 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPhone-en-GB-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPhone-en-GB-0.png index 2ccfb64fb..85ea9d02b 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPhone-en-GB-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPhone-en-GB-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e9f79f0f119a77b1659aa33b8f002e0485cf79475f033073b5e4cd19ff861589 -size 177370 +oid sha256:8370211a447162279955b9c68fc31ee18e6d3bb014cde5b01ab574eda04672b7 +size 176891 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPhone-pseudo-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPhone-pseudo-0.png index 3aa89980c..977a124cb 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPhone-pseudo-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/spaceScreen.iPhone-pseudo-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e46c14eac78312f2062f40eb2d9a7833b3fafe3e18d6bd075804db613a05b5bb -size 202083 +oid sha256:063206bb855eadc5586a007d4f55b2e114305e0009bec9a67c3dc0e2ea71d8df +size 201669