-
Notifications
You must be signed in to change notification settings - Fork 139
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
Support for more onKeyPress actions #437
Comments
Hi @ospfranco . Regarding fine grain key events within a TextInput we have no plans to deviate from the upstream react-native behavior. For enter key events in a single line TextInput the onSubmit event should fire. For multiline TextInput the onTextChange or onKeyPress should contain If upstream react-native adds low level key event handlers for arrow case and such in a future release, then react-native-macos fork would implement them. Thanks! |
ok, good to know, thanks! |
@tom-un I'm thinking it is worth reconsidering this decision, I'm continuing trying to build an autocomplete box but not having much success. As you suggested, I'm trying to use onSelectionChange to catch arrow events, however typing on the box also changes the selection on the field, therefore I cannot distinguish when something has been typed or when the arrow key has been pressed: <KTextInput
placeholder="Start typing..."
value={text}
onChangeText={(t) => {
console.warn(`text changed`, t)
setText(t)
}}
onSubmitEditing={_onCommit}
multiline
numberOfLines={5}
style={styles.input}
autoFocus
onSelectionChange={(event) => {
console.warn(`selection change`, event.nativeEvent)
if (autocompleteVisible) {
console.warn(`should highlight next item`)
} else {
console.warn(`setting selection`)
setInputSelection(event.nativeEvent.selection)
}
}}
selection={inputSelection}
// onKeyPress={onKeyPress}
/> The console output for this code, when I try to type something is:
also the fact that the two callbacks fire independently of each other creates a level of asynchronicity that is hard to reason about, like I said, I cannot distinguish a pure selection change from something has been typed in each render cycle Maybe you have some pointers or an idea of how to accomplish this? |
Unlike mobile devices, the keyboard is the main input on desktop, I was trying to create an autocomplete text input, but I've just fallen short, I've tried to attach an onKeyPress to a TextInput, but it has not been updated to handle all keyboard events, in this particular case, I need to listen to the keyboard arrow keys and the
enter
key.Will support for this functionality be added at some point or should I just try to plug in the hole myself with some native coding?
The text was updated successfully, but these errors were encountered: