Fix taps in message cells.

pull/1/head
Matthew Chen 7 years ago
parent d3f106e3b7
commit a1386eca81

@ -41,6 +41,10 @@ NS_ASSUME_NONNULL_BEGIN
- (NSCache *)cellMediaCache; - (NSCache *)cellMediaCache;
#pragma mark - Messages
- (void)didTapFailedOutgoingMessage:(TSOutgoingMessage *)message;
@end @end
#pragma mark - #pragma mark -

@ -35,8 +35,6 @@ typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) {
- (void)didTapFailedIncomingAttachment:(ConversationViewItem *)viewItem - (void)didTapFailedIncomingAttachment:(ConversationViewItem *)viewItem
attachmentPointer:(TSAttachmentPointer *)attachmentPointer; attachmentPointer:(TSAttachmentPointer *)attachmentPointer;
- (void)didTapFailedOutgoingMessage:(TSOutgoingMessage *)message;
- (void)didTapConversationItem:(ConversationViewItem *)viewItem quotedReply:(OWSQuotedReplyModel *)quotedReply; - (void)didTapConversationItem:(ConversationViewItem *)viewItem quotedReply:(OWSQuotedReplyModel *)quotedReply;
- (void)didTapConversationItem:(ConversationViewItem *)viewItem - (void)didTapConversationItem:(ConversationViewItem *)viewItem
quotedReply:(OWSQuotedReplyModel *)quotedReply quotedReply:(OWSQuotedReplyModel *)quotedReply
@ -73,8 +71,16 @@ typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) {
- (void)prepareForReuse; - (void)prepareForReuse;
#pragma mark - Gestures
- (OWSMessageGestureLocation)gestureLocationForLocation:(CGPoint)locationInMessageBubble; - (OWSMessageGestureLocation)gestureLocationForLocation:(CGPoint)locationInMessageBubble;
// This only needs to be called when we use the cell _outside_ the context
// of a conversation view message cell.
- (void)addTapGestureHandler;
- (void)handleTapGesture:(UITapGestureRecognizer *)sender;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -67,10 +67,6 @@ NS_ASSUME_NONNULL_BEGIN
[self addSubview:self.bubbleView]; [self addSubview:self.bubbleView];
[self.bubbleView autoPinEdgesToSuperviewEdges]; [self.bubbleView autoPinEdgesToSuperviewEdges];
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[self addGestureRecognizer:tap];
self.bodyTextView = [self newTextView]; self.bodyTextView = [self newTextView];
// Setting dataDetectorTypes is expensive. Do it just once. // Setting dataDetectorTypes is expensive. Do it just once.
self.bodyTextView.dataDetectorTypes self.bodyTextView.dataDetectorTypes
@ -1071,6 +1067,13 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Gestures #pragma mark - Gestures
- (void)addTapGestureHandler
{
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[self addGestureRecognizer:tap];
}
- (void)handleTapGesture:(UITapGestureRecognizer *)sender - (void)handleTapGesture:(UITapGestureRecognizer *)sender
{ {
OWSAssert(self.delegate); OWSAssert(self.delegate);
@ -1083,7 +1086,6 @@ NS_ASSUME_NONNULL_BEGIN
if (self.viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) { if (self.viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.viewItem.interaction; TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.viewItem.interaction;
if (outgoingMessage.messageState == TSOutgoingMessageStateUnsent) { if (outgoingMessage.messageState == TSOutgoingMessageStateUnsent) {
[self.delegate didTapFailedOutgoingMessage:outgoingMessage];
return; return;
} else if (outgoingMessage.messageState == TSOutgoingMessageStateAttemptingOut) { } else if (outgoingMessage.messageState == TSOutgoingMessageStateAttemptingOut) {
// Ignore taps on outgoing messages being sent. // Ignore taps on outgoing messages being sent.

@ -83,6 +83,10 @@ NS_ASSUME_NONNULL_BEGIN
self.contentView.userInteractionEnabled = YES; self.contentView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[self addGestureRecognizer:tap];
UILongPressGestureRecognizer *longPress = UILongPressGestureRecognizer *longPress =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)]; [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
[self.contentView addGestureRecognizer:longPress]; [self.contentView addGestureRecognizer:longPress];
@ -490,6 +494,29 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Gesture recognizers #pragma mark - Gesture recognizers
- (void)handleTapGesture:(UITapGestureRecognizer *)sender
{
OWSAssert(self.delegate);
if (sender.state != UIGestureRecognizerStateRecognized) {
DDLogVerbose(@"%@ Ignoring tap on message: %@", self.logTag, self.viewItem.interaction.debugDescription);
return;
}
if (self.viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.viewItem.interaction;
if (outgoingMessage.messageState == TSOutgoingMessageStateUnsent) {
[self.delegate didTapFailedOutgoingMessage:outgoingMessage];
return;
} else if (outgoingMessage.messageState == TSOutgoingMessageStateAttemptingOut) {
// Ignore taps on outgoing messages being sent.
return;
}
}
[self.messageBubbleView handleTapGesture:sender];
}
- (void)handleLongPressGesture:(UILongPressGestureRecognizer *)sender - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)sender
{ {
OWSAssert(self.delegate); OWSAssert(self.delegate);

@ -2163,7 +2163,7 @@ typedef enum : NSUInteger {
}]; }];
} }
- (void)didTapConversationItem:(ConversationViewItem *)viewItem quotedMessage:(OWSQuotedReplyModel *)quotedReply - (void)didTapConversationItem:(ConversationViewItem *)viewItem quotedReply:(OWSQuotedReplyModel *)quotedReply
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
OWSAssert(viewItem); OWSAssert(viewItem);

@ -322,6 +322,7 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
let messageBubbleView = OWSMessageBubbleView(frame: CGRect.zero) let messageBubbleView = OWSMessageBubbleView(frame: CGRect.zero)
messageBubbleView.delegate = self messageBubbleView.delegate = self
messageBubbleView.addTapGestureHandler()
self.messageBubbleView = messageBubbleView self.messageBubbleView = messageBubbleView
messageBubbleView.viewItem = viewItem messageBubbleView.viewItem = viewItem
messageBubbleView.cellMediaCache = NSCache() messageBubbleView.cellMediaCache = NSCache()

Loading…
Cancel
Save