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
Related
I'm using AppIntroSlider with LottieAnimations and i have troubles with animation launching on IOS.
<View style={styles.slide}>
<View style={styles.titleContainer}>
<Text style={styles.title}>{item.title}</Text>
</View>
{item.key > 1 && (
<LottieView
source={item.lottieAnimation}
autoPlay={true}
loop={true}
speed={0.7}
/>
)}
<Image source={item.image} style={styles.image} />
<Text style={styles.text}>{item.text}</Text>
</View>
It shows only a frist frame and animation doesn't start.
"lottie-react-native": "^5.0.1"
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.
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
When I remove TouchableWithoutFeedback then Input text is responding otherwise not.
I tried lots but I am not getting any solution there.
<TouchableWithoutFeedback
onPress={() => {
Keyboard.dismiss();
}}
>
<View style={styles.screen}>
<Text style={styles.title}>The a New Game !</Text>
<Card style={styles.inputContainer}>
<Text>Select a Number</Text>
<Input
style={styles.input}
blurOnSubmit
autoCapitalize="none"
autoCorrect={false}
keyboardType="number-pad"
maxLength={2}
onChange={numberInputHandler}
value={enteredValue}
/>
<View style={styles.buttonContainer}>
<View>
<Button style={styles.button} title="Reset" onPress={() => {}} color={Color.accent} />
</View>
<View>
<Button
style={styles.button}
title="Confirm"
onPress={() => {}}
color={Color.primary}
/>
</View>
</View>
</Card>
</View>
</TouchableWithoutFeedback>
);
};
Try using zIndex( style={{zIndex: 20}} ) on both TextInput and TouchableWithoutFeedback, and make sure you give a greater value to the TextInput.
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.