From a9eb407cc4be78637876a9ba150e3f09b44d307d Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 15 Feb 2021 09:52:07 +1100 Subject: [PATCH] Fix conflicting pan gestures --- Session/Conversations V2/ConversationVC.swift | 1 + .../Message Cells/VisibleMessageCell.swift | 12 ++++++++---- .../Views & Modals/MessagesTableView.swift | 14 +++++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Session/Conversations V2/ConversationVC.swift b/Session/Conversations V2/ConversationVC.swift index b065516ea..f8a490bd2 100644 --- a/Session/Conversations V2/ConversationVC.swift +++ b/Session/Conversations V2/ConversationVC.swift @@ -7,6 +7,7 @@ // • Resending failed messages // • Link previews // • Slight paging glitch +// • Scrolling bug final class ConversationVC : BaseVC, ConversationViewModelDelegate, UITableViewDataSource, UITableViewDelegate { let thread: TSThread diff --git a/Session/Conversations V2/Message Cells/VisibleMessageCell.swift b/Session/Conversations V2/Message Cells/VisibleMessageCell.swift index 6d8914609..ac3e2807a 100644 --- a/Session/Conversations V2/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations V2/Message Cells/VisibleMessageCell.swift @@ -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) diff --git a/Session/Conversations V2/Views & Modals/MessagesTableView.swift b/Session/Conversations V2/Views & Modals/MessagesTableView.swift index c72439d57..7ea97216b 100644 --- a/Session/Conversations V2/Views & Modals/MessagesTableView.swift +++ b/Session/Conversations V2/Views & Modals/MessagesTableView.swift @@ -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 + } + } }