Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native button press after textInput in Keyboard aware scroll view

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>
    );
  }
}
like image 858
Waltari Avatar asked Nov 22 '17 08:11

Waltari


People also ask

How do you push a view up when a keyboard appears 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. xml . Instead, you should use "adjustResize" and have a wonderful life.

What does keyboard avoiding view do?

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.

How do you scroll automatically react native?

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.


1 Answers

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.

like image 167
Sivajee Battina Avatar answered Nov 04 '22 14:11

Sivajee Battina