Skip to content

Commit 44b22f5

Browse files
authored
Use navigation bar appearance in GalleryHeaderView (#942)
1 parent e78a4bf commit 44b22f5

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

Sources/StreamChatSwiftUI/CommonViews/GalleryHeaderView.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,38 @@ struct GalleryHeaderView: View {
2727
.frame(height: 16)
2828
}
2929
.padding()
30-
.foregroundColor(Color(colors.text))
30+
.foregroundColor(closeImageColor)
3131

3232
Spacer()
3333
}
3434

3535
VStack {
3636
Text(title)
3737
.font(fonts.bodyBold)
38+
.foregroundColor(Color(colors.navigationBarTitle))
3839
Text(subtitle)
3940
.font(fonts.footnote)
40-
.foregroundColor(Color(colors.textLowEmphasis))
41+
.foregroundColor(Color(colors.navigationBarSubtitle))
4142
}
4243
}
44+
.modifier(GalleryHeaderViewAppearanceViewModifier())
45+
}
46+
47+
private var closeImageColor: Color {
48+
// Note that default design uses `text` color
49+
guard colors.navigationBarTintColor != colors.tintColor else { return Color(colors.text) }
50+
return colors.navigationBarTintColor
51+
}
52+
}
53+
54+
private struct GalleryHeaderViewAppearanceViewModifier: ViewModifier {
55+
@Injected(\.colors) var colors
56+
57+
func body(content: Content) -> some View {
58+
if let backgroundColor = colors.navigationBarBackground {
59+
content.background(Color(backgroundColor).edgesIgnoringSafeArea(.top))
60+
} else {
61+
content
62+
}
4363
}
4464
}

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
402C54492B6AAC0100672BFB /* StreamChatSwiftUI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1212
4F03F18F2E0140C6001C71A2 /* ChannelAvatarsMerger_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F03F18E2E0140C6001C71A2 /* ChannelAvatarsMerger_Tests.swift */; };
1313
4F077EF82C85E05700F06D83 /* DelayedRenderingViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F077EF72C85E05700F06D83 /* DelayedRenderingViewModifier.swift */; };
14+
4F0B67C92E7025B6003DA844 /* GalleryHeaderView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0B67C82E7025B6003DA844 /* GalleryHeaderView_Tests.swift */; };
1415
4F198FDD2C0480EC00148F49 /* Publisher+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F198FDC2C0480EC00148F49 /* Publisher+Extensions.swift */; };
1516
4F3536942E6EFB510046678E /* NavigationBarBackgroundViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F3536932E6EFB4B0046678E /* NavigationBarBackgroundViewModifier.swift */; };
1617
4F65F1862D06EEA7009F69A8 /* ChooseChannelQueryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F65F1852D06EEA5009F69A8 /* ChooseChannelQueryView.swift */; };
@@ -616,6 +617,7 @@
616617
4A65451E274BA170003C5FA8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
617618
4F03F18E2E0140C6001C71A2 /* ChannelAvatarsMerger_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelAvatarsMerger_Tests.swift; sourceTree = "<group>"; };
618619
4F077EF72C85E05700F06D83 /* DelayedRenderingViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelayedRenderingViewModifier.swift; sourceTree = "<group>"; };
620+
4F0B67C82E7025B6003DA844 /* GalleryHeaderView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryHeaderView_Tests.swift; sourceTree = "<group>"; };
619621
4F198FDC2C0480EC00148F49 /* Publisher+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publisher+Extensions.swift"; sourceTree = "<group>"; };
620622
4F3536932E6EFB4B0046678E /* NavigationBarBackgroundViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarBackgroundViewModifier.swift; sourceTree = "<group>"; };
621623
4F65F1852D06EEA5009F69A8 /* ChooseChannelQueryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChooseChannelQueryView.swift; sourceTree = "<group>"; };
@@ -1225,6 +1227,7 @@
12251227
isa = PBXGroup;
12261228
children = (
12271229
4F6D83532C1094220098C298 /* AlertBannerViewModifier_Tests.swift */,
1230+
4F0B67C82E7025B6003DA844 /* GalleryHeaderView_Tests.swift */,
12281231
);
12291232
path = CommonViews;
12301233
sourceTree = "<group>";
@@ -3073,6 +3076,7 @@
30733076
8423C346277D9BFF0092DCF1 /* TestCommandsConfig.swift in Sources */,
30743077
84B2B5D82819778D00479CEE /* FileAttachmentsViewModel_Tests.swift in Sources */,
30753078
4F6D83352C0F05040098C298 /* PollCommentsViewModel_Tests.swift in Sources */,
3079+
4F0B67C92E7025B6003DA844 /* GalleryHeaderView_Tests.swift in Sources */,
30763080
841B2EF6278F108700ED619E /* MessageReadIndicatorView_Tests.swift in Sources */,
30773081
84CC3732290B0A4000689B73 /* StreamChatModel.xcdatamodeld in Sources */,
30783082
84E04790284A444E00BAFA17 /* CDNClient_Mock.swift in Sources */,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Copyright © 2025 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import SnapshotTesting
6+
@testable import StreamChat
7+
@testable import StreamChatSwiftUI
8+
import SwiftUI
9+
import XCTest
10+
11+
final class GalleryHeaderView_Tests: StreamChatTestCase {
12+
let size = CGSize(width: 300, height: 60)
13+
14+
func test_default_snapshot() {
15+
// When
16+
let view = GalleryHeaderView(title: "Title", subtitle: "Subtitle", isShown: .constant(false))
17+
.applySize(size)
18+
19+
// Then
20+
AssertSnapshot(view, variants: [.defaultLight], size: size)
21+
}
22+
23+
func test_customized_snapshot() {
24+
// When
25+
customizedNavigationBarAppearance()
26+
let view = GalleryHeaderView(title: "Title", subtitle: "Subtitle", isShown: .constant(false))
27+
.applySize(size)
28+
29+
// Then
30+
AssertSnapshot(view, variants: [.defaultLight], size: size)
31+
}
32+
}
3.26 KB
Loading
3.03 KB
Loading

0 commit comments

Comments
 (0)