Disabled tableview scroll when swiping to reply in a conversation

This commit is contained in:
Mark Feaver 2021-08-08 17:57:48 +10:00
parent 67e8191c2c
commit f0fb4529c8
3 changed files with 21 additions and 0 deletions

View File

@ -468,6 +468,15 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
}
}
}
func handleViewItemSwiped(_ viewItem: ConversationViewItem, state: SwipeState) {
switch state {
case .began:
messagesTableView.isScrollEnabled = false
case .ended, .cancelled:
messagesTableView.isScrollEnabled = true
}
}
func showFailedMessageSheet(for tsMessage: TSOutgoingMessage) {
let thread = self.thread

View File

@ -1,5 +1,11 @@
import UIKit
public enum SwipeState {
case began
case ended
case cancelled
}
class MessageCell : UITableViewCell {
weak var delegate: MessageCellDelegate?
var viewItem: ConversationViewItem? { didSet { update() } }
@ -55,6 +61,7 @@ protocol MessageCellDelegate : AnyObject {
func handleViewItemLongPressed(_ viewItem: ConversationViewItem)
func handleViewItemTapped(_ viewItem: ConversationViewItem, gestureRecognizer: UITapGestureRecognizer)
func handleViewItemDoubleTapped(_ viewItem: ConversationViewItem)
func handleViewItemSwiped(_ viewItem: ConversationViewItem, state: SwipeState)
func showFullText(_ viewItem: ConversationViewItem)
func openURL(_ url: URL)
func handleReplyButtonTapped(for viewItem: ConversationViewItem)

View File

@ -466,9 +466,12 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
}
@objc private func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {
guard let viewItem = viewItem else { return }
let viewsToMove = [ bubbleView, profilePictureView, replyButton, timerView, messageStatusImageView ]
let translationX = gestureRecognizer.translation(in: self).x.clamp(-CGFloat.greatestFiniteMagnitude, 0)
switch gestureRecognizer.state {
case .began:
delegate?.handleViewItemSwiped(viewItem, state: .began)
case .changed:
// The idea here is to asymptotically approach a maximum drag distance
let damping: CGFloat = 20
@ -486,8 +489,10 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
previousX = translationX
case .ended, .cancelled:
if abs(translationX) > VisibleMessageCell.swipeToReplyThreshold {
delegate?.handleViewItemSwiped(viewItem, state: .ended)
reply()
} else {
delegate?.handleViewItemSwiped(viewItem, state: .cancelled)
resetReply()
}
default: break