Fix conflicting pan gestures

pull/347/head
nielsandriesse 4 years ago
parent ebd91dcc73
commit a9eb407cc4

@ -7,6 +7,7 @@
// Resending failed messages
// Link previews
// Slight paging glitch
// Scrolling bug
final class ConversationVC : BaseVC, ConversationViewModelDelegate, UITableViewDataSource, UITableViewDelegate {
let thread: TSThread

@ -18,7 +18,13 @@ final class VisibleMessageCell : MessageCell, UITextViewDelegate, BodyTextViewDe
private lazy var messageStatusImageViewTopConstraint = messageStatusImageView.pin(.top, to: .bottom, of: bubbleView, withInset: 0)
private lazy var messageStatusImageViewWidthConstraint = messageStatusImageView.set(.width, to: VisibleMessageCell.messageStatusImageViewSize)
private lazy var messageStatusImageViewHeightConstraint = messageStatusImageView.set(.height, to: VisibleMessageCell.messageStatusImageViewSize)
private lazy var panGestureRecognizer: UIPanGestureRecognizer = {
let result = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
result.delegate = self
return result
}()
private var positionInCluster: Position? {
guard let viewItem = viewItem else { return nil }
if viewItem.isFirstInCluster { return .top }
@ -178,8 +184,6 @@ final class VisibleMessageCell : MessageCell, UITextViewDelegate, BodyTextViewDe
doubleTapGestureRecognizer.numberOfTapsRequired = 2
addGestureRecognizer(doubleTapGestureRecognizer)
tapGestureRecognizer.require(toFail: doubleTapGestureRecognizer)
let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
panGestureRecognizer.delegate = self
addGestureRecognizer(panGestureRecognizer)
}
@ -360,7 +364,7 @@ final class VisibleMessageCell : MessageCell, UITextViewDelegate, BodyTextViewDe
}
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
if gestureRecognizer == panGestureRecognizer {
let v = panGestureRecognizer.velocity(in: self)
guard v.x < 0 else { return false }
return abs(v.x) > abs(v.y)

@ -1,7 +1,10 @@
final class MessagesTableView : UITableView {
var keyboardHeight: CGFloat = 0
// Overriding contentInset and adjustedContentInset is to keep them from changing when the
// conversation view controller is dismissed.
override var contentInset: UIEdgeInsets {
get { UIEdgeInsets(top: 0, leading: 0, bottom: MessagesTableView.baselineContentInset + keyboardHeight, trailing: 0) }
set { }
@ -34,4 +37,13 @@ final class MessagesTableView : UITableView {
contentInsetAdjustmentBehavior = .never
keyboardDismissMode = .interactive
}
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer == panGestureRecognizer {
let v = panGestureRecognizer.velocity(in: self)
return abs(v.x) < 120
} else {
return true
}
}
}

Loading…
Cancel
Save