-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Added ability to intercept -[UITextView paste:] #1136
Changes from 4 commits
c5c7050
8dea72a
08ff2cb
62385e4
5b0badf
12dd5b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,21 @@ | |
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class JSQMessagesComposerTextView; | ||
|
||
/** | ||
* A delegate used to forward custom notifications from `JSQMessagesComposerTextView`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
@protocol JSQMessagesComposerTextViewPasteDelegate <NSObject> | ||
|
||
/** | ||
* Asks the delegate whether or not the `textView` should use the original implementation of -[UITextView paste]. | ||
* If you want any custom pasting behavior, implement this delegate method and return `NO` | ||
* when you want to handle pasting yourself. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
- (BOOL)composerTextView:(JSQMessagesComposerTextView *)textView shouldPasteWithSender:(id)sender; | ||
@end | ||
|
||
/** | ||
* An instance of `JSQMessagesComposerTextView` is a subclass of `UITextView` that is styled and used | ||
* for composing messages in a `JSQMessagesViewController`. It is a subview of a `JSQMessagesToolbarContentView`. | ||
|
@@ -34,6 +49,11 @@ | |
*/ | ||
@property (strong, nonatomic) UIColor *placeHolderTextColor; | ||
|
||
/** | ||
* A delegate that conforms to `JSQMessagesComposerTextViewDelegate`. The default value is `nil`. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change to:
|
||
@property (weak, nonatomic) id<JSQMessagesComposerTextViewPasteDelegate> pasteDelegate; | ||
|
||
/** | ||
* Determines whether or not the text view contains text after trimming white space | ||
* from the front and back of its string. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,13 @@ - (void)setTextAlignment:(NSTextAlignment)textAlignment | |
[self setNeedsDisplay]; | ||
} | ||
|
||
- (void)paste:(id)sender | ||
{ | ||
if (!self.pasteDelegate || [self.pasteDelegate composerTextView:self shouldPasteWithSender:sender]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That means that if there's no paste delegate, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops. you're right 👍 |
||
[super paste:sender]; | ||
} | ||
} | ||
|
||
#pragma mark - Drawing | ||
|
||
- (void)drawRect:(CGRect)rect | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move this to the header file.