Skip to content

[trello.com/c/jKqpxiCa/13] update message reading with keyboard #886

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

Merged
merged 2 commits into from
Jul 4, 2025
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
19 changes: 18 additions & 1 deletion Adamant/Modules/Chat/View/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ final class ChatViewController: MessagesViewController {
numberOfLines: 1
)

private var keyboardHeight: CGFloat = 0
private var sendTransaction: SendTransaction

// swiftlint:disable unused_setter_value
Expand Down Expand Up @@ -321,6 +322,20 @@ extension ChatViewController {
self?.state.isAppActive = false
}
.store(in: &subscriptions)

if !isMacOS {
NotificationCenter.default.publisher(for: UIResponder.keyboardDidChangeFrameNotification)
.sink { [weak self] notification in
guard let self,
let frame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect,
let window = self.view.window else { return }

let convertedFrame = self.view.convert(frame, from: window)
let height = max(self.view.bounds.maxY - convertedFrame.minY - hiddenScrollViewPartHeight / 2, 0)
print(UIScreen.main.bounds.height)
}
.store(in: &subscriptions)
}

viewModel.didTapAdmNodesList
.sink { [weak self] in
Expand Down Expand Up @@ -594,7 +609,7 @@ extension ChatViewController {
x: messagesCollectionView.contentOffset.x,
y: messagesCollectionView.contentOffset.y + hiddenScrollViewPartHeight,
width: messagesCollectionView.bounds.width,
height: messagesCollectionView.bounds.height - hiddenScrollViewPartHeight * 2
height: messagesCollectionView.bounds.height - hiddenScrollViewPartHeight * 2 - keyboardHeight
)

let visibleIndexPaths = messagesCollectionView.indexPathsForVisibleItems
Expand Down Expand Up @@ -950,6 +965,8 @@ extension ChatViewController {
NewMessagesCell.self,
forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter
)
collection.enableKeyboardDismissOnTap(targetView: collection)

return collection
}

Expand Down
10 changes: 9 additions & 1 deletion Adamant/Modules/Chat/View/Subviews/ChatMessagesCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ final class ChatMessagesCollectionView: MessagesCollectionView {
setContentOffset(contentOffset, animated: false)
}


func enableKeyboardDismissOnTap(targetView: UIView) {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
tapGesture.cancelsTouchesInView = false
self.addGestureRecognizer(tapGesture)
}

@objc private func dismissKeyboard() {
self.superview?.endEditing(true)
}
}

fileprivate extension ChatMessagesCollectionView {
Expand Down