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 <adgleitm@microsoft.com>
This commit is contained in:
Adam Gleitman 2024-08-19 12:46:09 -07:00 коммит произвёл GitHub
Родитель 23a33f2eff
Коммит 6785f6dba1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 20 добавлений и 0 удалений

Просмотреть файл

@ -36,6 +36,9 @@ static const CGFloat kSingleLineKeyboardBottomOffset = 15.0;
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 @@ static const CGFloat kSingleLineKeyboardBottomOffset = 15.0;
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 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
- (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 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
- (void)textInputDidEndEditing
{
#if TARGET_OS_OSX // [macOS consolidate duplicate callbacks
if (!_isCurrentlyEditing) {
return;
}
_isCurrentlyEditing = NO;
#endif // macOS]
self.ghostText = nil; // [macOS]
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd