I have a problem where I have a TextInput and a button inside a KeyboardAwareScrollView
. I want the user to input some text and then press the button made with TouchableOpacity. This sends the text forward that the user just inputted.
Problem is that after inputting text, one first try TextInput merely loses focus. Only on the next press attempt is the button actually pressed. How can I have the button react on the first press?
I am using this package https://github.com/APSL/react-native-keyboard-aware-scroll-view
My code is as follows:
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
export default class App extends Component<{}> {
render() {
return (
<KeyboardAwareScrollView>
<TextInput
style={{ width: 100, height: 50, backgroundColor: 'blue' }}
/>
<TouchableOpacity
style={{ backgroundColor: 'red', width: 50, height: 50 }}
/>
</KeyboardAwareScrollView>
);
}
}
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. xml . Instead, you should use "adjustResize" and have a wonderful life.
KeyboardAvoidingView is a React Native built-in component with full JS implementation. It relies on RN's keyboard events ( keyboardWillChangeFrame on iOS & keyboardDidHide/Show on Android) and, based on provided behavior prop, applies additional padding, translation, or changes container's height.
Auto scroll is provided out of the box by react native. The ScrollView component by react native has props to scroll to the desired co-ordinates on the screen. There are two such props in ScrollView: ScrollTo(): takes the x and y offset coordinates and scrolls to that position.
Please use keyboardShouldPersistTaps='always' on ScrollView. Below is how to do it.
<ScrollView
keyboardShouldPersistTaps='always' >
</ScrollView>
It's happening because ScrollView
has property to dismiss the keyboard first and then it will allow actions to its child views. Now we are changing that behavior with above property.
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