Skip to content

Commit 67ab9f3

Browse files
authored
Use AppSettings.fileUploadConfig for setting supported UTI types for the file picker (#713)
1 parent b016961 commit 67ab9f3

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44
# Upcoming
55

66
### ✅ Added
7+
- Use `AppSettings.fileUploadConfig` for setting supported UTI types for the file picker [#713](https://github.com/GetStream/stream-chat-swiftui/pull/713)
78
- Colors and images for voice recording view [#704](https://github.com/GetStream/stream-chat-swiftui/pull/704)
89
- `ColorPalette.voiceMessageControlBackground`
910
- `Images.pauseFilled`

Sources/StreamChatSwiftUI/ChatChannel/Composer/FilePickerView.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
//
44

55
import SwiftUI
6+
import UniformTypeIdentifiers
67

78
/// SwiftUI wrapper for picking files from the device.
89
public struct FilePickerView: UIViewControllerRepresentable {
10+
@Injected(\.chatClient) var client
911
@Binding var fileURLs: [URL]
1012

1113
public func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
12-
let picker = UIDocumentPickerViewController(forOpeningContentTypes: [.item])
14+
let picker = UIDocumentPickerViewController(forOpeningContentTypes: openingContentTypes)
1315
picker.delegate = context.coordinator
1416
picker.allowsMultipleSelection = true
1517
return picker
1618
}
19+
20+
var openingContentTypes: [UTType] {
21+
guard let settings = client.appSettings else { return [.item] }
22+
let allowedUTITypes = settings.fileUploadConfig.allowedUTITypes.compactMap { UTType($0) }
23+
return allowedUTITypes.isEmpty ? [.item] : allowedUTITypes
24+
}
1725

1826
public func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {
1927
// We don't need handling updates of the VC at the moment.

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
4F7DD9A02BFC7C6100599AA6 /* ChatClient+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F7DD99F2BFC7C6100599AA6 /* ChatClient+Extensions.swift */; };
2121
4F7DD9A22BFCB2EF00599AA6 /* ChatClientExtensions_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F7DD9A12BFCB2EF00599AA6 /* ChatClientExtensions_Tests.swift */; };
2222
4FD3592A2C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD359292C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift */; };
23+
4FD964622D353D88001B6838 /* FilePickerView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD964612D353D82001B6838 /* FilePickerView_Tests.swift */; };
2324
4FEAB3182BFF71F70057E511 /* SwiftUI+UIAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEAB3172BFF71F70057E511 /* SwiftUI+UIAlertController.swift */; };
2425
8205B4142AD41CC700265B84 /* StreamSwiftTestHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = 8205B4132AD41CC700265B84 /* StreamSwiftTestHelpers */; };
2526
8205B4182AD4267200265B84 /* StreamSwiftTestHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = 8205B4172AD4267200265B84 /* StreamSwiftTestHelpers */; };
@@ -608,6 +609,7 @@
608609
4F7DD99F2BFC7C6100599AA6 /* ChatClient+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ChatClient+Extensions.swift"; sourceTree = "<group>"; };
609610
4F7DD9A12BFCB2EF00599AA6 /* ChatClientExtensions_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatClientExtensions_Tests.swift; sourceTree = "<group>"; };
610611
4FD359292C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollViewModel_Tests.swift; sourceTree = "<group>"; };
612+
4FD964612D353D82001B6838 /* FilePickerView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilePickerView_Tests.swift; sourceTree = "<group>"; };
611613
4FEAB3172BFF71F70057E511 /* SwiftUI+UIAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftUI+UIAlertController.swift"; sourceTree = "<group>"; };
612614
820A619F29D6D78E002257FB /* QuotedReply_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotedReply_Tests.swift; sourceTree = "<group>"; };
613615
825AADF3283CCDB000237498 /* ThreadPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadPage.swift; sourceTree = "<group>"; };
@@ -2116,6 +2118,7 @@
21162118
84C94D5027591DE2007FE2B9 /* ChatMessageIDs_Tests.swift */,
21172119
84204BFD2C052BD600AE522B /* CreatePollView_Tests.swift */,
21182120
4FD359292C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift */,
2121+
4FD964612D353D82001B6838 /* FilePickerView_Tests.swift */,
21192122
84AB7B20277203EF00631A10 /* GalleryView_Tests.swift */,
21202123
8469592E29BB235400134EA0 /* LazyImageExtensions_Tests.swift */,
21212124
840008BA27E8D64A00282D88 /* MessageActions_Tests.swift */,
@@ -2992,6 +2995,7 @@
29922995
84DEC8DF2760A1D100172876 /* MessageView_Tests.swift in Sources */,
29932996
847F7949282A91AD0009F74C /* ChatChannelView_Tests.swift in Sources */,
29942997
84CC3734290B0C2900689B73 /* ChatMessageControllerSUI_Mock.swift in Sources */,
2998+
4FD964622D353D88001B6838 /* FilePickerView_Tests.swift in Sources */,
29952999
91B763A6283EB39600B458A9 /* MoreChannelActionsFullScreenWrappingView_Tests.swift in Sources */,
29963000
846608E9278C98CB00D3D7B3 /* TypingIndicatorView_Tests.swift in Sources */,
29973001
8421BCEC27A400E8000F977D /* ReactionsUsersView_Tests.swift in Sources */,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Copyright © 2025 Stream.io Inc. All rights reserved.
3+
//
4+
5+
@testable import StreamChat
6+
@testable import StreamChatSwiftUI
7+
@testable import StreamChatTestTools
8+
import UniformTypeIdentifiers
9+
import XCTest
10+
11+
final class FilePickerView_Tests: StreamChatTestCase {
12+
func test_openingContentTypes_default() {
13+
let picker = FilePickerView(fileURLs: .constant([]))
14+
XCTAssertEqual(picker.openingContentTypes, [UTType.item])
15+
}
16+
17+
func test_openingContentTypes_allowedLists() {
18+
chatClient.mockedAppSettings = .mock(fileUploadConfig: .mock(allowedFileExtensions: [".pdf"]))
19+
XCTAssertEqual(FilePickerView(fileURLs: .constant([])).openingContentTypes, [UTType.pdf])
20+
21+
chatClient.mockedAppSettings = .mock(fileUploadConfig: .mock(allowedMimeTypes: ["audio/mp3"]))
22+
XCTAssertEqual(FilePickerView(fileURLs: .constant([])).openingContentTypes, [UTType.mp3])
23+
}
24+
}

0 commit comments

Comments
 (0)