Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KeyboardAvoidingView is pushing up content with excessive padding in react native

I am having trouble getting the KeyboardAvoidingView to work properly. For a similar screen it is working smoothly, however, for another it is pushing up content way too far up on the screen, adding excessive amounts of space in between. Any fix?

enter image description here

code:

<KeyboardAvoidingView behavior="padding" style={styles.container}>
         {this.props.signNameErr &&
            (<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
          }
      <View style={styles.formContainer}>
        <TextInput
          style={styles.formInput}
          placeholderTextColor="rgba(255,255,255,0.7)"
          underlineColorAndroid='rgba(0,0,0,0)'
          returnKeyType="next"
          autoCorrect={false}
          onChangeText={(full_name)=> this.setState({full_name})}
          value={this.state.fullname}
          placeholder="Enter Full Name"
          />
          {this.props.signEmailErr &&
            (<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
          }
        <TextInput
          style={styles.formInput}
          placeholderTextColor="rgba(255,255,255,0.7)"
          underlineColorAndroid='rgba(0,0,0,0)'
          returnKeyType="next"
          keyboardType="email-address"
          autoCapitalize="none"
          autoCorrect={false}
          onChangeText={(email)=> this.setState({email})}
          value={this.state.email}
          placeholder="Enter Email"
          keyboardType="email-address"
          />
           {this.props.signPwErr &&
            (<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
          }
        <TextInput
          style={styles.formInput}
          placeholderTextColor="rgba(255,255,255,0.7)"
          underlineColorAndroid='rgba(0,0,0,0)'
          returnKeyType="next"
          autoCorrect={false}
          onChangeText={(password)=> this.setState({password})}
          secureTextEntry={this.state.togglePW}
          value={this.state.password}
          placeholder="Create Password (Min. 6 Char)"
          />
        <TouchableOpacity style={styles.buttonContainer} onPress={this.handleSignup}>
          <Text style={styles.buttonText}>SIGN UP</Text>
        </TouchableOpacity>
      </View >
      </KeyboardAvoidingView>
like image 708
Colin Sygiel Avatar asked May 30 '17 09:05

Colin Sygiel


People also ask

How do I stop keyboard pushing layout up in Android 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 is KeyboardAvoidingView in React Native?

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 make your React Native app respond gracefully when the keyboard pops up?

The first thing you have to do is replace the container View with the KeyboardAvoidingView and then add a behavior prop to it. If you look at the documentation you'll see that it accepts 3 different values — height, padding, position. I've found that padding works in the most predictable manner.

What is keyboardVerticalOffset in React Native?

keyboardVerticalOffset ​ This is the distance between the top of the user screen and the react native view, may be non-zero in some use cases.

What is keyboardavoidingview in React Native?

Post a comment KeyboardAvoidingView is a core component in React Native. This component makes sure the virtual keyboard will never cover the TextInput component so that your user can type without annoyance. Without KeyboardAvodingView, a TextInput might be overlapped by the soft keyboard if it stays near the bottom of the screen:

How to solve the keyboard padding problem in React Native?

There are different ways to solve it. One of the easiest ways is to use KeyboardAvoidingView that you will get with the react-native package. It automatically adjusts the bottom padding of the view based on the keyboard position. In this post, I will show you how to use KeyboardAvoidingView with a simple example.

How to avoid keyboard overlapping on textinput widget in React Native?

KeyboardAvoidingView component is used to avoid keyboard overlapping on TextInput widget in react native. By default if we do not use KeyboardAvoidingView then Keypad will show above TextInput widget on focus.

How to move components once the keyboard appears in React-Native?

KeyboardAvoidingView comes with the react-native package. If we wrap all other components inside it, it will move the components once the keyboard appears. For the above example, after adding KeyboardAvoidingView, it will give the following result : Following are the props it accepts :


1 Answers

You can set the padding, you can even set for android and ios

import {KeyboardAvoidingView,Platform,} from 'react-native';

<KeyboardAvoidingView 
  behavior='padding'
  keyboardVerticalOffset={
  Platform.select({
     ios: () => 0,
     android: () => 200
  })()
}>
   ...content...
</KeyboardAvoidingView>

Just an example, try it out and set how you like. The padding can also be a negative value like -300.

like image 88
Brunaine Avatar answered Oct 18 '22 21:10

Brunaine