Skip to content

Commit 6785f6d

Browse files
amgleitmanAdam Gleitman
andauthored
Deduplicate textInputDid(Begin|End)Editing calls for multiline <TextInput> elements (#2159)
* Add _isCurrentlyEditing to RCTBaseTextInputView * Move _isCurrentlyEditing check earlier in textInputDidBeginEditing * Adjust comment * nit: remove extra newline * Limit changes to macOS --------- Co-authored-by: Adam Gleitman <[email protected]>
1 parent 23a33f2 commit 6785f6d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ @implementation RCTBaseTextInputView {
3636
BOOL _hasInputAccessoryView;
3737
// [macOS] remove explicit _predictedText ivar declaration
3838
BOOL _didMoveToWindow;
39+
#if TARGET_OS_OSX // [macOS avoids duplicating effects of textInputDid(Begin|End)Editing calls
40+
BOOL _isCurrentlyEditing;
41+
#endif // macOS]
3942
}
4043

4144
#if !TARGET_OS_OSX // [macOS]
@@ -71,6 +74,9 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
7174
if (self = [super initWithEventDispatcher:bridge.eventDispatcher]) { // [macOS]
7275
_bridge = bridge;
7376
_eventDispatcher = bridge.eventDispatcher;
77+
#if TARGET_OS_OSX // [macOS
78+
_isCurrentlyEditing = NO;
79+
#endif // macOS]
7480
}
7581

7682
return self;
@@ -446,6 +452,13 @@ - (BOOL)textInputShouldBeginEditing
446452

447453
- (void)textInputDidBeginEditing
448454
{
455+
#if TARGET_OS_OSX // [macOS consolidate duplicate callbacks
456+
if (_isCurrentlyEditing) {
457+
return;
458+
}
459+
_isCurrentlyEditing = YES;
460+
#endif // macOS]
461+
449462
if (_clearTextOnFocus) {
450463
self.backedTextInputView.attributedText = [NSAttributedString new];
451464
}
@@ -474,6 +487,13 @@ - (BOOL)textInputShouldEndEditing
474487

475488
- (void)textInputDidEndEditing
476489
{
490+
#if TARGET_OS_OSX // [macOS consolidate duplicate callbacks
491+
if (!_isCurrentlyEditing) {
492+
return;
493+
}
494+
_isCurrentlyEditing = NO;
495+
#endif // macOS]
496+
477497
self.ghostText = nil; // [macOS]
478498

479499
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd

0 commit comments

Comments
 (0)