Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Upcoming

### ✅ Added
- Add the `makeAttachmentTextView` method to ViewFactory [#1013](https://github.com/GetStream/stream-chat-swiftui/pull/1013)

### 🐞 Fixed
- Fix composer not being locked after the channel was frozen [#1015](https://github.com/GetStream/stream-chat-swiftui/pull/1015)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public struct VoiceRecordingContainerView<Factory: ViewFactory>: View {
}
}
if !message.text.isEmpty {
AttachmentTextView(message: message)
AttachmentTextView(factory: factory, message: message)
.frame(maxWidth: .infinity)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public struct ImageAttachmentContainer<Factory: ViewFactory>: View {
}

if !message.text.isEmpty {
AttachmentTextView(message: message)
AttachmentTextView(factory: factory, message: message)
.frame(width: width)
}
}
Expand Down Expand Up @@ -93,21 +93,23 @@ public struct ImageAttachmentContainer<Factory: ViewFactory>: View {
}
}

public struct AttachmentTextView: View {
public struct AttachmentTextView<Factory: ViewFactory>: View {
@Injected(\.colors) private var colors
@Injected(\.fonts) private var fonts

var factory: Factory
var message: ChatMessage
let injectedBackgroundColor: UIColor?

public init(message: ChatMessage, injectedBackgroundColor: UIColor? = nil) {
public init(factory: Factory = DefaultViewFactory.shared, message: ChatMessage, injectedBackgroundColor: UIColor? = nil) {
self.factory = factory
self.message = message
self.injectedBackgroundColor = injectedBackgroundColor
}

public var body: some View {
HStack {
StreamTextView(message: message)
factory.makeAttachmentTextView(options: .init(mesage: message))
.standardPadding()
.fixedSize(horizontal: false, vertical: true)
Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public struct LinkAttachmentContainer<Factory: ViewFactory>: View {

if #available(iOS 15, *) {
HStack {
StreamTextView(message: message)
factory.makeAttachmentTextView(options: .init(mesage: message))
.standardPadding()
Spacer()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public struct MessageTextView<Factory: ViewFactory>: View {
)
}

StreamTextView(message: message)
factory.makeAttachmentTextView(options: .init(mesage: message))
.padding(.leading, leadingPadding)
.padding(.trailing, trailingPadding)
.padding(.top, topPadding)
Expand Down Expand Up @@ -247,6 +247,16 @@ struct StreamTextView: View {
}
}

// Options for the attachment text view.
public class AttachmentTextViewOptions {
// The message to display the text for.
public let message: ChatMessage

public init(mesage: ChatMessage) {
self.message = mesage
}
}

@available(iOS 15, *)
public struct LinkDetectionTextView: View {
@Environment(\.layoutDirection) var layoutDirection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct VideoAttachmentsContainer<Factory: ViewFactory>: View {
}

if !message.text.isEmpty {
AttachmentTextView(message: message)
AttachmentTextView(factory: factory, message: message)
.frame(width: width)
}
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/StreamChatSwiftUI/DefaultViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,12 @@ extension ViewFactory {
) -> some View {
AddUsersView(loadedUserIds: options.loadedUsers.map(\.id), onUserTap: onUserTap)
}

public func makeAttachmentTextView(
options: AttachmentTextViewOptions
) -> some View {
StreamTextView(message: options.message)
}
}

/// Default class conforming to `ViewFactory`, used throughout the SDK.
Expand Down
8 changes: 8 additions & 0 deletions Sources/StreamChatSwiftUI/ViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1182,4 +1182,12 @@ public protocol ViewFactory: AnyObject {
options: AddUsersOptions,
onUserTap: @escaping (ChatUser) -> Void
) -> AddUsersViewType

associatedtype AttachmentTextViewType: View
/// Creates a view for displaying the text of an attachment.
/// - Parameter options: Configuration options for the attachment text view, such as message.
/// - Returns: The view shown in the attachment text slot.
func makeAttachmentTextView(
options: AttachmentTextViewOptions
) -> AttachmentTextViewType
}
11 changes: 11 additions & 0 deletions StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,17 @@ class ViewFactory_Tests: StreamChatTestCase {
// Then
XCTAssert(view is AddUsersView<DefaultViewFactory>)
}

func test_viewFactory_makeAttachmentTextView() {
// Given
let viewFactory = DefaultViewFactory.shared

// When
let view = viewFactory.makeAttachmentTextView(options: .init(mesage: message))

// Then
XCTAssert(view is StreamTextView)
}
}

extension ChannelAction: Equatable {
Expand Down
Loading