React Native -- TouchableOpacity takes time to navigate - reactjs

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

Related

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

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!

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.

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

Vertical scrolling where attribute name row is fixed and horizontal scrolling where left most column is fixed in React Native

So far I've achieved this:
//code on data listing screen with a vertical flatlist
const DataListing = props => {
const memoizedValue = useMemo(() => renderItem, [props.coinData]);
const renderItem = ({item}) => {
return (
<View
style={{
flexDirection: 'row',
backgroundColor: item?.id % 2 ? '#ffffff' : '#f9f9f9f9',
height: 40,
alignItems: 'center',
}}>
{/* coin */}
{item.coin ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.coin}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* open time */}
{item.openTime ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.openTime}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* open */}
{item.open ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.open}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* high */}
{item.high ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.high}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* low */}
{item.low ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.low}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* close */}
{item.close ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.close}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* quote asset volume */}
{item.quoteAssetVolume ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.quoteAssetVolume}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* trade number */}
{item.tradeNumber ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.tradeNumber}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* tracker buy base */}
{item.takerBuyBase ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.takerBuyBase}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* tracker buy quote */}
{item.takerBuyQuote ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.takerBuyQuote}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* price change */}
{item.priceChange ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.priceChange}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* price change % */}
{item.priceChangePercent ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.priceChangePercent}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* previos close price */}
{item.prevClosePrice ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.prevClosePrice}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* last price */}
{item.lastPrice ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.lastPrice}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* open price */}
{item.openPrice ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.openPrice}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* low price */}
{item.lowPrice ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.lowPrice}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* price volume */}
{item.pricevolume ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.pricevolume}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* quote volume */}
{item.quoteVolume ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.quoteVolume}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* price open time */}
{item.priceopenTime ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.priceopenTime}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* price close time */}
{item.pricecloseTime ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.pricecloseTime}
</Text>
) : (
<View style={{width: 150}} />
)}
{/* created at */}
{item.created_at ? (
<Text style={{width: 150, textAlign: 'center', color: '#000000'}}>
{item.created_at}
</Text>
) : (
<View style={{width: 150}} />
)}
</View>
);
};
return (
<FlatList
showsVerticalScrollIndicator={false}
data={props.coinData}
keyExtractor={(item, index) => index}
renderItem={renderItem}
/>
);
};
export default DataListing;
// code on data attributes page
const DataAttributes = props => {
return (
// container
<View style={{flexDirection: 'row'}}>
{/* coin name */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
COIN
</Text>
</TouchableOpacity>
{/* open time */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
OPEN TIME
</Text>
</TouchableOpacity>
{/* open */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
OPEN
</Text>
</TouchableOpacity>
{/* high */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
HIGH
</Text>
</TouchableOpacity>
{/* low */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
LOW
</Text>
</TouchableOpacity>
{/* close */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
CLOSE
</Text>
</TouchableOpacity>
{/* quote asset volume */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
VOLUME
</Text>
</TouchableOpacity>
{/* trade number */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
TRADE NUMBER
</Text>
</TouchableOpacity>
{/* taker buy base */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
TAKER BUY BASE
</Text>
</TouchableOpacity>
{/* taker buy quote */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
TAKER BUY QUOTE
</Text>
</TouchableOpacity>
{/* price change */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
PRICE CHANGE
</Text>
</TouchableOpacity>
{/* price change percent */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
PRICE CHANGE %
</Text>
</TouchableOpacity>
{/* previos close price */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
PREVIOUS CLOSE PRICE
</Text>
</TouchableOpacity>
{/* last price */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
LAST PRICE
</Text>
</TouchableOpacity>
{/* open price */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
OPEN PRICE
</Text>
</TouchableOpacity>
{/* low price */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
LOW PRICE
</Text>
</TouchableOpacity>
{/* price volume */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
PRICE VOLUME
</Text>
</TouchableOpacity>
{/* quote volume */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
QUOTE VOLUME
</Text>
</TouchableOpacity>
{/* price open time */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
PRICE OPEN TIME
</Text>
</TouchableOpacity>
{/* price close time */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderColor: '#31313199',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
PRICE CLOSE TIME
</Text>
</TouchableOpacity>
{/* created at */}
<TouchableOpacity
style={{
flexDirection: 'row',
backgroundColor: '#FDE047',
height: 40,
width: 150,
alignItems: 'center',
justifyContent: 'center',
}}
onPress={() => {}}>
<Text
style={{
fontSize: 10,
fontWeight: '400',
color: '#000000',
}}>
CREATED AT
</Text>
</TouchableOpacity>
</View>
);
};
export default DataAttributes;
// then they are imported to home and put inside a horizontal scrollview
import DataAttributes from '../Components/HomeScreen/DataAttributes';
import DataListing from '../Components/HomeScreen/DataListing';
const HomeScreen = ({navigation}) => {
const [coinData, setCoinData] = useState([]);
useEffect(() => {
coinStastics();
}, []);
// fetching coin statistics
const coinStastics = async () => {
const header = {
'Content-Type': 'application/json',
};
await axios
.post(baseUrl + coin_statistics, '', {headers: header})
.then(res => {
setCoinData(res.data.data);
})
.catch(function (error) {
// handle error
console.log(error);
});
};
return (
<SafeAreaView
style={{
flex: 1,
alignItems: 'center',
}}>
<Header/>
{/* DATA */}
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
<View>
{/* attributes for data */}
<DataAttributes coinData={coinData} setCoinData={setCoinData} />
{/* data section */}
<DataListing coinData={coinData} />
</View>
</ScrollView>
<Footer />
</>
)}
</SafeAreaView>
);
};
export default HomeScreen;
I am expecting something like this, where I can scroll the data portion vertically where the the column names / attribute names stay fixed but as soon I start scrolling horizontally all the columns should start to respond except the left most one, it should stay fixed along with it's COLUMN NAME on top

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