Avoid keypress event when text is pasted on macOS

Summary:
There is an issue on react-native-macOS in which clipboard pastes cause a keyPress event both for SingleLine and Multiline text fields.

This problem does not exist on iOS.

However, we can fix it for macOS and keep the iOS behavior unchanged.

# Invocation order on macOS

## macOS Singeline textField
- https://github.com/microsoft/react-native-macos/blob/main/Libraries/Text/TextInput/Multiline/RCTUITextView.m#L309 is called
- [NSTextView(NSPasteboard) paste:] () is called
- [NSTextView(NSSharing) shouldChangeTextInRanges:replacementStrings:] () is called
- https://github.com/microsoft/react-native-macos/blob/main/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m#L382 is called
- https://github.com/microsoft/react-native-macos/blob/main/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m#L323 is called
- https://github.com/microsoft/react-native-macos/blob/main/Libraries/Text/TextInput/RCTBaseTextInputView.m#L436

There is the issue. As ```!backedTextInputView.textWasPasted``` is still ```NO``` we accidently send a keyPress event

## macOS Multiline textView
- [NSTextView(NSSharing) shouldChangeTextInRanges:replacementStrings:] () is called
- https://github.com/microsoft/react-native-macos/blob/main/Libraries/Text/TextInput/Singleline/RCTUITextField.m#L438 is called
- https://github.com/microsoft/react-native-macos/blob/main/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m#L91 is called
- https://github.com/microsoft/react-native-macos/blob/main/Libraries/Text/TextInput/RCTBaseTextInputView.m#L436

There is the issue. As ```!backedTextInputView.textWasPasted``` is still ```NO``` we accidently send a keyPress event

# Invocation order on iOS
Problem does not arise as https://github.com/facebook/react-native/blob/main/Libraries/Text/TextInput/RCTBaseTextInputView.m#L381 is not called as [UIPasteboard _performAsDataOwner:block:] () is used, not causing an side-effects

Changelog:
[macOS][Fixed] - Avoid keypress event when text is pasted on macOS

Reviewed By: sammy-SC

Differential Revision: D38460692

fbshipit-source-id: 343425d3866d32973b118c90a5bfd8ee9db146b6
This commit is contained in:
Christoph Purrer 2022-08-09 14:30:35 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 1bc9ddbce3
Коммит 477663cba8
2 изменённых файлов: 2 добавлений и 2 удалений

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

@ -164,8 +164,8 @@ static UIColor *defaultPlaceholderColor()
- (void)paste:(id)sender
{
[super paste:sender];
_textWasPasted = YES;
[super paste:sender];
}
// Turn off scroll animation to fix flaky scrolling.

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

@ -188,8 +188,8 @@
- (void)paste:(id)sender
{
[super paste:sender];
_textWasPasted = YES;
[super paste:sender];
}
#pragma mark - Layout