Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatSuggestionVC is getting redisplayed and commands shortcut not working #3215

Merged
merged 9 commits into from
May 21, 2024
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ _May 20, 2024_
### ✅ Added
- Add a new state layer with async-await and observable state objects ([learn more](https://getstream.io/chat/docs/sdk/ios/client/state-layer/state-layer-overview/)) [#3177](https://github.com/GetStream/stream-chat-swift/pull/3177)

## StreamChatUI
### 🐞 Fixed
- Do not re-display suggestion view on each character change [#3215](https://github.com/GetStream/stream-chat-swift/pull/3215)
- Fix command suggestions not appearing [#3215](https://github.com/GetStream/stream-chat-swift/pull/3215)
- Reduce suggestion view height updates while scrolling [#3215](https://github.com/GetStream/stream-chat-swift/pull/3215)
### 🔄 Changed
- Replace `updateCommandSuggestions()` and `updateMentionSuggestions()` with `updateSuggestions()` in `ChatSuggestionVC` [#3215](https://github.com/GetStream/stream-chat-swift/pull/3215)
nuno-vieira marked this conversation as resolved.
Show resolved Hide resolved

# [4.55.0](https://github.com/GetStream/stream-chat-swift/releases/tag/4.55.0)
_May 13, 2024_

Expand Down
15 changes: 7 additions & 8 deletions Sources/StreamChatUI/Composer/ComposerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ open class ComposerVC: _ViewController,

override open func updateContent() {
super.updateContent()

// Note: The order of the calls is important.
updateText()
updateKeystrokeEvents()
Expand All @@ -531,10 +530,8 @@ open class ComposerVC: _ViewController,
updateCheckbox()
updateBottomContainerVisibility()
updateLeadingContainerVisibility()
updateCommandSuggestions()
updateMentionSuggestions()
updateSuggestions()
updatePlaceholderLabel()
dismissSuggestions()
}

open func updateText() {
Expand Down Expand Up @@ -697,20 +694,22 @@ open class ComposerVC: _ViewController,
}
}

open func updateCommandSuggestions() {
/// Controls whether the suggestions view should be shown or not.
/// By default there are 2 types of suggestions: Commands and Mentions.
open func updateSuggestions() {
if isCommandsEnabled, let typingCommand = typingCommand(in: composerView.inputMessageView.textView) {
showCommandSuggestions(for: typingCommand)
return
}
}

open func updateMentionSuggestions() {

if isMentionsEnabled, let (typingMention, mentionRange) = typingMention(in: composerView.inputMessageView.textView) {
userMentionsDebouncer.execute { [weak self] in
self?.showMentionSuggestions(for: typingMention, mentionRange: mentionRange)
}
return
laevandus marked this conversation as resolved.
Show resolved Hide resolved
}

dismissSuggestions()
}

open func updatePlaceholderLabel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ open class ChatSuggestionsVC: _ViewController,
options: [.new],
changeHandler: { [weak self] collectionView, change in
guard let self = self, let newSize = change.newValue else { return }
guard !collectionView.isTrackingOrDecelerating else { return }
nuno-vieira marked this conversation as resolved.
Show resolved Hide resolved

// NOTE: The defaultRowHeight height value will be used only once to set visibleCells
// once again, not looping it to 0 value so this controller can resize again.
let cellHeight = collectionView.visibleCells.first?.bounds.height ?? self.defaultRowHeight

let newHeight = min(newSize.height, cellHeight * self.numberOfVisibleRows)
guard self.heightConstraints.constant != newHeight else { return }
self.heightConstraints.constant = newHeight
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,41 @@ final class ComposerVC_Tests: XCTestCase {
XCTAssertEqual(searchUsers([user], by: "françois"), [user])
XCTAssertEqual(searchUsers([user], by: "franc"), [user])
}


// MARK: - suggestions view

func test_showCommandSuggestionsView() {
let containerView = UIViewController()
containerView.addChildViewController(composerVC, embedIn: containerView.view)
let channel = ChatChannel.mock(
cid: .unique,
config: .mock(commands: [.init(name: "giphy")])
)
mockedChatChannelController.channel_mock = channel
composerVC.content = .initial()
composerVC.content.text = "/"
composerVC.updateContent()
AssertSnapshot(containerView.view, variants: [.defaultLight], size: .init(width: 400, height: 150))
}

func test_showMentionSuggestionsView() {
let containerView = UIViewController()
containerView.addChildViewController(composerVC, embedIn: containerView.view)
let channel = ChatChannel.mock(
cid: .unique,
config: .mock(commands: [.init(name: "giphy")]),
lastActiveMembers: [.mock(id: "leia_organa", name: "Leia Organa")]
)
mockedChatChannelController.channel_mock = channel
composerVC.userSearchController = .init(client: mockedChatChannelController.client)
composerVC.userMentionsDebouncer = .init(0, queue: .main)
composerVC.content = .initial()
composerVC.content.text = "Hello @Le"
composerVC.content.mentionedUsers = [.mock(id: "leia_organa", name: "Leia Organa")]
composerVC.updateContent()
AssertSnapshot(containerView.view, variants: [.defaultLight], size: .init(width: 400, height: 130))
}

// MARK: - attachmentsPreview

func test_attachmentsPreview_withFourAttachments_addedSameTime() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading