diff --git a/AccessibilityTests/Sources/GeneratedAccessibilityTests.swift b/AccessibilityTests/Sources/GeneratedAccessibilityTests.swift index e3b08b1f7..babbe67f3 100644 --- a/AccessibilityTests/Sources/GeneratedAccessibilityTests.swift +++ b/AccessibilityTests/Sources/GeneratedAccessibilityTests.swift @@ -63,6 +63,10 @@ extension AccessibilityTests { try await performAccessibilityAudit(named: "BlockedUsersScreen_Previews") } + func testBloomModifier() async throws { + try await performAccessibilityAudit(named: "BloomModifier_Previews") + } + func testBugReportScreen() async throws { try await performAccessibilityAudit(named: "BugReportScreen_Previews") } diff --git a/ElementX/Sources/Other/TestablePreview/TestablePreviewsDictionary.swift b/ElementX/Sources/Other/TestablePreview/TestablePreviewsDictionary.swift index 66cc03005..5ccf1c20a 100644 --- a/ElementX/Sources/Other/TestablePreview/TestablePreviewsDictionary.swift +++ b/ElementX/Sources/Other/TestablePreview/TestablePreviewsDictionary.swift @@ -23,6 +23,7 @@ enum TestablePreviewsDictionary { "BadgeLabel_Previews" : BadgeLabel_Previews.self, "BigIcon_Previews" : BigIcon_Previews.self, "BlockedUsersScreen_Previews" : BlockedUsersScreen_Previews.self, + "BloomModifier_Previews" : BloomModifier_Previews.self, "BugReportScreen_Previews" : BugReportScreen_Previews.self, "CallInviteRoomTimelineView_Previews" : CallInviteRoomTimelineView_Previews.self, "CallNotificationRoomTimelineView_Previews" : CallNotificationRoomTimelineView_Previews.self, diff --git a/ElementX/Sources/Screens/HomeScreen/View/BloomModifier.swift b/ElementX/Sources/Screens/HomeScreen/View/BloomModifier.swift index e4f2fb382..b4a0fa992 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/BloomModifier.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/BloomModifier.swift @@ -11,19 +11,25 @@ import SwiftUI import SwiftUIIntrospect extension View { - @ViewBuilder - func bloom() -> some View { + /// Adds a bloom behind the navigation bar. + /// - Parameter hasSearchBar: Whether or not the navigation bar contains a search bar (so that + /// the bloom can be sized appropriately). + @ViewBuilder func toolbarBloom(hasSearchBar: Bool) -> some View { if #available(iOS 26, *) { - modifier(BloomModifier()) + modifier(BloomModifier(hasSearchBar: hasSearchBar)) } else { - modifier(OldBloomModifier()) + modifier(OldBloomModifier(hasSearchBar: hasSearchBar)) } } } private struct BloomModifier: ViewModifier { + let hasSearchBar: Bool + @State private var height = CGFloat.zero + private var endPointY: CGFloat { hasSearchBar ? 0.35 : 0.5 } + func body(content: Content) -> some View { content .onGeometryChange(for: CGFloat.self) { proxy in @@ -34,7 +40,7 @@ private struct BloomModifier: ViewModifier { .overlay(alignment: .top) { LinearGradient(gradient: .compound.subtle, startPoint: .top, - endPoint: .init(x: 0.5, y: 0.35)) + endPoint: .init(x: 0.5, y: endPointY)) .ignoresSafeArea(edges: .all) .frame(height: height) .allowsHitTesting(false) @@ -47,6 +53,8 @@ private struct BloomModifier: ViewModifier { private struct OldBloomModifier: ViewModifier { @Environment(\.colorScheme) private var colorScheme + let hasSearchBar: Bool + @State private var standardAppearance = UINavigationBarAppearance() @State private var scrollEdgeAppearance = UINavigationBarAppearance() @@ -93,10 +101,12 @@ private struct OldBloomModifier: ViewModifier { return bloom } + private var endPointY: CGFloat { hasSearchBar ? 0.5 : 0.7 } + private var bloomGradient: some View { LinearGradient(gradient: .compound.subtle, startPoint: .top, - endPoint: .init(x: 0.5, y: 0.7)) + endPoint: .init(x: 0.5, y: endPointY)) .ignoresSafeArea(edges: .all) .frame(width: 256, height: 256) } @@ -115,3 +125,32 @@ private struct OldBloomModifier: ViewModifier { var baseColor: Color? } } + +// MARK: - Previews + +struct BloomModifier_Previews: PreviewProvider, TestablePreview { + static var previews: some View { + NavigationStack { + mockScreen + .navigationTitle(L10n.screenRoomlistMainSpaceTitle) + .searchable(text: .constant(""), placement: .navigationBarDrawer(displayMode: .always)) + .toolbarBloom(hasSearchBar: true) + } + .previewDisplayName("Chats") + + NavigationStack { + mockScreen + .navigationTitle(L10n.screenSpaceListTitle) + .toolbarBloom(hasSearchBar: false) + } + .previewDisplayName("Spaces") + } + + static var mockScreen: some View { + List { } + .toolbar { + Button { } label: { CompoundIcon(\.check) } + .accessibilityLabel(L10n.actionConfirm) // Keep the a11y tests happy 😄 + } + } +} diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift index 649f64d29..1812fa8a4 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift @@ -25,7 +25,7 @@ struct HomeScreen: View { .toolbar { toolbar } .background(Color.compound.bgCanvasDefault.ignoresSafeArea()) .track(screen: .Home) - .bloom() + .toolbarBloom(hasSearchBar: true) .sentryTrace("\(Self.self)") } diff --git a/ElementX/Sources/Screens/Spaces/SpaceListScreen/View/SpaceListScreen.swift b/ElementX/Sources/Screens/Spaces/SpaceListScreen/View/SpaceListScreen.swift index 120c12082..07fa44c07 100644 --- a/ElementX/Sources/Screens/Spaces/SpaceListScreen/View/SpaceListScreen.swift +++ b/ElementX/Sources/Screens/Spaces/SpaceListScreen/View/SpaceListScreen.swift @@ -22,7 +22,7 @@ struct SpaceListScreen: View { .navigationBarTitleDisplayMode(.inline) .toolbar { toolbar } .background(Color.compound.bgCanvasDefault.ignoresSafeArea()) - .bloom() + .toolbarBloom(hasSearchBar: true) .onAppear { context.send(viewAction: .screenAppeared) } .sheet(isPresented: $context.isPresentingFeatureAnnouncement) { SpacesAnnouncementSheetView(context: context) diff --git a/PreviewTests/Sources/GeneratedPreviewTests.swift b/PreviewTests/Sources/GeneratedPreviewTests.swift index 6bec2a291..e3faecfbc 100644 --- a/PreviewTests/Sources/GeneratedPreviewTests.swift +++ b/PreviewTests/Sources/GeneratedPreviewTests.swift @@ -95,6 +95,12 @@ extension PreviewTests { } } + func testBloomModifier() async throws { + for (index, preview) in BloomModifier_Previews._allPreviews.enumerated() { + try await assertSnapshots(matching: preview, step: index) + } + } + func testBugReportScreen() async throws { for (index, preview) in BugReportScreen_Previews._allPreviews.enumerated() { try await assertSnapshots(matching: preview, step: index) diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPad-en-GB.png new file mode 100644 index 000000000..ce153c427 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPad-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:158498fc55b72583eddb12a90533550bc4311ab5421c087d66147dcbe91333a7 +size 115492 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPad-pseudo.png new file mode 100644 index 000000000..a8d09de57 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPad-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57a4f1a8ca8f11a67078c3263e3c560666dcdf572c0db5695a8c1384557019db +size 115791 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPhone-16-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPhone-16-en-GB.png new file mode 100644 index 000000000..0d79e952a --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPhone-16-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3346489010c047b4286e29afd4113880342d1b73e99e8d1390e2c448863c362e +size 52946 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPhone-16-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPhone-16-pseudo.png new file mode 100644 index 000000000..7998fd7e7 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Chats-iPhone-16-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:988d6d27125778fde9a803e8099a6f13c287dede58a2a6244883377ea1076375 +size 54858 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPad-en-GB.png new file mode 100644 index 000000000..1a8629313 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPad-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b35be286bc9ca52ad0e02cb0bee9c9b72973a3968eee457d4c584ccf23ff633 +size 112203 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPad-pseudo.png new file mode 100644 index 000000000..1a8629313 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPad-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b35be286bc9ca52ad0e02cb0bee9c9b72973a3968eee457d4c584ccf23ff633 +size 112203 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPhone-16-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPhone-16-en-GB.png new file mode 100644 index 000000000..6c3e2d9a2 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPhone-16-en-GB.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:23f8d1c80181c9634198ae5488cb665e606db61d363d0ebe6e54644fc2ff2a55 +size 50960 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPhone-16-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPhone-16-pseudo.png new file mode 100644 index 000000000..d36d8bfdb --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/bloomModifier.Spaces-iPhone-16-pseudo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb3072779e29a9f67a8f580c7c07f46c0ab11e603605ce1fef31d6d502df2a0b +size 51525