Skip to content

Commit f4f2641

Browse files
Implemented config for uploads
1 parent 422c53a commit f4f2641

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/AttachmentPickerTypeView.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright © 2022 Stream.io Inc. All rights reserved.
33
//
44

5+
import StreamChat
56
import SwiftUI
67

78
/// Enum for the picker type state.
@@ -30,16 +31,19 @@ public struct AttachmentPickerTypeView: View {
3031
@Injected(\.colors) private var colors
3132

3233
@Binding var pickerTypeState: PickerTypeState
34+
var channelConfig: ChannelConfig?
3335

3436
public var body: some View {
3537
HStack(spacing: 16) {
3638
switch pickerTypeState {
3739
case let .expanded(attachmentPickerType):
38-
PickerTypeButton(
39-
pickerTypeState: $pickerTypeState,
40-
pickerType: .media,
41-
selected: attachmentPickerType
42-
)
40+
if channelConfig?.uploadsEnabled == true {
41+
PickerTypeButton(
42+
pickerTypeState: $pickerTypeState,
43+
pickerType: .media,
44+
selected: attachmentPickerType
45+
)
46+
}
4347

4448
PickerTypeButton(
4549
pickerTypeState: $pickerTypeState,

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
1515
@State private var composerHeight: CGFloat = 0
1616

1717
private var factory: Factory
18+
private var channelConfig: ChannelConfig?
1819
@Binding var quotedMessage: ChatMessage?
1920
@Binding var editedMessage: ChatMessage?
2021

@@ -27,6 +28,7 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
2728
onMessageSent: @escaping () -> Void
2829
) {
2930
factory = viewFactory
31+
channelConfig = channelController.channel?.config
3032
_viewModel = StateObject(
3133
wrappedValue: ViewModelsFactory.makeMessageComposerViewModel(
3234
with: channelController,
@@ -55,7 +57,10 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
5557
}
5658

5759
HStack(alignment: .bottom) {
58-
factory.makeLeadingComposerView(state: $viewModel.pickerTypeState)
60+
factory.makeLeadingComposerView(
61+
state: $viewModel.pickerTypeState,
62+
channelConfig: channelConfig
63+
)
5964

6065
factory.makeComposerInputView(
6166
text: $viewModel.text,

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,14 @@ extension ViewFactory {
292292
}
293293

294294
public func makeLeadingComposerView(
295-
state: Binding<PickerTypeState>
295+
state: Binding<PickerTypeState>,
296+
channelConfig: ChannelConfig?
296297
) -> some View {
297-
AttachmentPickerTypeView(pickerTypeState: state)
298-
.padding(.bottom, 8)
298+
AttachmentPickerTypeView(
299+
pickerTypeState: state,
300+
channelConfig: channelConfig
301+
)
302+
.padding(.bottom, 8)
299303
}
300304

301305
@ViewBuilder

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,13 @@ public protocol ViewFactory: AnyObject {
288288

289289
associatedtype LeadingComposerViewType: View
290290
/// Creates the leading part of the composer view.
291-
/// - Parameter state: Indicator what's the current picker state (can be ignored for different types of views).
291+
/// - Parameters:
292+
/// - state: Indicator what's the current picker state (can be ignored for different types of views).
293+
/// - channelConfig: The configuration of a channel.
292294
/// - Returns: view displayed in the leading part of the message composer view.
293295
func makeLeadingComposerView(
294-
state: Binding<PickerTypeState>
296+
state: Binding<PickerTypeState>,
297+
channelConfig: ChannelConfig?
295298
) -> LeadingComposerViewType
296299

297300
/// Creates the composer input view.

0 commit comments

Comments
 (0)