14
14
#import " RCTUtils.h"
15
15
#import " UIView+React.h"
16
16
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
+
17
33
@implementation RCTTextView
18
34
{
19
35
RCTEventDispatcher *_eventDispatcher;
@@ -33,7 +49,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
33
49
_eventDispatcher = eventDispatcher;
34
50
_placeholderTextColor = [self defaultPlaceholderTextColor ];
35
51
36
- _textView = [[UITextView alloc ] initWithFrame: self .bounds];
52
+ _textView = [[RCTUITextView alloc ] initWithFrame: self .bounds];
37
53
_textView.backgroundColor = [UIColor clearColor ];
38
54
_textView.scrollsToTop = NO ;
39
55
_textView.delegate = self;
@@ -56,15 +72,15 @@ - (void)updateFrames
56
72
// first focused.
57
73
UIEdgeInsets adjustedFrameInset = UIEdgeInsetsZero;
58
74
adjustedFrameInset.left = _contentInset.left - 5 ;
59
-
75
+
60
76
UIEdgeInsets adjustedTextContainerInset = _contentInset;
61
77
adjustedTextContainerInset.top += 5 ;
62
78
adjustedTextContainerInset.left = 0 ;
63
-
79
+
64
80
CGRect frame = UIEdgeInsetsInsetRect (self.bounds , adjustedFrameInset);
65
81
_textView.frame = frame;
66
82
_placeholderView.frame = frame;
67
-
83
+
68
84
_textView.textContainerInset = adjustedTextContainerInset;
69
85
_placeholderView.textContainerInset = adjustedTextContainerInset;
70
86
}
@@ -138,8 +154,18 @@ - (NSString *)text
138
154
return _textView.text ;
139
155
}
140
156
141
- - (BOOL )textView : (UITextView *)textView shouldChangeTextInRange : (NSRange )range replacementText : (NSString *)text
157
+ - (BOOL )textView : (RCTUITextView *)textView shouldChangeTextInRange : (NSRange )range replacementText : (NSString *)text
142
158
{
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
+
143
169
if (_maxLength == nil ) {
144
170
return YES ;
145
171
}
@@ -215,6 +241,7 @@ - (void)textViewDidBeginEditing:(UITextView *)textView
215
241
[_eventDispatcher sendTextEventWithType: RCTTextEventTypeFocus
216
242
reactTag: self .reactTag
217
243
text: textView.text
244
+ key: nil
218
245
eventCount: _nativeEventCount];
219
246
}
220
247
@@ -225,6 +252,7 @@ - (void)textViewDidChange:(UITextView *)textView
225
252
[_eventDispatcher sendTextEventWithType: RCTTextEventTypeChange
226
253
reactTag: self .reactTag
227
254
text: textView.text
255
+ key: nil
228
256
eventCount: _nativeEventCount];
229
257
230
258
}
@@ -234,6 +262,7 @@ - (void)textViewDidEndEditing:(UITextView *)textView
234
262
[_eventDispatcher sendTextEventWithType: RCTTextEventTypeEnd
235
263
reactTag: self .reactTag
236
264
text: textView.text
265
+ key: nil
237
266
eventCount: _nativeEventCount];
238
267
}
239
268
@@ -253,6 +282,7 @@ - (BOOL)resignFirstResponder
253
282
[_eventDispatcher sendTextEventWithType: RCTTextEventTypeBlur
254
283
reactTag: self .reactTag
255
284
text: _textView.text
285
+ key: nil
256
286
eventCount: _nativeEventCount];
257
287
}
258
288
return result;
0 commit comments