From 6785f6dba1c8eb0c1cda7efd28792f546cc651a8 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Mon, 19 Aug 2024 12:46:09 -0700 Subject: [PATCH] Deduplicate `textInputDid(Begin|End)Editing` calls for multiline `` 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 --- .../Text/TextInput/RCTBaseTextInputView.mm | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm index c73e5133d1..b805f10d86 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm @@ -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