1414#import " RCTUtils.h"
1515#import " UIView+React.h"
1616
17+ @interface RCTUITextView : UITextView
18+
19+ @property (nonatomic , assign ) BOOL textWasPasted;
20+
21+ @end
22+
23+ @implementation RCTUITextView
24+
25+ - (void )paste : (id )sender
26+ {
27+ _textWasPasted = YES ;
28+ [super paste: sender];
29+ }
30+
31+ @end
32+
1733@implementation RCTTextView
1834{
1935 RCTEventDispatcher *_eventDispatcher;
@@ -33,7 +49,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
3349 _eventDispatcher = eventDispatcher;
3450 _placeholderTextColor = [self defaultPlaceholderTextColor ];
3551
36- _textView = [[UITextView alloc ] initWithFrame: self .bounds];
52+ _textView = [[RCTUITextView alloc ] initWithFrame: self .bounds];
3753 _textView.backgroundColor = [UIColor clearColor ];
3854 _textView.scrollsToTop = NO ;
3955 _textView.delegate = self;
@@ -56,15 +72,15 @@ - (void)updateFrames
5672 // first focused.
5773 UIEdgeInsets adjustedFrameInset = UIEdgeInsetsZero;
5874 adjustedFrameInset.left = _contentInset.left - 5 ;
59-
75+
6076 UIEdgeInsets adjustedTextContainerInset = _contentInset;
6177 adjustedTextContainerInset.top += 5 ;
6278 adjustedTextContainerInset.left = 0 ;
63-
79+
6480 CGRect frame = UIEdgeInsetsInsetRect (self.bounds , adjustedFrameInset);
6581 _textView.frame = frame;
6682 _placeholderView.frame = frame;
67-
83+
6884 _textView.textContainerInset = adjustedTextContainerInset;
6985 _placeholderView.textContainerInset = adjustedTextContainerInset;
7086}
@@ -138,8 +154,18 @@ - (NSString *)text
138154 return _textView.text ;
139155}
140156
141- - (BOOL )textView : (UITextView *)textView shouldChangeTextInRange : (NSRange )range replacementText : (NSString *)text
157+ - (BOOL )textView : (RCTUITextView *)textView shouldChangeTextInRange : (NSRange )range replacementText : (NSString *)text
142158{
159+ if (textView.textWasPasted ) {
160+ textView.textWasPasted = NO ;
161+ } else {
162+ [_eventDispatcher sendTextEventWithType: RCTTextEventTypeKeyPress
163+ reactTag: self .reactTag
164+ text: nil
165+ key: text
166+ eventCount: _nativeEventCount];
167+ }
168+
143169 if (_maxLength == nil ) {
144170 return YES ;
145171 }
@@ -215,6 +241,7 @@ - (void)textViewDidBeginEditing:(UITextView *)textView
215241 [_eventDispatcher sendTextEventWithType: RCTTextEventTypeFocus
216242 reactTag: self .reactTag
217243 text: textView.text
244+ key: nil
218245 eventCount: _nativeEventCount];
219246}
220247
@@ -225,6 +252,7 @@ - (void)textViewDidChange:(UITextView *)textView
225252 [_eventDispatcher sendTextEventWithType: RCTTextEventTypeChange
226253 reactTag: self .reactTag
227254 text: textView.text
255+ key: nil
228256 eventCount: _nativeEventCount];
229257
230258}
@@ -234,6 +262,7 @@ - (void)textViewDidEndEditing:(UITextView *)textView
234262 [_eventDispatcher sendTextEventWithType: RCTTextEventTypeEnd
235263 reactTag: self .reactTag
236264 text: textView.text
265+ key: nil
237266 eventCount: _nativeEventCount];
238267}
239268
@@ -253,6 +282,7 @@ - (BOOL)resignFirstResponder
253282 [_eventDispatcher sendTextEventWithType: RCTTextEventTypeBlur
254283 reactTag: self .reactTag
255284 text: _textView.text
285+ key: nil
256286 eventCount: _nativeEventCount];
257287 }
258288 return result;
0 commit comments