Skip to content

Commit 9fc5e64

Browse files
Added possiblity to customize no content icons (#740)
1 parent f172363 commit 9fc5e64

File tree

66 files changed

+41
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+41
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public struct FileAttachmentsView: View {
1212

1313
@Injected(\.colors) private var colors
1414
@Injected(\.fonts) private var fonts
15+
@Injected(\.images) private var images
1516

1617
public init(channel: ChatChannel) {
1718
_viewModel = StateObject(
@@ -29,7 +30,7 @@ public struct FileAttachmentsView: View {
2930
LoadingView()
3031
} else if viewModel.attachmentsDataSource.isEmpty {
3132
NoContentView(
32-
imageName: "folder",
33+
image: images.noMedia,
3334
title: L10n.ChatInfo.Files.emptyTitle,
3435
description: L10n.ChatInfo.Files.emptyDesc
3536
)

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/MediaAttachmentsView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import SwiftUI
77

88
/// View displaying media attachments.
99
public struct MediaAttachmentsView: View {
10+
11+
@Injected(\.images) private var images
1012

1113
@StateObject private var viewModel: MediaAttachmentsViewModel
1214

@@ -40,7 +42,7 @@ public struct MediaAttachmentsView: View {
4042
LoadingView()
4143
} else if viewModel.mediaItems.isEmpty {
4244
NoContentView(
43-
imageName: "folder",
45+
image: images.noMedia,
4446
title: L10n.ChatInfo.Media.emptyTitle,
4547
description: L10n.ChatInfo.Media.emptyDesc
4648
)

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import SwiftUI
77

88
/// View displaying pinned messages in the chat info screen.
99
public struct PinnedMessagesView: View {
10+
11+
@Injected(\.images) private var images
1012

1113
@StateObject private var viewModel: PinnedMessagesViewModel
1214

@@ -32,7 +34,7 @@ public struct PinnedMessagesView: View {
3234
}
3335
} else {
3436
NoContentView(
35-
imageName: "message",
37+
image: images.noContent,
3638
title: L10n.ChatInfo.PinnedMessages.emptyTitle,
3739
description: L10n.ChatInfo.PinnedMessages.emptyDesc,
3840
shouldRotateImage: true

Sources/StreamChatSwiftUI/ChatChannelList/NoChannelsView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import SwiftUI
88
///
99
/// Different view can be injected in its place.
1010
public struct NoChannelsView: View {
11+
12+
@Injected(\.images) private var images
1113

1214
public var body: some View {
1315
NoContentView(
14-
imageName: "message",
16+
image: images.noContent,
1517
title: L10n.Channel.NoContent.title,
1618
description: L10n.Channel.NoContent.message,
1719
shouldRotateImage: true

Sources/StreamChatSwiftUI/ChatThreadList/NoThreadsView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import SwiftUI
66

77
/// Default SDK implementation for the view displayed when there are no threads available.
88
public struct NoThreadsView: View {
9+
10+
@Injected(\.images) private var images
911

1012
public init() {}
1113

1214
public var body: some View {
1315
NoContentView(
14-
imageName: "text.bubble",
16+
image: images.noThreads,
1517
title: nil,
1618
description: L10n.Thread.NoContent.message,
1719
shouldRotateImage: false

Sources/StreamChatSwiftUI/CommonViews/NoContentView.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ struct NoContentView: View {
1010
@Injected(\.fonts) private var fonts
1111
@Injected(\.colors) private var colors
1212

13-
var imageName: String
13+
var image: UIImage
1414
var title: String?
1515
var description: String
1616
var shouldRotateImage: Bool = false
17+
var size: CGSize = CGSize(width: 100, height: 100)
1718

1819
public var body: some View {
1920
VStack(spacing: 8) {
2021
Spacer()
2122

2223
VStack(spacing: 8) {
23-
Image(systemName: imageName)
24+
Image(uiImage: image)
25+
.resizable()
26+
.renderingMode(.template)
27+
.aspectRatio(contentMode: .fit)
28+
.frame(width: size.width, height: size.height)
2429
.rotation3DEffect(
2530
shouldRotateImage ? .degrees(180) : .zero, axis: (x: 0, y: 1, z: 0)
2631
)
27-
.aspectRatio(contentMode: .fit)
28-
.font(.system(size: 100))
2932
.foregroundColor(Color(colors.textLowEmphasis))
3033
title.map { Text($0) }
3134
.font(fonts.bodyBold)

Sources/StreamChatSwiftUI/Images.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,19 @@ public class Images {
278278
// MARK: - Threads
279279

280280
public var threadIcon: UIImage = UIImage(systemName: "text.bubble")!
281+
282+
// MARK: - No Content Icons
283+
284+
public var noContent: UIImage = UIImage(
285+
systemName: "message",
286+
withConfiguration: UIImage.SymbolConfiguration(pointSize: 100, weight: .regular)
287+
) ?? UIImage.circleImage
288+
public var noMedia: UIImage = UIImage(
289+
systemName: "folder",
290+
withConfiguration: UIImage.SymbolConfiguration(pointSize: 100, weight: .regular)
291+
) ?? UIImage.circleImage
292+
public var noThreads: UIImage = UIImage(
293+
systemName: "text.bubble",
294+
withConfiguration: UIImage.SymbolConfiguration(pointSize: 100, weight: .regular)
295+
) ?? UIImage.circleImage
281296
}

StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/FileAttachmentsView_Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class FileAttachmentsView_Tests: StreamChatTestCase {
4242
.applyDefaultSize()
4343

4444
// Then
45-
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
45+
AssertSnapshot(view, size: defaultScreenSize)
4646
}
4747

4848
func test_fileAttachmentsView_loadingSnapshot() {

StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/MediaAttachmentsView_Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class MediaAttachmentsView_Tests: StreamChatTestCase {
4343
.applyDefaultSize()
4444

4545
// Then
46-
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
46+
AssertSnapshot(view, size: .defaultAvatarSize)
4747
}
4848

4949
func test_mediaAttachmentsView_loading() {

0 commit comments

Comments
 (0)