Skip to content

Commit

Permalink
Deduplicate textInputDid(Begin|End)Editing calls for multiline `<Te…
Browse files Browse the repository at this point in the history
…xtInput>` 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]>
amgleitman and Adam Gleitman authored Aug 19, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 23a33f2 commit 6785f6d
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -36,6 +36,9 @@ @implementation RCTBaseTextInputView {
BOOL _hasInputAccessoryView;
// [macOS] remove explicit _predictedText ivar declaration
BOOL _didMoveToWindow;
#if TARGET_OS_OSX // [macOS avoids duplicating effects of textInputDid(Begin|End)Editing calls
BOOL _isCurrentlyEditing;
#endif // macOS]
}

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

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

- (void)textInputDidBeginEditing
{
#if TARGET_OS_OSX // [macOS consolidate duplicate callbacks
if (_isCurrentlyEditing) {
return;
}
_isCurrentlyEditing = YES;
#endif // macOS]

if (_clearTextOnFocus) {
self.backedTextInputView.attributedText = [NSAttributedString new];
}
@@ -474,6 +487,13 @@ - (BOOL)textInputShouldEndEditing

- (void)textInputDidEndEditing
{
#if TARGET_OS_OSX // [macOS consolidate duplicate callbacks
if (!_isCurrentlyEditing) {
return;
}
_isCurrentlyEditing = NO;
#endif // macOS]

self.ghostText = nil; // [macOS]

[_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd

0 comments on commit 6785f6d

Please sign in to comment.