Skip to content

Commit a7f2f41

Browse files
authored
Show attachment title instead of URL in the file attachment preview view (#930)
1 parent 3525230 commit a7f2f41

File tree

7 files changed

+39
-7
lines changed

7 files changed

+39
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6-
### 🔄 Changed
6+
### 🐞 Fixed
7+
- Show attachment title instead of URL in the `FileAttachmentPreview` view [#930](https://github.com/GetStream/stream-chat-swiftui/pull/930)
78

89
# [4.86.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.86.0)
910
_August 21, 2025_

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public struct FileAttachmentsView: View {
6060
.padding(.vertical)
6161
}
6262
.sheet(item: $viewModel.selectedAttachment) { item in
63-
FileAttachmentPreview(url: item.assetURL)
63+
FileAttachmentPreview(title: item.title, url: item.assetURL)
6464
}
6565

6666
Divider()

Sources/StreamChatSwiftUI/ChatChannel/MessageList/FileAttachmentPreview.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@ public struct FileAttachmentPreview: View {
1616
utils.fileCDN
1717
}
1818

19+
let title: String?
1920
var url: URL
2021

2122
@State private var adjustedUrl: URL?
2223
@State private var isLoading = false
23-
@State private var title: String?
24+
@State private var webViewTitle: String?
2425
@State private var error: Error?
25-
26+
27+
var navigationTitle: String {
28+
if let title, !title.isEmpty { return title }
29+
if let webViewTitle, !webViewTitle.isEmpty { return webViewTitle }
30+
return url.absoluteString
31+
}
32+
2633
public var body: some View {
2734
NavigationView {
2835
ZStack {
@@ -35,7 +42,7 @@ public struct FileAttachmentPreview: View {
3542
WebView(
3643
url: adjustedUrl,
3744
isLoading: $isLoading,
38-
title: $title,
45+
title: $webViewTitle,
3946
error: $error
4047
)
4148
}
@@ -58,7 +65,7 @@ public struct FileAttachmentPreview: View {
5865
.navigationBarTitleDisplayMode(.inline)
5966
.toolbar {
6067
ToolbarItem(placement: .principal) {
61-
Text(title ?? url.absoluteString)
68+
Text(navigationTitle)
6269
.font(fonts.bodyBold)
6370
.lineLimit(1)
6471
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/FileAttachmentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public struct FileAttachmentView: View {
109109
.roundWithBorder()
110110
.withUploadingStateIndicator(for: attachment.uploadingState, url: attachment.assetURL)
111111
.sheet(isPresented: $fullScreenShown) {
112-
FileAttachmentPreview(url: attachment.assetURL)
112+
FileAttachmentPreview(title: attachment.title, url: attachment.assetURL)
113113
}
114114
.accessibilityIdentifier("FileAttachmentView")
115115
}

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
4FD3592A2C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD359292C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift */; };
3333
4FD964622D353D88001B6838 /* FilePickerView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD964612D353D82001B6838 /* FilePickerView_Tests.swift */; };
3434
4FEAB3182BFF71F70057E511 /* SwiftUI+UIAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEAB3172BFF71F70057E511 /* SwiftUI+UIAlertController.swift */; };
35+
4FEDF72B2E5DB03D00CE2676 /* FileAttachmentPreview_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEDF72A2E5DB03D00CE2676 /* FileAttachmentPreview_Tests.swift */; };
3536
8205B4142AD41CC700265B84 /* StreamSwiftTestHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = 8205B4132AD41CC700265B84 /* StreamSwiftTestHelpers */; };
3637
8205B4182AD4267200265B84 /* StreamSwiftTestHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = 8205B4172AD4267200265B84 /* StreamSwiftTestHelpers */; };
3738
820A61A029D6D78E002257FB /* QuotedReply_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 820A619F29D6D78E002257FB /* QuotedReply_Tests.swift */; };
@@ -635,6 +636,7 @@
635636
4FD359292C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollViewModel_Tests.swift; sourceTree = "<group>"; };
636637
4FD964612D353D82001B6838 /* FilePickerView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilePickerView_Tests.swift; sourceTree = "<group>"; };
637638
4FEAB3172BFF71F70057E511 /* SwiftUI+UIAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftUI+UIAlertController.swift"; sourceTree = "<group>"; };
639+
4FEDF72A2E5DB03D00CE2676 /* FileAttachmentPreview_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileAttachmentPreview_Tests.swift; sourceTree = "<group>"; };
638640
820A619F29D6D78E002257FB /* QuotedReply_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotedReply_Tests.swift; sourceTree = "<group>"; };
639641
825AADF3283CCDB000237498 /* ThreadPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadPage.swift; sourceTree = "<group>"; };
640642
829AB4D128578ACF002DC629 /* StreamTestCase+Tags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StreamTestCase+Tags.swift"; sourceTree = "<group>"; };
@@ -2001,6 +2003,7 @@
20012003
84B2B5D528196FD100479CEE /* MediaAttachmentsView_Tests.swift */,
20022004
84B2B5D72819778D00479CEE /* FileAttachmentsViewModel_Tests.swift */,
20032005
84B2B5D9281985DA00479CEE /* FileAttachmentsView_Tests.swift */,
2006+
4FEDF72A2E5DB03D00CE2676 /* FileAttachmentPreview_Tests.swift */,
20042007
84507C97281AC40F0081DDC2 /* AddUsersViewModel_Tests.swift */,
20052008
84507C99281ACCD70081DDC2 /* AddUsersView_Tests.swift */,
20062009
);
@@ -3076,6 +3079,7 @@
30763079
84C94D1327578BF2007FE2B9 /* XCTestCase+MockJSON.swift in Sources */,
30773080
84C94D5E275A3AA9007FE2B9 /* ImageCDN_Tests.swift in Sources */,
30783081
84C94C8027567D3F007FE2B9 /* ChatChannelListViewModel_Tests.swift in Sources */,
3082+
4FEDF72B2E5DB03D00CE2676 /* FileAttachmentPreview_Tests.swift in Sources */,
30793083
84B9B20E27998E9200BFAEAE /* ColorExtensions.swift in Sources */,
30803084
8423C344277CC5020092DCF1 /* CommandsHandler_Tests.swift in Sources */,
30813085
84B2B5D2281965D000479CEE /* MediaAttachmentsViewModel_Tests.swift in Sources */,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright © 2025 Stream.io Inc. All rights reserved.
3+
//
4+
5+
@testable import SnapshotTesting
6+
@testable import StreamChatSwiftUI
7+
@testable import StreamChatTestTools
8+
import SwiftUI
9+
import XCTest
10+
11+
class FileAttachmentPreview_Tests: StreamChatTestCase {
12+
func test_fileAttachmentPreview_pdf() {
13+
let view = FileAttachmentPreview(
14+
title: "Document title",
15+
url: URL.localYodaQuote
16+
).applyDefaultSize()
17+
18+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
19+
}
20+
}
Loading

0 commit comments

Comments
 (0)