I'm making a login form in React Native. I can login and register already but when I try to enter values in the TextInput fields in my register form, the keyboard disappears after I enter one value, so I have to re-click every time on the input field to re-open the keyboard. This does not happen on Android, just with iPhone.
The weird thing is that this behavior does not happen on the login screen even though it is built exactly the same. Does anyone have any idea why this is happening?
Register.js
return (
<View>
<TextInput
style={styles.input}
value={username}
onChangeText={(text) => setUsername(text)}
placeholder="username"
returnKeyType="next"
/>
<TextInput
style={styles.input}
value={fullname}
onChangeText={(text) => setFullname(text)}
placeholder="full name"
/>
<TextInput
style={styles.input}
value={password}
onChangeText={(text) => setPassword(text)}
placeholder="password"
/>
<PasswordStrengthMeterBar password={password} />
<Button title="Register" onPress={handleSubmit} />
</View>
);
Login.js
return (
<View style={styles.container}>
{this.state.showComponent ? (
<View>
<Text>
<Register setShowComponent={this.setShowComponent} />
</Text>
<Pressable onPress={this.handlePress}>
<Text>Login</Text>
</Pressable>
</View>
) : (
<View>
<TextInput
style={styles.input}
value={this.state.users_username}
onChangeText={this.handleusers_usernameChange}
placeholder="username"
/>
<TextInput
style={styles.input}
value={this.state.users_password}
onChangeText={this.handleusers_passwordChange}
placeholder="password"
secureTextEntry
/>
<Button title="Login" onPress={this.handleLoginPress} />
<Pressable onPress={this.handlePress}>
<Text>Register</Text>
</Pressable>
<Text>{this.state.response}</Text>
</View>
)}
</View>
);
I already updated my phone, but that has not solved anything.
Related
I'm creating an app with React Native & Expo.
One of the search inputs includes an icon, so I did it like so:
<View style={styles.inputContainer}>
<FontAwesome name="search" size={20} color="black" />
<TextInput
style={styles.input}
value={search}
placeholder="Pesquise"
placeholderTextColor={text_gray}
onChangeText={(text) => setSearch(text)}
/>
</View>
But the Keyboard shows only when I click the TextInput, and I need to open it wherever I click the View that wraps it and the icon.
How can I achieve that?
Create a ref to the TextInput and then call REF.current.focus() to focus on the textInput and REF.current.blur() to blur it. Use Pressable instead of View, its just like a View but with different onPress events.
const textInput = useRef(null);
return (
<Pressable style={styles.inputContainer} onPress={() => textInput?.current?.focus()}>
<FontAwesome name="search" size={20} color="black" />
<TextInput
ref={textInput}
style={styles.input}
value={search}
placeholder="Pesquise"
placeholderTextColor={text_gray}
onChangeText={(text) => setSearch(text)}
/>
</Pressable>
)
my container doesn't want to display full width.. even though I have written the code as below, is there something wrong?
all my style code was here, I gave the background color to show there is a space at the end, and how to remove this until the color become fullscreen
this the code from name.txs
render() {
return (
<Container style = {styles.container}>
<VStack alignItems="center" alignContent="center">
<View style = {styles.view}>
<Text style={{fontSize:12, textAlign:'center'}}>
Please Input your Name
</Text>
<TextInput
style={styles.input}
placeholder='Enter Your Name Here'
onChangeText={ (name) => this.props.authStore.setName(name)}
/>
</View>
<View style = {styles.view}>
<Text style={{fontSize:12, textAlign:'center'}}>
Month of Your Born
</Text>
<TextInput
style={styles.input}
placeholder='January, February, etc.'
onChangeText={ (month) => this.props.authStore.setMonth(month)}
/>
</View>
<View style = {styles.view}>
<Text style={{fontSize:12, textAlign:'center'}}>
Day of Your Born
</Text>
<TextInput
keyboardType="numeric"
placeholder='1-31'
onChangeText={ (day) => this.props.authStore.setDay(day)}
/>
</View>
<View style = {styles.view}>
<Button
title="Submit"
onPress={() => this.props.navigation.push('Zodiac')}/>
</View>
</VStack>
</Container>
);
}
Replace <Container> with <Center flex={1}> from NativeBase
I am using accordion-collapse-react-native to manage Sections. When i collapse that section and opens it again the redux form values disappear. How can i manage to maintain the state of the Redux Form Field Values. Thanks in advance.
Here is my code :
<Collapse style={styles.item} isCollapsed={this.state.isCollapsed_First}
onToggle={isCollapsed => this.setState({ isCollapsed_First: isCollapsed })}
>
<CollapseHeader style={styles.header}>
<View style={styles.headerContent}>
<Text style={styles.headerText} >Personal Information</Text>
<Icon name={this.state.isCollapsed_First ? "arrow-up" : "arrow-down"} size={18} color='#fff' />
</View>
</CollapseHeader>
<CollapseBody>
<View style={{flexDirection:'row',marginTop:7}}>
<View style={{width:'48%',marginRight:'4%'}}>
<Field name="first_name"
placeholder="First Name"
inputViewStyle={styles.inputView}
inputTextStyle={styles.inputText}
component={this.renderTextInput}
/>
</View>
<View style={{width:'48%'}}>
<Field name="last_name"
placeholder="Last Name"
inputViewStyle={styles.inputView}
inputTextStyle={styles.inputText}
component={this.renderTextInput}
/>
</View>
</View>
<View style={{flexDirection:'row',marginTop:-7}}>
<View style={{width:'100%'}}>
<Field name="dd_country"
placeholder="Country"
data = {this.state.countriesList}
onItemSelect={item => this.props.change('dd_country', item.id)}
textInputStyle={styles.inputView}
component={this.renderDropdownInput}
/>
</View>
</View>
<View style={{flexDirection:'row',marginTop:-7}}>
<View style={{width:'100%'}}>
<Field name="dd_ben_type"
placeholder="Beneficiary Type"
data = {this.state.custTypesList}
onItemSelect={item => this.props.change('dd_ben_type', item.id)}
textInputStyle={styles.inputView}
component={this.renderDropdownInput}
/>
</View>
</View>
</CollapseBody>
</Collapse>
You have to maintain it's state yourself.
Try maintaining the state in the component, something like this:
export function Form() {
const [name, setName] = useState('');
const [country, setCountry] = useState('');
return(
<View>
<Input
onChangeText={setName}
value={name}
placeholder='Name'
/>
<Input
onChangeText={setCountry}
value={country}
placeholder='Country'
/>
</View>
)
}
I am a beginner at React Native. When I try to type a text in a Text Input box, I'm not able to type, because the keyboard hides within 2 seconds. I don't know why this happens, here is my code, kindly solve this issue, this issue only occurs on Android devices.
Here is my code,
render() {
return (
<View style={styles.container1}>
<ScrollView>
<View style={styles.container}>
<View style={styles.SectionStyle}>
<Image source={require('../assets/padlock.png')} style={styles.ImageStyle} />
<TextInput
style={{flex:1}}
placeholder="Current Password"
underlineColorAndroid="transparent"
secureTextEntry
selectionColor={'#002B60'}
returnKeyType={'next'}
blurOnSubmit={false}
onSubmitEditing={() => this.passwordRef.focus()}
onChangeText={(oldpassword) => this.setState({oldpassword})}
/>
</View> </View>
</View>
</ScrollView>
</View>
);
}
}
How can i solve this issue .
keyboard overlapping like this below
Code Here
<View style={styles.container}>
<View style={styles.Subcontainer}>
<ScrollView contentContainerStyle={styles.scrolViewFlex} ref='scrollView' automaticallyAdjustContentInsets={true} showsHorizontalScrollIndicator={true} showsVerticalScrollIndicator={true}>
<View style={styles.logoView}>
<Image source={require('#images/Icon_K.png')} style={styles.imageStyles} />
</View>
<View style={styles.textInputView}>
<ActivityIndicator
animating = {this.state.animating}
color = '#494949'
size = "large"
style = {styles.activityIndicator}
/>
<View style={styles.namesContainer}>
{/*<View style={styles.exploreContainerDirection}> */}
<View style={styles.pincodeContainer}>
<TextInput
underlineColorAndroid="transparent"
autoCapitalize="words"
style={[styles.firstnameTextInput,{borderColor:this.state.backgroundColor,color: this.state.color}]}
placeholder=" First Name"
placeholderTextColor="#494949"
returnKeyType='next'
onChangeText={this.handleChange.bind(this,'FirstName')}
value={this.state.updateAccountValues.FirstName}
onFocus={this.inputFocused.bind(this,'FirstName')}
onSubmitEditing={(event)=>{
this.refs.SecondInput.focus();
}}/>
</View>
<View style={styles.spaceview}/>
<View style={styles.mobileNoContainer}>
<TextInput
underlineColorAndroid="transparent"
autoCapitalize="words"
ref="SecondInput"
style={[styles.lastnametextInput,{borderColor:this.state.backgroundColor,color: this.state.color}]}
placeholder=" Last Name"
placeholderTextColor="#494949"
returnKeyType='next'
onChangeText={this.handleChange.bind(this,'LastName')}
onFocus={this.inputFocused.bind(this,'LastName')}
value={this.state.updateAccountValues.LastName}
onSubmitEditing={(event)=>{
this.refs.ThirdInput.focus();
}}/>
</View>
{/* </View>*/}
</View>
</ScrollView>
</View>
</View>
So this is my Screen short when i enter in textinput keyboard appers some times like this below screen
So, Please check it once and find Our my Issue
I followed this: Set
android:windowSoftInputMode="adjustPan" in MainfestFile.xml file
React-native: How to control what keyboard pushes up