Simplify and fix edge cases around long pressing on system message cells.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-10-17 09:21:06 -07:00
parent 6cba186d8a
commit 06eb794db6
5 changed files with 29 additions and 144 deletions

View File

@ -31,7 +31,6 @@ NS_ASSUME_NONNULL_BEGIN
// TODO: We might want to decompose this method.
- (void)didTapSystemMessageWithInteraction:(TSInteraction *)interaction;
- (void)didLongPressSystemMessageCell:(ConversationViewCell *)systemMessageCell fromView:(UIView *)fromView;
#pragma mark - Offers

View File

@ -10,8 +10,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSSystemMessageCell : ConversationViewCell
//- (CGSize)bubbleSizeForInteraction:(TSInteraction *)interaction collectionViewWidth:(CGFloat)collectionViewWidth;
+ (NSString *)cellReuseIdentifier;
@end

View File

@ -305,11 +305,31 @@ NS_ASSUME_NONNULL_BEGIN
[super prepareForReuse];
}
#pragma mark - editing
#pragma mark - UIMenuController
- (BOOL)canBecomeFirstResponder
- (void)showMenuController
{
return YES;
OWSAssert([NSThread isMainThread]);
DDLogDebug(@"%@ long pressed system message cell: %@", self.logTag, self.viewItem.interaction.debugDescription);
[self becomeFirstResponder];
if ([UIMenuController sharedMenuController].isMenuVisible) {
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:NO];
}
UIMenuController *menuController = [UIMenuController sharedMenuController];
menuController.menuItems = @[];
UIView *fromView = self.titleLabel;
CGRect targetRect = [fromView.superview convertRect:fromView.frame toView:self];
[menuController setTargetRect:targetRect inView:self];
[menuController setMenuVisible:YES animated:YES];
}
- (BOOL)canPerformAction:(SEL)action withSender:(nullable id)sender
{
return action == @selector(delete:);
}
- (void) delete:(nullable id)sender
@ -322,6 +342,11 @@ NS_ASSUME_NONNULL_BEGIN
[interaction remove];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
#pragma mark - Gesture recognizers
- (void)handleTapGesture:(UITapGestureRecognizer *)sender
@ -343,7 +368,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(interaction);
if (longPress.state == UIGestureRecognizerStateBegan) {
[self.delegate didLongPressSystemMessageCell:self fromView:self.titleLabel];
[self showMenuController];
}
}

View File

@ -209,126 +209,6 @@ NS_ASSUME_NONNULL_BEGIN
return [self.text ows_stripped];
}
// TODO:
//#import <QuartzCore/QuartzCore.h>
//
//#import "NSString+JSQMessages.h"
//
//
//@implementation JSQMessagesComposerTextView
//
//#pragma mark - Initialization
//
//- (void)jsq_configureTextView
//{
//
// [self jsq_addTextViewNotificationObservers];
//}
//
//
//- (void)dealloc
//{
// [self jsq_removeTextViewNotificationObservers];
//}
//
//#pragma mark - Composer text view
//
//- (BOOL)hasText
//{
// return ([[self.text jsq_stringByTrimingWhitespace] length] > 0);
//}
//
//- (void)paste:(id)sender
//{
// if (!self.jsqPasteDelegate || [self.jsqPasteDelegate composerTextView:self shouldPasteWithSender:sender]) {
// [super paste:sender];
// }
//}
//
//#pragma mark - Drawing
//
//- (void)drawRect:(CGRect)rect
//{
// [super drawRect:rect];
//
// if ([self.text length] == 0 && self.placeHolder) {
// [self.placeHolderTextColor set];
//
// [self.placeHolder drawInRect:CGRectInset(rect, 7.0f, 5.0f)
// withAttributes:[self jsq_placeholderTextAttributes]];
// }
//}
//
//#pragma mark - Notifications
//
//- (void)jsq_addTextViewNotificationObservers
//{
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(jsq_didReceiveTextViewNotification:)
// name:UITextViewTextDidChangeNotification
// object:self];
//
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(jsq_didReceiveTextViewNotification:)
// name:UITextViewTextDidBeginEditingNotification
// object:self];
//
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(jsq_didReceiveTextViewNotification:)
// name:UITextViewTextDidEndEditingNotification
// object:self];
//}
//
//- (void)jsq_removeTextViewNotificationObservers
//{
// [[NSNotificationCenter defaultCenter] removeObserver:self
// name:UITextViewTextDidChangeNotification
// object:self];
//
// [[NSNotificationCenter defaultCenter] removeObserver:self
// name:UITextViewTextDidBeginEditingNotification
// object:self];
//
// [[NSNotificationCenter defaultCenter] removeObserver:self
// name:UITextViewTextDidEndEditingNotification
// object:self];
//}
//
//- (void)jsq_didReceiveTextViewNotification:(NSNotification *)notification
//{
// [self setNeedsDisplay];
//}
//
//#pragma mark - Utilities
//
//- (NSDictionary *)jsq_placeholderTextAttributes
//{
// NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
// paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
// paragraphStyle.alignment = self.textAlignment;
//
// return @{ NSFontAttributeName : self.font,
// NSForegroundColorAttributeName : self.placeHolderTextColor,
// NSParagraphStyleAttributeName : paragraphStyle };
//}
//
//#pragma mark - UIMenuController
//
//- (BOOL)canBecomeFirstResponder
//{
// return [super canBecomeFirstResponder];
//}
//
//- (BOOL)becomeFirstResponder
//{
// return [super becomeFirstResponder];
//}
//
//- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
// [UIMenuController sharedMenuController].menuItems = nil;
// return [super canPerformAction:action withSender:sender];
//}
//@end
#pragma mark - UITextViewDelegate

View File

@ -2087,23 +2087,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
}
}
- (void)didLongPressSystemMessageCell:(ConversationViewCell *)systemMessageCell fromView:(UIView *)fromView
{
OWSAssert([NSThread isMainThread]);
OWSAssert(systemMessageCell);
OWSAssert(fromView);
DDLogDebug(@"%@ long pressed system message cell: %@", self.tag, systemMessageCell);
[systemMessageCell becomeFirstResponder];
// TODO: Update menu controller actions.
UIMenuController *theMenu = [UIMenuController sharedMenuController];
CGRect targetRect = [fromView.superview convertRect:fromView.frame toView:systemMessageCell];
[theMenu setTargetRect:targetRect inView:systemMessageCell];
[theMenu setMenuVisible:YES animated:YES];
}
#pragma mark - ContactEditingDelegate
- (void)didFinishEditingContact