KeboardAvoidingView not working on standalone app [React Native Expo] - react-native

The KeyBoardAvoidingView is working fine in the expo testing but when i build a stand alone app it does not work at all.
PS: i am using react navigation but the header is set to null.
KeyBoardAvoidingView Usage Code
<KeyboardAvoidingView behavior='padding'>
<TextInput style={styles.formTextInput}
onChangeText={this.emailOnChange}
value={this.state.email}
placeholder={'Email...'}
onSubmitEditing={() => { this.secondTextInput.focus(); }}
blurOnSubmit={false}
autoCapitalize='none'
returnKeyType='next'
keyboardType='email-address'
/>
<TextInput style={styles.formTextInput}
onChangeText={this.passwordOnChange}
value={this.state.password}
ref={(input) => { this.secondTextInput = input; }}
password={true}
secureTextEntry={true}
placeholder={'Password...'}
maxLength={20}
autoCapitalize='none'
/>
</KeyboardAvoidingView>

Can you try with this one,
import {
View,
KeyboardAvoidingView,
ScrollView,
Platform,
} from "react-native";
<View style={{ flex: 1 }}>
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : null}
style={{ flex: 1 }}
enabled
>
<ScrollView keyboardShouldPersistTaps="always">
<EmailField />
<PasswordField />
</ScrollView>
</KeyboardAvoidingView>
</View>
Customize your TextInputs

Related

React Native scrollview not working in android

I am using a ScrollView in my react-native app. The App work fine in my iOS simulator but when I test in my Android emulator the ScrollView does not work.
Here is what my React Components returns
<SafeAreaView style={styles.container}>
<Image
source={require('../assets/images/logo.png')}
style={styles.logo}
/>
<Androw style={styles.shadow}>
<Text style={[styles.logoText, styles.shadow]}>{NAME}</Text>
</Androw>
<Text style={styles.title}>Welcome Back</Text>
<View style={styles.subContainer}>
<ScrollView showsVerticalScrollIndicator={false}>
<Text style={styles.loginText}>Login</Text>
<View style={styles.textBox}>
<Input
// icon="email"
placeholder="Email or username"
autoCapitalize="none"
autoCompleteType="email"
value={this.state.email}
onChangeText={(txt) => this.setState({email: txt})}
/>
<View style={styles.textInput}>
<Input
// icon="pass"
placeholder="Password"
autoCapitalize="none"
autoCompleteType="password"
value={this.state.password}
onChangeText={(txt) => this.setState({password: txt})}
/>
</View>
</View>
<TouchableOpacity>
<Text style={styles.forgotPasswordText}>
Don't remember your password?
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => console.log(this.state)}>
<Button text="Login" />
</TouchableOpacity>
<Text style={styles.noAccountText}>
Don't have an account?{' '}
<Text style={styles.signupText}>Signup</Text>
</Text>
</ScrollView>
</View>
</SafeAreaView>
you should wrap your child views inside like
<ScrollView>
<View>
.....
</View>
</ScrollView>
Top <View> must have style flex:1. Alternate try doing like this
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
...
</ScrollView>
SafeAreaView that does not require flex: 1. Also try removing it from ScrollView too if it is there.
This is what i assume. Would be more helpful if you share your stylesheet also.

React Native - Moving up screen in TextInput with KeyboardAvoidingView

I have a view with some TextInputs, and some of them are in the bottom part of the screen. The thing is I want the screen to move up when I click on them to that way I can see what I'm writing. I searched a lot but nothing works for me, I have my view nested in a KeyboardAvoidingView but nothing happens when I click on the TextInput. Here's my code:
<KeyboardAvoidingView
keyboardVerticalOffset={64}
style={{ flex: 1 }}
>
<View style={styles.screen}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<TextInput
value={title}
onChangeText={text => setTitle(text)}
style={styles.singleLineTextInput}
placeholder="Title"
/>
<TextInput
value={keywords}
onChangeText={text => setKeywords(text)}
style={styles.singleLineTextInput}
placeholder="Keywords"
/>
<TextInput
value={description}
onChangeText={text => setDescription(text)}
style={{ ...styles.singleLineTextInput, ...styles.descriptionTextInput }}
placeholder="Description"
multiline={true}
autoFocus={true}
/>
</TouchableWithoutFeedback>
</View>
</KeyboardAvoidingView >
And my styles:
const styles = StyleSheet.create({
screen: {
flex: 1,
padding: 16,
alignItems: 'center'
},
singleLineTextInput: {
width: DEVICE_WIDTH * 0.8,
borderColor: 'black',
borderBottomWidth: 2,
fontSize: 16,
paddingHorizontal: 16
},
descriptionTextInput: {
maxHeight: DEVICE_HEIGHT / 4
}
});
I'm using React-Navigation and I tried changing keyboardVertialOffset and behavior to multiples values but nothing happens. Any ideas?
Thanks in advance
Import Content from native-base as
import { Content } from 'native-base';
And import platform from react-native
import { Platform } from 'react-native';
And use content and platform in your code like this:
<KeyboardAvoidingView
behavior={Platform.Os == "ios" ? "padding" : "height"}
style={{ flex: 1 }}
><Content>
<View style={styles.screen}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<TextInput
value={title}
onChangeText={text => setTitle(text)}
style={styles.singleLineTextInput}
placeholder="Title"
/>
<TextInput
value={keywords}
onChangeText={text => setKeywords(text)}
style={styles.singleLineTextInput}
placeholder="Keywords"
/>
<TextInput
value={description}
onChangeText={text => setDescription(text)}
style={{ ...styles.singleLineTextInput, ...styles.descriptionTextInput }}
placeholder="Description"
multiline={true}
autoFocus={true}
/>
</TouchableWithoutFeedback>
</View>
</Content>
</KeyboardAvoidingView>
Hope this helps!

Text inputs covered by Keyboard (React-Native)

I'm trying to create a new simple app. While in this process, I've decided to start with a login page and a sign up page. These pages have the same styling, where the top third of the screen is a container with a logo in it, and the bottom two thirds is a form with input fields.
The problem that I'm stuck at now is that everything looks great, but when you press one of the inputs then the keyboard covers most of the inputs. I've done a little research and I've tried to apply both ScrollView and KeyboardAvoidingView, but neither of these seem to work properly.
This is how my page is set up:
<View style={styles.screen}>
{this.state.loading && (
<View style={styles.loading}>
<ActivityIndicator
color={primaryColor}
size="large"
/>
</View>
)}
<View style={styles.logoContainer}>
<Image source={require('../../../assets/logo.png')} style={styles.logo} />
</View>
<View style={styles.formContainer}>
<KeyboardAvoidingView
behavior={'padding'}
enabled
style={styles.form}
>
<FloatingLabelInput
blurOnSubmit={false}
editable={true}
keyboardType={'email-address'}
label="Email"
onChangeText={this.handleEmailChange}
onSubmitEditing={() => this.passwordInput && this.passwordInput.focus()}
ref={(input) => { this.emailInput = input; }}
returnKeyType="next"
value={this.state.email}
/>
<FloatingLabelInput
editable={true}
label="Password"
onChangeText={this.handlePasswordChange}
onSubmitEditing={() => this.signup()}
ref={(input) => { this.passwordInput = input; }}
secureTextEntry={true}
value={this.state.password}
/>
</KeyboardAvoidingView>
<View style={styles.buttonContainer}>
<Button buttonFunction={() => this.signup()} buttonStyle={'primary'} buttonText={'Sign Up'} />
</View>
</View>
</View>
I feel like I've exhausted most solutions, but I must be missing something crucial.
I had added a Content component in your code, which solves your problem. I don't know why issue had gone by removing KeyboardAvoidingView, but if you want to use KeyboardAvoidingView you can do like this.
<View style={styles.container}>
<Content>
<View style={{ alignItems: "center", marginTop: "50%" }}>
<Image source={require('../assets/CustomLogo1.png')} style={{ marginLeft: 10, marginBottom: 20, height: 200, width: 200 }} />
</View>
<View>
<KeyboardAvoidingView behavior={Platform.Os == "ios" ? "padding" : "height"}>
<FloatingLabelInput
blurOnSubmit={false}
editable={true}
keyboardType={'email-address'}
label="Email"
onChangeText={this.handleEmailChange}
onSubmitEditing={() => this.passwordInput && this.passwordInput.focus()}
ref={(input) => { this.emailInput = input; }}
returnKeyType="next"
value="sample mail"
/>
<FloatingLabelInput
editable={true}
label="Password"
onChangeText={this.handlePasswordChange}
onSubmitEditing={() => this.signup()}
ref={(input) => { this.passwordInput = input; }}
secureTextEntry={true}
value="password"
/>
</KeyboardAvoidingView>
<View style={{ marginTop: 20 }}>
<Button buttonFunction={() => this.signup()} title="sign up" />
</View>
</View>
</Content>
</View>
Initial login page when there is a problem in focusing password:
After making some necessary changes it will be like this:
Just add a content component which can be imported from native base after your View component. I think removing KeyBoardAvoidingView will not fix the issue for smaller screens.
Hope this helps!

KeyboardAvoidingView is not supporting in IOS devices

I want to get the textInputs without covering by Keyboard.
I have tried with keyboardAvoidingView but it is only supports in Android.
<KeyboardAvoidingView>
<SafeAreaView keyboardShouldPersistTaps={'handled'}>
<View style={styles.middleView}>
<Text>Login</Text>
<TextInput
placeholder="example#google.com"
placeholderTextColor="#a4b0be"
returnKeyType="go"
keyboardType="email-address"
autoCapitalize="none"
autoCorrect={false}
autoFocus={true}
/>
<TouchableOpacity>
<Text style=Login</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</KeyboardAvoidingView>
How I can solve this. Is there any other library to do this?
KeyboardAvoidingView behaves differently on iOS and Android. On iOS is it recommended to add the behavior props, and I usually use 'padding' which works fine in most cases:
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
>
Install React Native Keyboard Spacer,
npm install --save react-native-keyboard-spacer
You can use this for iOS Application. KeyboardAoidingView is working perfectly in Android. So apply this library only for iOS platform.
import KeyboardSpacer from 'react-native-keyboard-spacer';
{Platform.OS === 'android' &&
<KeyboardAvoidingView>
<SafeAreaView keyboardShouldPersistTaps={'handled'}>
<View style={styles.middleView}>
<Text>Login</Text>
<TextInput
placeholder="example#google.com"
placeholderTextColor="#a4b0be"
returnKeyType="go"
keyboardType="email-address"
autoCapitalize="none"
autoCorrect={false}
autoFocus={true}
/>
<TouchableOpacity>
<Text style=Login</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</KeyboardAvoidingView>
}
{Platform.OS === 'iOS' &&
<SafeAreaView keyboardShouldPersistTaps={'handled'}>
<View style={styles.middleView}>
<Text>Login</Text>
<TextInput
placeholder="example#google.com"
placeholderTextColor="#a4b0be"
returnKeyType="go"
keyboardType="email-address"
autoCapitalize="none"
autoCorrect={false}
autoFocus={true}
/>
<TouchableOpacity>
<Text style=Login</Text>
</TouchableOpacity>
</View>
<KeyboardSpacer/>
</SafeAreaView>
}
to solve the keyboard issue in iPhone and Android I recommend you to use the awesome package
https://github.com/APSL/react-native-keyboard-aware-scroll-view

React Native - How to combine TouchableWithoutFeedback with KeyboardAvoidingView?

This is my code:
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<KeyboardAvoidingView style={styles.container} behavior="padding" enabled>
<Text style={styles.title}>Login</Text>
<ActivityIndicator size="large" color="#0000ff" animating={this.state.isProcessing} />
<View style={styles.inputContainer}>
<TextInput
style={styles.textInput}
onChangeText={(email) => this.setState({ email })}
value={this.state.email}
keyboardType="email-address"
textContentType="emailAddress"
placeholder="Email"
editable={!this.state.isProcessing}
/>
</View>
<View style={styles.inputContainer}>
<TextInput
style={styles.textInput}
onChangeText={(password) => this.setState({ password })}
value={this.state.password}
secureTextEntry={true}
placeholder="Password"
editable={!this.state.isProcessing}
/>
</View>
<View style={styles.inputContainer}>
<TouchableOpacity
style={styles.button}
onPress={this.logIn.bind(this)}
disabled={this.state.isProcessing}
>
<Text style={{ color: '#fefffe' }}>Login</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
</TouchableWithoutFeedback>
Keyboard.dismiss can work properly, but KeyboardAvoidingView does not work completely.
If I touch the TextInput, KeyboardAvoidingView will not adjust position based on the position of the keyboard.
Why does this happened?
Please help me. Thanks a lot.