Skip to content

Commit 3e39f4c

Browse files
Added possiblity to customize no content icons
1 parent 3912314 commit 3e39f4c

File tree

7 files changed

+35
-9
lines changed

7 files changed

+35
-9
lines changed

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,18 @@ public class Images {
278278
// MARK: - Threads
279279

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

0 commit comments

Comments
 (0)