I have a TextInput with multiline set to true. I am scrolling to the input on focus with:
scrollResponder.scrollResponderScrollNativeHandleToKeyboard(
React.findNodeHandle(this.refs.myInput),
0,
true
);
However when the multiline TextInput expands the text will be hidden beneath the keyboard. I only want to scroll down when the cursor/current text is not visible. So I can't just run the code above on text change as it would scroll the view even if the current cursor/current text is visible (like editing on the first line).
Is there any way to get the cursor/current text position on screen? Or is there any other way to do what I'm trying to?
Currently:
What I'm trying to achieve:
TextInput has a blurOnSubmit prop; when set to true, the return key dismisses the keyboard. For Multiline TextInput, return key enters a new line and not dismiss the keyboard. So, clicking on some other part of the View should dismiss the keyboard.
How do you control what keyboard pushes up React Native? Use android:windowSoftInputMode="adjustResize". KeyboardAvoidingView and other keyboard-related components don't work quite well if you have "adjustPan" set for your android:windowSoftInputMode in AndroidManifest.
The best way to do it seems to be with the react-native-keyboard-aware-scroll-view library and use the method _scrollToInput and follow what the docs say.
The one thing I had to change was to call "this.scroll.props.scrollToFocusedInput(reactNode)" instead of "this.scroll.scrollToFocusedInput(reactNode)" in the docs!
You may use the onLayout method, provided by the View (which Text extends). It returns the dimensions of the view, which you may use to recalculate the scroll position of your scrollview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With