Skip to content

Commit

Permalink
Add _isCurrentlyEditing to RCTBaseTextInputView
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Gleitman committed Aug 9, 2024
1 parent 67152e1 commit bc84a27
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ @implementation RCTBaseTextInputView {
BOOL _hasInputAccessoryView;
// [macOS] remove explicit _predictedText ivar declaration
BOOL _didMoveToWindow;
BOOL _isCurrentlyEditing; // [macOS] avoids duplicating effects of textInputDid(Begin|End)Editing calls
}

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

return self;
Expand Down Expand Up @@ -455,16 +457,19 @@ - (void)textInputDidBeginEditing
[self.backedTextInputView selectAll:nil];
}
#if TARGET_OS_OSX // [macOS
} else {
} else if (!_isCurrentlyEditing) {
[self.backedTextInputView setSelectedTextRange:NSMakeRange(NSNotFound, 0) notifyDelegate:NO];
#endif // macOS]
}

[_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus
reactTag:self.reactTag
text:[self.backedTextInputView.attributedText.string copy]
key:nil
eventCount:_nativeEventCount];
if (!_isCurrentlyEditing) { // [macOS] avoid sending duplicate onFocus events
_isCurrentlyEditing = YES; // [macOS]
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus
reactTag:self.reactTag
text:[self.backedTextInputView.attributedText.string copy]
key:nil
eventCount:_nativeEventCount];
} // [macOS]
}

- (BOOL)textInputShouldEndEditing
Expand All @@ -474,8 +479,16 @@ - (BOOL)textInputShouldEndEditing

- (void)textInputDidEndEditing
{
// [macOS avoid sending duplicate onEndEditing/onBlur events
if (!_isCurrentlyEditing) {
return;
}
_isCurrentlyEditing = NO;
// macOS]

self.ghostText = nil; // [macOS]


[_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd
reactTag:self.reactTag
text:[self.backedTextInputView.attributedText.string copy]
Expand Down

0 comments on commit bc84a27

Please sign in to comment.