-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Adds declarative props to clear/submit TextInput #7333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I haven't added anything to TextInput.windows.js (though it works w/o declaring the prop types) and this should probably include an e2e test / update to RNTester. Will work on those once we decide if this is worth landing. |
42f8f6e to
413b3f4
Compare
|
@rozele thanks for sending this out! I'd love for these types of changes to be discussed at one of the design reviews. For example, is it necessary to have a property for "clear on submit" instead of just having the app do the clear on an onSubmit event handler? |
| Super::updateProperties(props); | ||
|
|
||
| // We need to re-register the PreviewKeyDown handler so it is invoked after the ShadowNodeBase handler | ||
| if (hasKeyDownEvents) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? I thought Subclass::UpdateProperties gets called after the ShadowNodeBase keyboard handler gets bound in the PreviewKeyboardEventHandlerOnRoot constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - this is necessary. Although the root-level keyboard event handler for emitting key events gets subscribed before any of these props get set, the view-level keyboard event handler that sets Handled(true) on the routed events gets subscribed in Super::updateProperties.
If we subscribe to PreviewKeyDown for onSubmitEditing before we subscribe to PreviewKeyDown for keyDownEvents, then we'll always call onSubmitEditing, even if the key was intended to be marked Handled by the keyDownEvents prop.
Note, this wasn't a problem before because you could just use keyDownEvents={[{code: 'Enter', handledEventPhase: Capturing}]} to mark the event as Handled in the preview phase, and the KeyDown event that was previously used for onSubmitEditing would not be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Then, I have a few questions:
- Since
UpdatePropertieswill be called at least once (and potentially many times during the lifespan of the component), do we need still need the initial registration up inregisterEvents()? Not sure how expensive these are, though.. - This seems to result in the re-registration of the Preview handler every time that
UpdatePropertiesis called for a TextInput withkeyDownEventsspecified - can we avoid that? - Just to confirm - do you need to switch from listening to
KeyDowntoPreviewKeyDown,so that you can stop the submission on 'Enter'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We still need the initial registration in case keyDownEvents is never set.
- I don't believe it's that expensive, but it will only be re-registered any time someone changes keyDownEvents, which is likely to be infrequent. It's probably not worth the added complexity to add a state field that signals when we've already re-registered.
- Not exactly. We now need to handle onSubmitEditing in PreviewKeyDown as opposed to KeyDown because we want submitKeyEvents to apply even to TextBox with AcceptsReturn == true. If we used KeyDown, there would be no way to intercept 'Enter' before it created a newline character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we subscribe to PreviewKeyDown for onSubmitEditing before we subscribe to PreviewKeyDown for keyDownEvents, then we'll always call onSubmitEditing, even if the key was intended to be marked Handled by the keyDownEvents prop.
Just for my information - this relies on the event handlers being called in the order of their registration for a given event type - is that guaranteed not to change (and documented somewhere)?
Can you add some examples to RNTester? Otheriwse, I think it looks great. |
This change adds two new props and a new behavior for multiline
TextInput.
New props:
1. `clearTextOnSubmit`: similar to `clearTextOnFocus`, except that it
clears out the TextInput whenever the `onSubmitEditing` event would be
dispatched.
2. `submitKeyEvents`: registers a set of key down events that will
trigger `onSubmitEditing` for multiline TextInput.
New behavior:
Previously, `onSubmitEditing` would never fire when `multiline={true}`
for a TextInput. Now, `onSubmitEditing` may fire for a multiline
TextInput if a key down event matching the configuration in
`submitKeyEvents` is observed.
Fixes microsoft#7330
|
@rectified95 Added an RNTester example: playground.2021-04-09.12-30-18.mp4 |
…e-windows#7333)
Summary:
This change adds two new props and a new behavior for multiline
TextInput.
New props:
1. `clearTextOnSubmit`: similar to `clearTextOnFocus`, except that it
clears out the TextInput whenever the `onSubmitEditing` event would be
dispatched.
2. `submitKeyEvents`: registers a set of key down events that will
trigger `onSubmitEditing` for multiline TextInput.
New behavior:
Previously, `onSubmitEditing` would never fire when `multiline={true}`
for a TextInput. Now, `onSubmitEditing` may fire for a multiline
TextInput if a key down event matching the configuration in
`submitKeyEvents` is observed.
Fixes microsoft#7330
See also microsoft#7333
Test Plan:
1. Clone into FBS
2. Modify ComposerEditor to leverage `onSubmitEditing` and `submitKeyEvents` instead of `keyDownEvents` when `Platform.OS === 'windows'
3. Ensure tasks below are resolved
{F481095305}
Reviewers: skyle, mylando
Reviewed By: skyle
Subscribers: eliwhite
Differential Revision: https://phabricator.intern.facebook.com/D26918559
Tasks: T84376196, T86162323, T85964399, T85628355
Signature: 26918559:1615423313:ad9d9ebe90e27919cc10b6cd4fa48041f1069006
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492
This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492 Co-authored-by: Alex Chiu <ackchiu@fb.com>
…1423) This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492 Co-authored-by: Alex Chiu <ackchiu@fb.com> # Conflicts: # Libraries/Components/TextInput/TextInput.js # Libraries/Text/TextInput/RCTBackedTextInputDelegate.h # Libraries/Text/TextInput/RCTBaseTextInputView.h # Libraries/Text/TextInput/RCTBaseTextInputView.m # Libraries/Text/TextInput/RCTBaseTextInputViewManager.m
…1423) This brings macOS parity with react-native-windows microsoft/react-native-windows#7333 for MultilineTextInput fields See react-native-windows PR for desired feature set. We can't do it for SinglelineTextInput fields (at least not w/o hacks) as it does not support overriding the keyDown event :-( https://stackoverflow.com/a/6076492 Co-authored-by: Alex Chiu <ackchiu@fb.com> # Conflicts: # Libraries/Components/TextInput/TextInput.js # Libraries/Text/TextInput/RCTBackedTextInputDelegate.h # Libraries/Text/TextInput/RCTBaseTextInputView.h # Libraries/Text/TextInput/RCTBaseTextInputView.m # Libraries/Text/TextInput/RCTBaseTextInputViewManager.m
This change adds two new props and a new behavior for multiline TextInput.
New props:
clearTextOnSubmit: similar toclearTextOnFocus, except that it clears out the TextInput whenever theonSubmitEditingevent would be dispatched.submitKeyEvents: registers a set of key down events that will triggeronSubmitEditingfor multiline TextInput.New behavior:
Previously,
onSubmitEditingwould never fire whenmultiline={true}for a TextInput. Now,onSubmitEditingmay fire for a multiline TextInput if a key down event matching the configuration insubmitKeyEventsis observed.Fixes #7330
Microsoft Reviewers: Open in CodeFlow