Make the space list bloom height match the room list. (#4585)

This commit is contained in:
Doug
2025-10-07 12:52:12 +01:00
committed by GitHub
parent c03ed528ba
commit 6def8e5973
14 changed files with 82 additions and 8 deletions
@@ -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 😄
}
}
}