Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information