Skip to content

Commit a2ef77f

Browse files
Added customization of the reactions overlay background
1 parent 3e84fe2 commit a2ef77f

File tree

6 files changed

+55
-14
lines changed

6 files changed

+55
-14
lines changed

CHANGELOG.md

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

66
### ✅ Added
77
- Configuration for stack based navigation for iPads
8+
- Customization of the reactions background
89

910
# [4.21.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.21.0)
1011
_September 02, 2022_

Sources/StreamChatSwiftUI/ChatChannel/Reactions/ReactionsOverlayView.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
5454

5555
public var body: some View {
5656
ZStack(alignment: .topLeading) {
57-
Image(uiImage: currentSnapshot)
58-
.overlay(Color.black.opacity(!popIn ? 0 : 0.1))
59-
.blur(radius: !popIn ? 0 : 4)
60-
.transition(.opacity)
61-
.onTapGesture {
62-
dismissReactionsOverlay() { /* No additional handling. */ }
63-
}
64-
.edgesIgnoringSafeArea(.all)
65-
.alert(isPresented: $viewModel.errorShown) {
66-
Alert.defaultErrorAlert
67-
}
57+
factory.makeReactionsBackgroundView(
58+
currentSnapshot: currentSnapshot,
59+
popInAnimationInProgress: !popIn
60+
)
61+
.transition(.opacity)
62+
.onTapGesture {
63+
dismissReactionsOverlay() { /* No additional handling. */ }
64+
}
65+
.edgesIgnoringSafeArea(.all)
66+
.alert(isPresented: $viewModel.errorShown) {
67+
Alert.defaultErrorAlert
68+
}
6869

6970
if !messageDisplayInfo.message.isSentByCurrentUser &&
7071
utils.messageListConfig.messageDisplayOptions.showAvatars(for: channel) {

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,15 @@ extension ViewFactory {
749749
)
750750
}
751751

752+
public func makeReactionsBackgroundView(
753+
currentSnapshot: UIImage,
754+
popInAnimationInProgress: Bool
755+
) -> some View {
756+
Image(uiImage: currentSnapshot)
757+
.overlay(Color.black.opacity(popInAnimationInProgress ? 0 : 0.1))
758+
.blur(radius: popInAnimationInProgress ? 0 : 4)
759+
}
760+
752761
public func makeQuotedMessageHeaderView(
753762
quotedMessage: Binding<ChatMessage?>
754763
) -> some View {

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,16 @@ public protocol ViewFactory: AnyObject {
742742
onActionExecuted: @escaping (MessageActionInfo) -> Void
743743
) -> ReactionsOverlayViewType
744744

745+
associatedtype ReactionsBackground: View
746+
/// Creates the reactions background view.
747+
/// - Parameters:
748+
/// - currentSnapshot: the current snapshot of the message list screen.
749+
/// - popInAnimationInProgress: whether the pop in animation is in progress.
750+
func makeReactionsBackgroundView(
751+
currentSnapshot: UIImage,
752+
popInAnimationInProgress: Bool
753+
) -> ReactionsBackground
754+
745755
associatedtype QuotedMessageHeaderViewType: View
746756
/// Creates the quoted message header view in the composer.
747757
/// - Parameters:

StreamChatSwiftUITests/Tests/ChatChannel/MessageListView_Tests.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,31 @@ class MessageListView_Tests: StreamChatTestCase {
4545
assertSnapshot(matching: button, as: .image)
4646
}
4747

48+
func test_messageListView_typingIndicator() {
49+
// Given
50+
let channelConfig = ChannelConfig(reactionsEnabled: true)
51+
let typingUser = ChatUser.mock(id: "martin", name: "Martin")
52+
let messageListView = makeMessageListView(
53+
channelConfig: channelConfig,
54+
currentlyTypingUsers: [typingUser]
55+
)
56+
.applyDefaultSize()
57+
58+
// Then
59+
assertSnapshot(matching: messageListView, as: .image)
60+
}
61+
4862
// MARK: - private
4963

50-
private func makeMessageListView(channelConfig: ChannelConfig) -> MessageListView<DefaultViewFactory> {
64+
private func makeMessageListView(
65+
channelConfig: ChannelConfig,
66+
currentlyTypingUsers: Set<ChatUser> = []
67+
) -> MessageListView<DefaultViewFactory> {
5168
let reactions = [MessageReactionType(rawValue: "like"): 2]
52-
let channel = ChatChannel.mockDMChannel(config: channelConfig)
69+
let channel = ChatChannel.mockDMChannel(
70+
config: channelConfig,
71+
currentlyTypingUsers: currentlyTypingUsers
72+
)
5373
let temp = [ChatMessage.mock(
5474
id: .unique,
5575
cid: channel.cid,
@@ -69,7 +89,7 @@ class MessageListView_Tests: StreamChatTestCase {
6989
currentDateString: nil,
7090
listId: "listId",
7191
isMessageThread: false,
72-
shouldShowTypingIndicator: false,
92+
shouldShowTypingIndicator: !currentlyTypingUsers.isEmpty,
7393
onMessageAppear: { _ in },
7494
onScrollToBottom: {},
7595
onLongPress: { _ in }
Loading

0 commit comments

Comments
 (0)