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:
Родитель
1bc9ddbce3
Коммит
477663cba8
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче