React Native - Increase view height as per text increases when keyboard open - reactjs

I have created a view which has title and body. Everything works fine but when I add body and keyboard opens then text goes out of the view. Please help me as how can I increase the view height or scroll the view fully so that text must not be out of view.
Code for view
<KeyboardAvoidingView
style={{
display: 'flex',
height: Dimensions.get('window').height,
width: Dimensions.get('window').width,
}}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
<SafeAreaView
style={{
flex: 1,
backgroundColor: !darkTheme
? Colors.light.f2Color
: Colors.dark.backgrounColor,
}}>
{/* header */}
{/* Post Section */}
<View
style={{
width: width * 0.96,
borderRadius: 16,
alignSelf: 'center',
marginTop: height * 0.01,
flex: 0.7,
}}>
<View
style={{
backfaceVisibility: 'hidden',
backgroundColor: !darkTheme
? Colors.light.backgrounColor
: Colors.dark.cardColor,
borderRadius: 16,
flex: 1,
paddingHorizontal: width * 0.02,
}}>
<TextInput
style={{
fontWeight: '300',
fontStyle: 'normal',
fontSize: 20,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.015,
color: !darkTheme ? Colors.light.black : Colors.dark.white,
width: '100%',
marginTop: height * 0.02,
flexWrap: 'wrap',
}}
value={postTitle}
onChangeText={value => {
setPostTitle(value);
}}
maxLength={150}
clearButtonMode="never"
multiline={true}
placeholder="Add a title"
placeholderTextColor={Colors.light.darkgrey}
/>
<TextInput
style={{
fontWeight: '300',
fontStyle: 'normal',
fontSize: 14,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.015,
color: !darkTheme ? Colors.light.black : Colors.dark.white,
width: '100%',
marginTop: height * 0.03,
}}
value={postBody}
onChangeText={value => {
setPostBody(value);
}}
maxLength={1000}
clearButtonMode="always"
multiline={true}
placeholder="Body text"
placeholderTextColor={Colors.light.darkgrey}
/>
{contentType === 'Add Question' && (
<View>
<FlatList
data={choiceArray}
scrollEnabled={true}
renderItem={({item, index}) => (
<View style={{flexDirection: 'row', alignItems: 'center'}}>
<TextInput
style={{
fontWeight: '300',
fontStyle: 'normal',
fontSize: 14,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.015,
marginTop: height * 0.025,
color: !darkTheme
? Colors.light.black
: Colors.dark.white,
width: '90%',
}}
value={postChoices[index]}
onChangeText={value => {
addOptionValue(index, value);
}}
// onEndEditing={(value) => addOptionValue(index, value)}
maxLength={150}
clearButtonMode="never"
multiline={false}
placeholder={
'Option ' +
String.fromCharCode(97 + index).toUpperCase()
}
placeholderTextColor={Colors.light.cardOuterShadow}
/>
{index > 1 ? (
<TouchableOpacity onPress={() => optionCdelete(index)}>
<Image
source={require('../assets/images/red-slash.png')}
/>
</TouchableOpacity>
) : null}
</View>
)}
numColumns={1}
keyExtractor={(item, index) => index}
contentContainerStyle={{
backgroundColor: '#fff',
marginTop: height * 0.02,
}}
showsVerticalScrollIndicator={false}
onEndReachedThreshold={0}
showsHorizontalScrollIndicator={false}
bounces={false}
keyboardShouldPersistTaps="handled"
/>
{choiceArray.length < 4 ? (
<TouchableOpacity
onPress={addNextOption}
style={{
flexDirection: 'row',
marginTop: height * 0.03,
alignItems: 'center',
}}>
<Image source={require('../assets/images/plus.png')} />
<Text
style={{
color: Colors.light.darkgrey,
fontSize: 14,
fontFamily: 'OpenSans-Regular',
marginLeft: width * 0.01,
}}>
Add Option
</Text>
</TouchableOpacity>
) : null}
</View>
)}
{/* {contentType === 'Add Question' && (
<View style={{marginTop: height * 0.02}}>
<View style={{flexDirection: 'row'}}>
<TextInput
style={{
fontWeight: '300',
fontStyle: 'normal',
fontSize: 14,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.015,
color: !darkTheme
? Colors.light.black
: Colors.dark.white,
width: '99%',
marginTop: height * 0.015,
}}
value={optionA}
onChangeText={value => {
setOptionA(value);
}}
onEndEditing={() => addChoices(optionA)}
maxLength={150}
clearButtonMode="never"
multiline={false}
placeholder="Option A"
placeholderTextColor={Colors.light.cardOuterShadow}
/>
</View>
<TextInput
style={{
fontWeight: '300',
fontStyle: 'normal',
fontSize: 14,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.015,
color: !darkTheme ? Colors.light.black : Colors.dark.white,
width: '99%',
marginTop: height * 0.025,
}}
value={optionB}
onChangeText={value => {
setOptionB(value);
}}
onEndEditing={() => addChoices(optionB)}
maxLength={150}
clearButtonMode="never"
multiline={false}
placeholder="Option B"
placeholderTextColor={Colors.light.cardOuterShadow}
/>
{surveyCount > 0 && (
<View style={{flexDirection: 'row'}}>
<TextInput
style={{
fontWeight: '300',
fontStyle: 'normal',
fontSize: 14,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.015,
marginTop: height * 0.025,
color: !darkTheme
? Colors.light.black
: Colors.dark.white,
width: '90%',
}}
value={optionC}
onChangeText={value => {
setOptionC(value);
}}
onEndEditing={() => addChoices(optionC)}
maxLength={150}
clearButtonMode="never"
multiline={false}
placeholder="Option C"
placeholderTextColor={Colors.light.cardOuterShadow}
/>
{optionC.length > 0 && (
<TouchableOpacity onPress={optionCdelete}>
<Image
source={require('../assets/images/red-slash.png')}
/>
</TouchableOpacity>
)}
</View>
)}
{surveyCount == 2 && (
<View style={{flexDirection: 'row'}}>
<TextInput
style={{
fontWeight: '300',
fontStyle: 'normal',
fontSize: 14,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.015,
color: !darkTheme
? Colors.light.black
: Colors.dark.white,
width: '90%',
marginTop: height * 0.025,
}}
value={optionD}
onChangeText={value => {
setOptionD(value);
}}
onEndEditing={() => addChoices(optionD)}
maxLength={150}
clearButtonMode="never"
multiline={false}
placeholder="Option D"
placeholderTextColor={Colors.light.cardOuterShadow}
/>
{optionD.length > 0 && (
<TouchableOpacity onPress={optionDdelete}>
<Image
source={require('../assets/images/red-slash.png')}
/>
</TouchableOpacity>
)}
</View>
)}
{surveyCount < 2 && (
<TouchableOpacity
onPress={() => setSurveyCount(surveyCount + 1)}
style={{
flexDirection: 'row',
marginTop: height * 0.03,
alignItems: 'center',
}}>
<Image source={require('../assets/images/plus.png')} />
<Text
style={{
color: Colors.light.darkgrey,
fontSize: 14,
fontFamily: 'OpenSans-Regular',
marginLeft: width * 0.01,
}}>
Add Option
</Text>
</TouchableOpacity>
)}
</View>
)} */}
</View>
</View>
</SafeAreaView>
</KeyboardAvoidingView>
Images of issue
This is the issue when I am trying to add more data.Please help!

Related

React Native - Each action takes lot of time to perform

I have created a Login Page in my app like always. I created and when I click on Login button it takes around 30 seconds for loader to appear and meanwhile my button get hanged and blank. I don't know why my code is behaving like this.
Validate Login when click login button and show loader on button but it takes around 30 minutes
const validateLogin = () => {
console.log('validate login');
setLoader(true);
if (userName.length === 0 || password.length === 0) {
setLoader(false);
Alert.alert('Username or password cannot be empty.');
} else {
if (!netInfo.isConnected) {
setLoader(false);
Alert.alert('You are not connected to internet. Please try again.');
} else {
const token = JWTToken(userName);
getUser(token);
}
}
};
API Code
const getUser = JWTToken => {
console.log('get use');
var axios = require('axios');
var data = JSON.stringify({
username: userName.toLocaleLowerCase(),
password: password,
});
console.log('signin ', data);
var config = {
method: 'post',
url: BASE_URL + GET_USER,
headers: {
'x-jwt-token': JWTToken,
'Content-Type': 'application/json',
},
data: data,
};
axios(config)
.then(function (response) {
const res = JSON.stringify(response.data);
UI Code
<KeyboardAvoidingView
style={{
display: 'flex',
height: Dimensions.get('window').height,
width: Dimensions.get('window').width,
}}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
<SafeAreaView
style={{
flex: 1,
backgroundColor: !darkTheme
? Colors.light.backgrounColor
: Colors.dark.backgrounColor,
justifyContent: 'center',
alignItems: 'center',
}}>
<View
style={{flex: 0.2, alignItems: 'center', justifyContent: 'center'}}>
{!darkTheme ? (
<Image
source={require('../assets/images/logo.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/logo-white.png')}
resizeMode="contain"
/>
)}
</View>
<View
style={{
alignSelf: 'center',
justifyContent: 'center',
flex: 0.7,
width: width * 0.9,
borderRadius: 20,
backgroundColor: Colors.backgroundColor,
marginHorizontal: width * 0.03,
marginBottom: height * 0.05,
padding: width * 0.03,
marginTop: height * 0.02,
}}>
<Text
style={{
color: !darkTheme
? Colors.light.textColor
: Colors.dark.textColor,
fontFamily: 'FiraSans-Medium',
fontSize: 20,
}}>
{strings.login}
</Text>
{/* Email */}
<View
style={{
flexDirection: 'row',
marginTop: height * 0.02,
width: width,
alignItems: 'center',
}}>
{!darkTheme ? (
<Image
source={require('../assets/images/email.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/email-white.png')}
resizeMode="contain"
/>
)}
<TextInput
style={{
fontSize: 16,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.01,
color: !darkTheme ? Colors.light.black : Colors.light.white,
borderColor: !darkTheme
? Colors.light.textInputLine
: Colors.dark.white,
borderBottomWidth: 1,
width: width * 0.7,
}}
value={userName}
onChangeText={value => {
setUserName(value);
}}
// onSubmitEditing={() => onEmailSubmit()}
clearButtonMode="always"
multiline={false}
placeholder={'Username'}
placeholderTextColor={
!darkTheme ? Colors.light.black65 : Colors.light.white65
}
autoCapitalize="none"
/>
</View>
{/* Password */}
<View
style={{
flexDirection: 'row',
marginTop: height * 0.04,
width: width,
alignItems: 'center',
}}>
{!darkTheme ? (
<Image
source={require('../assets/images/password.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/password-white.png')}
resizeMode="contain"
/>
)}
<TextInput
style={{
fontSize: 16,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.01,
color: !darkTheme ? Colors.light.black : Colors.light.white,
borderColor: !darkTheme
? Colors.light.textInputLine
: Colors.light.white,
borderBottomWidth: 1,
width: width * 0.65,
}}
value={password}
onChangeText={value => {
setPassword(value);
}}
onSubmitEditing={() => checkPassword(password)}
secureTextEntry={securePwd}
placeholder={strings.password}
placeholderTextColor={
!darkTheme ? Colors.light.black65 : Colors.light.white65
}
autoCapitalize="none"
/>
<TouchableOpacity onPress={() => setSecurePwd(!securePwd)}>
{securePwd ? (
!darkTheme ? (
<Image
source={require('../assets/images/eye-close.png')}
resizeMode="contain"
style={{width: 30, height: 20}}
/>
) : (
<Image
source={require('../assets/images/eye-close-white.png')}
resizeMode="contain"
style={{width: 30, height: 20}}
/>
)
) : !darkTheme ? (
<Image
source={require('../assets/images/eye-open.png')}
resizeMode="contain"
style={{width: 30, height: 20}}
/>
) : (
<Image
source={require('../assets/images/eye-open-white.png')}
resizeMode="contain"
style={{width: 30, height: 20}}
/>
)}
</TouchableOpacity>
</View>
<View style={{flexDirection: 'row-reverse'}}>
<TouchableOpacity onPress={goToForgotPwd}>
<Text
style={{
color: Colors.light.blueColor,
fontFamily: 'OpenSans-Regular',
fontSize: 16,
marginRight: width * 0.03,
marginTop: height * 0.005,
}}>
{strings.forgotPassword}
</Text>
</TouchableOpacity>
</View>
{/* sign Up button */}
<View
style={{
width: width * 0.3,
height: height * 0.05,
alignItems: 'center',
justifyContent: 'center',
alignSelf: 'center',
borderRadius: 25,
marginTop: height * 0.07,
backgroundColor: Colors.light.buttonBackground,
}}>
<TouchableOpacity onPress={validateLogin}>
<View>
{!loader ? (
<Text
style={{
color: Colors.light.white,
fontFamily: 'FiraSans-Regular',
fontSize: 17,
}}>
{strings.login}
</Text>
) : (
<ActivityIndicator color={Colors.light.white} />
)}
</View>
</TouchableOpacity>
</View>
</View>
<View
style={{
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
}}>
<Text
style={{
fontFamily: 'OpenSans-Regular',
fontSize: 16,
color: !darkTheme
? Colors.light.placeholderColor
: Colors.light.white,
marginRight: width * 0.01,
}}>
{strings.noSignUp}
</Text>
<TouchableOpacity onPress={goToRegister}>
<Text
style={{
fontFamily: 'OpenSans-Regular',
fontSize: 16,
color: Colors.light.blueColor,
}}>
{strings.register}
</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</KeyboardAvoidingView>
Please help as I am not able to understand why I am having this issue.

React Native -- TouchableOpacity takes time to navigate

I have created an app in which if I am using TouchableOpacity to perform any action or navigate but the issue is that I need to click button multiple times also it takes time to navigate to next place. I am writing simple piece of code but don't know why it causing this issue. Please help.
Code to navigate to Login Screen
goToLogin = () => {
navigation.replace('SignIn');
};
UI Code
<KeyboardAvoidingView
style={{
display: 'flex',
height: Dimensions.get('window').height,
width: Dimensions.get('window').width,
}}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
<ScrollView
style={{
flex: 1,
backgroundColor: !darkTheme
? Colors.light.backgrounColor
: Colors.dark.backgrounColor,
}}>
<View
style={{flex: 0.15, alignItems: 'center', justifyContent: 'center', marginTop:height*0.1}}>
{!darkTheme ? (
<Image
source={require('../assets/images/logo.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/logo-white.png')}
resizeMode="contain"
/>
)}
</View>
<View style={{alignItems:'center', justifyContent:'center', flex: 0.875,}}>
<View
style={{
alignSelf: 'center',
marginTop:height*0.02
}}>
<View
style={{
width: width * 0.9,
borderRadius: 20,
marginHorizontal: width * 0.015,
marginBottom: height * 0.05,
padding: width * 0.03,
shadowColor: '#49494966',
shadowOffset: {
width: -9,
height: -9,
},
shadowRadius: 16,
shadowOpacity: 0.5,
}}>
<View>
<Text
style={{
color: !darkTheme
? Colors.light.textColor
: Colors.dark.textColor,
fontFamily: 'FiraSans-Medium',
fontSize: 20,
}}>
Sign Up
</Text>
{/* Your Name */}
<View
style={{
flexDirection: 'row',
marginTop: height * 0.04,
width: width,
alignItems: 'center',
}}>
{!darkTheme ? (
<Image
source={require('../assets/images/name.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/name-white.png')}
resizeMode="contain"
/>
)}
<TextInput
style={{
fontSize: 16,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.01,
color: !darkTheme ? Colors.light.black : Colors.light.white,
borderColor: !darkTheme
? Colors.light.textInputLine
: Colors.light.white,
borderBottomWidth: 1,
width: width * 0.75,
}}
value={yourName}
onChangeText={value => {
setYourName(value);
}}
clearButtonMode="always"
placeholder="Your Name"
placeholderTextColor={
!darkTheme
? Colors.light.placeholderColor
: Colors.light.white65
}
autoCapitalize="none"
/>
</View>
{/* Date of Birth */}
<TouchableOpacity onPress={showDatepicker}>
<View
style={{
flexDirection: 'row',
marginTop: height * 0.04,
width: width,
alignItems: 'center',
}}>
{!darkTheme ? (
<Image
source={require('../assets/images/dob.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/dob-white.png')}
resizeMode="contain"
/>
)}
<View
style={{
borderColor: Colors.light.textInputLine,
borderBottomWidth: 1,
}}>
<Text
style={{
fontSize: 16,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.01,
color: dateSelected
? Colors.light.textColor
: Colors.light.placeholderColor,
width: width * 0.75,
}}>
{dateSelected ? dob : ' Date of Birth'}
</Text>
</View>
</View>
</TouchableOpacity>
{show && (
<DatePicker
modal
open={show}
date={startDate}
mode="date"
textColor={Colors.light.text}
display="inline"
onConfirm={date => {
setShow(false);
setDate(date);
setDateSelected(true);
setDOB(moment(date).format('MM-DD-YYYY'));
}}
onCancel={() => {
setShow(startDate);
}}
/>
)}
{/* parent name */}
<View
style={{
flexDirection: 'row',
marginTop: height * 0.04,
width: width,
alignItems: 'center',
}}>
{!darkTheme ? (
<Image
source={require('../assets/images/parent-name.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/parent-name-white.png')}
resizeMode="contain"
/>
)}
<TextInput
style={{
fontSize: 16,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.01,
color: !darkTheme ? Colors.light.black : Colors.light.white,
borderColor: !darkTheme
? Colors.light.textInputLine
: Colors.light.white,
borderBottomWidth: 1,
width: width * 0.75,
}}
value={parentName}
onChangeText={value => {
setParentName(value);
}}
clearButtonMode="always"
secureTextEntry={false}
placeholder="Parent Name"
placeholderTextColor={
!darkTheme
? Colors.light.placeholderColor
: Colors.light.white
}
autoCapitalize="none"
/>
</View>
{/* Email */}
<View
style={{
flexDirection: 'row',
marginTop: height * 0.04,
width: width,
alignItems: 'center',
}}>
{!darkTheme ? (
<Image
source={require('../assets/images/email.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/email-white.png')}
resizeMode="contain"
/>
)}
<TextInput
style={{
fontSize: 16,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.01,
color: !darkTheme ? Colors.light.black : Colors.light.white,
borderColor: !darkTheme
? Colors.light.textInputLine
: Colors.light.white,
borderBottomWidth: 1,
width: width * 0.75,
}}
value={email}
onChangeText={value => {
setEmail(value);
}}
onSubmitEditing={() => onEmailSubmit()}
clearButtonMode="always"
placeholder="Email"
placeholderTextColor={
!darkTheme
? Colors.light.placeholderColor
: Colors.light.white
}
autoCapitalize="none"
/>
</View>
{/* UserName */}
<View
style={{
flexDirection: 'row',
marginTop: height * 0.04,
width: width,
alignItems: 'center',
}}>
{!darkTheme ? (
<Image
source={require('../assets/images/username.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/username-white.png')}
resizeMode="contain"
/>
)}
<TextInput
style={{
fontSize: 16,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.01,
color: !darkTheme ? Colors.light.black : Colors.light.white,
borderColor: !darkTheme
? Colors.light.textInputLine
: Colors.light.white,
borderBottomWidth: 1,
width: width * 0.75,
}}
value={userName}
onChangeText={value => {
setUserName(value.toLowerCase());
}}
clearButtonMode="always"
secureTextEntry={false}
placeholder="Username"
placeholderTextColor={
!darkTheme
? Colors.light.placeholderColor
: Colors.light.white
}
autoCapitalize="none"
/>
</View>
{/* Password */}
<View
style={{
flexDirection: 'row',
marginTop: height * 0.04,
width: width,
alignItems: 'center',
}}>
{!darkTheme ? (
<Image
source={require('../assets/images/password.png')}
resizeMode="contain"
/>
) : (
<Image
source={require('../assets/images/password-white.png')}
resizeMode="contain"
/>
)}
<TextInput
style={{
fontSize: 16,
fontFamily: 'OpenSans-Regular',
paddingHorizontal: width * 0.01,
color: !darkTheme ? Colors.light.black : Colors.light.white,
borderColor: !darkTheme
? Colors.light.textInputLine
: Colors.light.white,
borderBottomWidth: 1,
width: width * 0.7,
}}
value={password}
onChangeText={value => {
setPassword(value);
}}
onSubmitEditing={() => checkPassword(password)}
secureTextEntry={securePwd}
placeholder="Password"
placeholderTextColor={
!darkTheme
? Colors.light.placeholderColor
: Colors.light.white
}
autoCapitalize="none"
/>
<TouchableOpacity onPress={() => setSecurePwd(!securePwd)}>
{securePwd ? (
!darkTheme ? (
<Image
source={require('../assets/images/eye-close.png')}
resizeMode="contain"
style={{width: 30, height: 20}}
/>
) : (
<Image
source={require('../assets/images/eye-close-white.png')}
resizeMode="contain"
style={{width: 30, height: 20}}
/>
)
) : !darkTheme ? (
<Image
source={require('../assets/images/eye-open.png')}
resizeMode="contain"
style={{width: 30, height: 20}}
/>
) : (
<Image
source={require('../assets/images/eye-open-white.png')}
resizeMode="contain"
style={{width: 30, height: 20}}
/>
)}
</TouchableOpacity>
</View>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
marginTop: height * 0.01,
}}>
<Text
style={{
color: !darkTheme
? Colors.light.placeholderColor
: Colors.light.white65,
fontFamily: 'OpenSans-Regular',
fontSize: 16,
marginRight: width * 0.03,
marginLeft: width * 0.01,
textAlign: 'justify',
}}>
{strings.tNc}
<Text
style={{
color: Colors.light.blueColor,
fontFamily: 'OpenSans-Regular',
fontSize: 16,
}}>
{strings.terms}
</Text>
<Text
style={{
color: !darkTheme
? Colors.light.placeholderColor
: Colors.light.white65,
fontFamily: 'OpenSans-Regular',
fontSize: 16,
}}>
{strings.and}
</Text>
<Text
style={{
color: Colors.light.blueColor,
fontFamily: 'OpenSans-Regular',
fontSize: 16,
}}>
{strings.privacyPolicy}
</Text>
</Text>
</View>
{/* sign Up button */}
<View
style={{
width: width * 0.3,
height: height * 0.05,
alignItems: 'center',
justifyContent: 'center',
alignSelf: 'center',
borderRadius: 25,
marginTop: height * 0.04,
backgroundColor: Colors.light.buttonBackground,
marginBottom: height * 0.04,
}}>
<TouchableOpacity
onPress={() => {
validateSignUp();
}}>
<View>
{!loader ? (
<Text
style={{
color: Colors.dark.textColor,
fontFamily: 'FiraSans-Regular',
fontSize: 17,
}}>
{strings.signUp}
</Text>
) : (
<ActivityIndicator color={Colors.light.white} />
)}
</View>
</TouchableOpacity>
</View>
</View>
</View>
</View>
<View
style={{
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
flex: 0.07,
}}>
<Text
style={{
fontFamily: 'OpenSans-Regular',
fontSize: 16,
color: !darkTheme
? Colors.light.placeholderColor
: Colors.light.white65,
marginRight: width * 0.01,
}}>
{strings.alreadyUser}
</Text>
<TouchableOpacity onPress={goToLogin}>
<Text
style={{
fontFamily: 'OpenSans-Regular',
fontSize: 16,
color: Colors.light.blueColor,
}}>
{strings.login}
</Text>
</TouchableOpacity>
</View>
</View>
</ScrollView>
</KeyboardAvoidingView>
Login Button Code
<TouchableOpacity onPress={goToLogin}>
<Text
style={{
fontFamily: 'OpenSans-Regular',
fontSize: 16,
color: Colors.light.blueColor,
}}>
{strings.login}
</Text>
</TouchableOpacity>
Could anyone please help me in this issue as I got fed up with this issue.
Thanks in advance

Keyboard closed on click on button in react native

I have creating a comment modal in which user can add comment. This section has a list of comments and a text input field to enter comments and a button to submit comment but the problem is the I enter something in text input and then press button to submit comment but first time it closes the keyboard and then I need to press button again to add the text into the array.
My problem is why I need to press two times. Why on first time my keyboard got closed.
<KeyboardAvoidingView
style={{
display: "flex",
height: Dimensions.get("window").height,
width: Dimensions.get("window").width,
}}
behavior={Platform.OS === "ios" ? "padding" : "height"}
>
<SafeAreaView
style={{
backgroundColor: "transparent",
flex: 1,
}}
>
<View
style={{ flex: 0.4, backgroundColor: "#000", opacity: 0.2 }}
></View>
<View
style={{
flex: 0.6,
backgroundColor: Colors.dark.text,
borderRadius: 20,
}}
>
<View
style={{
flexDirection: "row",
marginTop: "3%",
paddingVertical: height * 0.005,
marginVertical: "4%",
borderTopRightRadius: 10,
borderTopLeftRadius: 10,
paddingHorizontal: "3%",
}}
>
<View style={{ flexDirection: "column", width: width * 0.8 }}>
<Text
style={{
fontFamily: "Roboto_700Bold",
fontSize: 10,
color: Colors.light.text,
opacity: 0.4,
}}
>
COMMENTS
</Text>
<Text
style={{
fontFamily: "Roboto_700Bold",
fontSize: 20,
marginTop: height * 0.01,
}}
>
{title}
</Text>
</View>
<TouchableOpacity
onPress={() => setCommentVisible(false)}
style={{
width: width * 0.15,
alignItems: "center",
justifyContent: "center",
}}
>
<SvgRedCross />
</TouchableOpacity>
</View>
<View
style={{
flex: 0.002,
backgroundColor: Colors.light.postText,
opacity: 0.2,
}}
>
<Text></Text>
</View>
<View style={{ flex: 0.87 }}>
<FlatList
data={allComment}
showsVerticalScrollIndicator={false}
keyExtractor={(item, index) => item.id}
key={(item, index) => item.qId}
renderItem={({ item, index }) => (
<View>
<View style={{ flexDirection: "column", padding: "3%" }}>
<Text
style={{
color: "#151617",
fontFamily: "Roboto_700Bold",
fontSize: 14,
}}
>
{item.name}{" "}
</Text>
<Text
style={{
color: "#151617",
fontFamily: "Roboto_400Regular",
fontSize: 13,
}}
>
{item.comment}{" "}
</Text>
</View>
<View
style={{
height: 0.5,
backgroundColor: Colors.light.postText,
opacity: 0.2,
marginTop: "3%",
}}
>
<Text></Text>
</View>
</View>
)}
style={{}}
pagingEnabled={false}
showsHorizontalScrollIndicator={false}
/>
</View>
<View
style={{
height: height * 0.08,
elevation: 2,
backgroundColor: "#fff",
flexDirection: "row",
alignItems: "center",
borderColor: Colors.light.tabSelection,
shadowColor: Colors.light.tabSelection,
shadowOffset: {
width: 0,
height: -3,
},
shadowRadius: 1,
shadowOpacity: 0.4,
position: "absolute",
bottom: 0,
flex: 0.2,
}}
>
<TextInput
style={{
fontWeight: "300",
fontStyle: "normal",
fontSize: 13,
fontFamily: "Roboto_400Regular",
paddingLeft: "5%",
paddingLeft: "5%",
color:
theme === true
? Colors.dark.postDateText
: Colors.light.postDateText,
width: "80%",
}}
value={comment}
onChangeText={(value) => {
setComment(value);
}}
maxLength={150}
clearButtonMode="always"
multiline={true}
placeholder="Write your comments here..."
placeholderTextColor={Colors.light.postDateText}
onSubmitEditing={() => Keyboard.dismiss()}
/>
//button code to submit comment
<TouchableOpacity
onPress={() => {
addComment(comment);
// Keyboard.dismiss();
}}
style={{ width: "20%", marginLeft: 10 }}
>
<SvgCommentArrow />
</TouchableOpacity>
</View>
</View>
</SafeAreaView>
</KeyboardAvoidingView>
It may happened due to not specifying the keyboard type in the textinput props https://reactnative.dev/docs/textinput#keyboardtype.
also refer this
https://reactnative.dev/docs/keyboard

Flat List renderItem width issue

I have some flat lists in my app with an item width of 160. For some reason when I reduce the width to 130 it will work as planned but with a width of 160px it starts to rerender again and again. What will be the possible reason for this and how to fix the issue.
My code
<FlatList
horizontal
inverted={getFlatListOrientation()}
data={data}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item, index }) => renderItem(item, index)}
contentContainerStyle={styles.listContainerStyle}
showsHorizontalScrollIndicator={false}
/>
this is my render item component
<TouchableWithoutFeedback
onPress={() => {
this.onSelect();
}}
>
<View style={{ height: 168,
width: 130,
marginRight: 10,
backgroundColor: kBackgroundWhiteColor,
shadowColor: kSeparatorTintColor,
shadowOffset: { width: 1, height: 1 },
shadowOpacity: 0.5,
shadowRadius: 5,
borderRadius: 5,
elevation: 10,}>
<FastImage
style={styles.imageStyle}
resizeMode={FastImage.resizeMode.cover}
source={
loadingError
? PLACE_HOLDER_IMAGE
: {
uri: photoUrl,
priority: FastImage.priority.normal,
}
}
onLoad={() => {
this.setState({ loadingImage: false });
}}
onError={() => {
this.setState({ loadingError: true });
}}
>
<View
style={{
flexDirection: "row",
flexGrow: 1,
justifyContent: "space-between",
alignItems: "center",
transform: [
{
rotateY: isKSA() ? "180deg" : "0deg",
},
],
}}
>
<TouchableOpacity
style={{
right: 0,
bottom: 0,
position: "absolute",
}}
onPress={() => this.onAddCarTofavorites()}
>
<View style={{ paddingLeft: 8, paddingTop: 8 }}>
<View
style={{
width: 26,
height: 26,
alignItems: "center",
justifyContent: "center",
borderRadius: 13,
backgroundColor: "#00000033",
marginRight: 5,
marginBottom: 5,
}}
>
<Image
source={
isFavorited
? IC_HEART_FILLED
: IC_HEART_OUTLINE
}
style={styles.favoriteImageStyle}
backgroundColor="clear"
/>
</View>
</View>
</TouchableOpacity>
{seenCarsIdlist &&
seenCarsIdlist.indexOf(id + "") != -1 && (
<Seen />
)}
{cappasity_link && <Tag3D />}
</View>
</FastImage>
{loadingImage && (
<FastImage
style={{
...styles.mainImageStyle,
position: "absolute",
}}
resizeMode={FastImage.resizeMode.cover}
source={PLACE_HOLDER_IMAGE}
/>
)}
<View style={styles.innerContainerStyle}>
<Text
style={styles.titleTextStyle}
ellipsizeMode={"tail"}
numberOfLines={1}
>
{makeName && modelName
? `${makeName} ${modelName} ${trim}`
: `${title} ${trim}`}
</Text>
<Text style={styles.priceTextStyle}>
{price + translate("filter_label_sar")}
</Text>
<View style={{ flexDirection: "row", paddingTop: 10 }}>
<Text style={styles.yearMileageTextStyle}>
{`${year} ยท ${mileage} ${
mileageUnitTemp
? mileageUnitTemp
: mileageUnit
}`}
</Text>
</View>
</View>
</View>
</TouchableWithoutFeedback>

KeyboardAvoidingView is not adjusting height

Im trying to get my text view and button to center when the Keyboard is summoned.
I tried wrapping my SafeArea with KeyboardAvoidingView but that did not seem to work.
I also tried setting the KeyBoardAvoidingView behavior to position which also did not work.
Any guidance would be appreciated.
KeyboardAvoidingView does not seem to work as expected.
**Whats happening : **
**Heres my code : **
<SafeAreaView style={{ flex: 1, backgroundColor: '#376772' }}>
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={Platform.Os == 'ios' ? 'padding' : null}
>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={{ flex: 1 }}>
<MapView
style={{ flex: 0.6 }}
showsMyLocationButton={true}
showsUserLocation={true}
followsUserLocation={lock}
onTouchStart={() => {
set(false)
}}
onPress={(loc) => {
setLocation(loc.nativeEvent.coordinate)
}}
>
<Marker coordinate={location} />
</MapView>
<Fragment>
<View
style={{
alignSelf: 'center',
alignContent: 'center',
backgroundColor: '#202B35',
padding: 10,
paddingHorizontal: 35,
margin: 5,
borderRadius: 5,
alignItems: 'center',
position: 'absolute',
}}
>
<View style={{ flexDirection: 'row' }}>
<Badge
status="error"
containerStyle={{ padding: 5 }}
/>
<Text
style={{
color: '#fff',
fontSize: 16,
marginBottom: 5,
}}
>
New Crossing
</Text>
<Text
style={{
color: '#fff',
fontSize: 10,
padding: 5,
}}
>
(Tap to add)
</Text>
</View>
<View style={{ flexDirection: 'row' }}>
<Badge
status="primary"
containerStyle={{ padding: 5 }}
/>
<Text
style={{
color: '#fff',
fontSize: 16,
}}
>
{'Existing Crossings'}
</Text>
</View>
</View>
</Fragment>
<View
style={{
flex: 0.4,
backgroundColor: '#376772',
margin: 5,
borderRadius: 5,
}}
>
<Input
placeholder="Enter Crossing name here"
inputStyle={{ color: 'orange' }}
rightIcon={
<Icon
name="edit"
size={25}
color="orange"
/>
}
placeholderTextColor={'orange'}
errorStyle={{ color: 'red' }}
/>
<Button
buttonStyle={{
margin: 10,
top: scale(10),
padding: 15,
backgroundColor: '#5cb85c',
borderRadius: 4,
}}
icon={
<Icon name="send" size={15} color="white" />
}
iconRight
titleStyle={{ fontWeight: 'bold' }}
title="Submit "
/>
</View>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</SafeAreaView>
Setting behavior to "position" worked for me by removing flex: 1 from styles, like
<KeyboardAvoidingView behavior="position">
{children}
</KeyboardAvoidingView>
Cheers!

Resources