How to navigate to new page from TextInput field? - reactjs

In this form i want to navigate to the new page as i click on the Field of Primary Address and Primary Bank Address
[In this form i want to navigate to new page conatining another form as i click on the field of primary address or primary bank account.]
<Text style={styles.labels}>
Address:
</Text>
<TextInput
style={styles.textinput}
placeholder="Primary Address"
placeholderTextColor="#000000"
mode="outlined"
underlineColorAndroid={'transparent'} />
<Text style={styles.labels}>
Bank Account:
</Text>
<TextInput
style={styles.textinput}
placeholder="Primary Bank Account"
placeholderTextColor="#000000"
mode="outlined"
underlineColorAndroid={'transparent'} />

Use ONFOCUS like
`onFocus={ () => this.onFocus() }
onFocus() {
},`

Wrap it inside a TouchableOpacity and take the user to next page using onPress
Also set editable prop to false in TextInput.

Related

How to 'edit page' with react native?

I am trying to make an edit profile page with react native. For example, a user wants to change his/her username so should go to the profile edit page. But after fetch the data from the database, I can't update the data.
I tried to use TextInput value prop. But if don't click it, it just sends null value. You can see my codes below.
<View >
<TextInput
placeholder='Adres'
placeholderTextColor='#808e9b'
style={styles.biginput}
multiline={true}
numberOfLines={50}
value={this.state.address}
onChangeText={Address => this.setState({ Address })}
/>
</View>
And i tried to use like below. But it sends null again
<View >
<TextInput
placeholder='İl'
placeholderTextColor='#808e9b'
style={styles.input}
onChangeText={City => this.setState({ City })}
>
{this.state.city}
</TextInput>
</View>
What should i do update the data?
I think you did not set the initial values when fetching the data from the server. Because of this if the user does not touch textInput, values are not set so they are null. When fetching the data set your states first.

How to implement TextInput without state [React-native]

I'm working on an app which the users will enter large number of records continously. App functionalities are completed but the performance is bit slow in low end mobiles. As i'm new to react native i've not much idea on this. But when i googled reagrding this issue it has been noticed that when the state changes the whole app get rerenders. So for reducing the state changes i want to know how to use TextInput without using state . Because in my TextInput by using onChangeText the state is updating in every keypress.
This is a demo snack of the project Demo
<View style={styles.fixedform}>
<View style={styles.textinputViewleft}>
<TextInput
style={styles.textinput}
ref={firstref}
label="Digit"
returnKeyType="next"
value={digit.value}
onChangeText={(text) => { setDigit({ value: text, error: '' }); if (text.length === 3) { ref.current.focus(); } }}
error={!!digit.error}
errorText={digit.error}
keyboardType="numeric"
maxLength={3}
minLength={3}/>
</View>
<View style={styles.textinputView}>
<TextInput
style={styles.textinput}
ref={ref}
label="Count"
value={count.value}
onChangeText={(text) => setCount({ value: text, error: '' })}
error={!!count.error}
errorText={count.error}
keyboardType="numeric"
maxLength={3}/>
</View>
<View style={styles.textinputView}>
<Button loading={loading} disabled={disabled} style={styles.buttonView} mode="contained" onPress={onSubmitPress}>Submit</Button>
</View>
</View>
Try this way, It will not rerender on text change and hold the value on key press like
<TextInput
...
value={digit.value} // remove this
onChangeText={(text) => digit.value = text };
...
/>
To clear value, try one of this
1- firstref.current.clear();
2- firstref.current.setNativeProps({ text: '' });
3- firstref.current.value = '';

Placeholder text shouldn't be removed upon entering text in TextInput React Native

I need some help in using TextInput react native.
What I am trying to achieve is I need to append the "months" text inside TextInput upon the user starts typing in the form field. If you look at the below screen shot for Tenure and Paid EMI the values are 123 and 12. I need to get like this "123 months" and "12 months" dynamically months should be added upon user entering the values.
For example if user is typing 2 then it should be displayed as "2 months" and if the user deletes 2, then default placeholder text should be displayed "36 months".
More importantly "months" should be non-editable, user should be able to only enter or update the numerical values. For example: If the value is "12 months" in the TextInput and the user wants to update it "32 months". Then he/she clicks on the TextInput field and clicks backspace 2 times and then enters new value "32". In the ui it will be displayed as "32 months".
[Note:- Only I need numerical values to be captured, I don't want the month value to be captured. It need to be displayed only for end user in the TextInput. "32 months" will be shown in the form field, but the state value should be only "32".
[EDITED-1 Added Code]
Render Function:-
<View style={{marginTop:height(2),width:width(90)}}>
<View style={{height:height(3),marginLeft:width(1)}}>
<Text style={{fontSize:16,fontFamily:"Ubuntu-Bold"}}>Tenure</Text>
</View>
<View style={{marginTop: height(1),width:width(90),alignItems:"center"}}>
<TouchableOpacity style={{width:width(90),flexDirection:"row",backgroundColor:"#F6F6F6",alignItems:"center",justifyContent:"center",height:height(6),borderRadius:12}}>
<TextInput placeholder="36 months"
textAlign={"center"}
value={this.state.tenure}
maxLength={3}
onChangeText={this.onTenureChanged.bind(this)}
keyboardType="number-pad"/>
</TouchableOpacity>
</View>
</View>
<View style={{marginTop:height(4.5),width:width(90),bottom: height(3)}}>
<View style={{height:height(3),marginLeft:width(1)}}>
<Text style={{fontSize:16,fontFamily:"Ubuntu-Bold"}}>Paid EMI</Text>
</View>
<View style={{marginTop: height(1),width:width(90),alignItems:"center"}}>
<TouchableOpacity style={{width:width(90),flexDirection:"row",backgroundColor:"#F6F6F6",alignItems:"center",justifyContent:"center",height:height(6),borderRadius:12}}>
<TextInput placeholder="15 months"
textAlign={"center"}
maxLength={3}
value={this.state.paidemi}
onChangeText={this.onPaidEMIChanged.bind(this)}
keyboardType="number-pad"/>
</TouchableOpacity>
</View>
</View>
Javascript Functions:-
onTenureChanged(itemValue){
this.setState({tenure: itemValue})
}
onPaidEMIChanged(itemValue){
this.setState({paidemi: itemValue})
}

Problem Using KeyBoard avoiding view in Overlay

Can Any One Help Me with This Problem Actually I Am New To React Native I have tried a couple of ways to overcome this problem but nothing worked out please help me with this I don't want the keyboard to interfere with the overlay
<View style={{height:"9%"}}>
<Button title="Add A New ToDO" onPress={this.onPressOpenOverLay} buttonStyle={{height:"100%",borderBottomLeftRadius:30,borderBottomRightRadius:30}}/>
<Overlay isVisible={this.state.setVisible}
onBackdropPress={this.onPressCloseOverLay}
animationType="fade"
overlayStyle={{height:"70%",width:"90%",borderRadius:20,alignItems:"center",paddingTop:"15%"}}>
<Text style={{fontSize:19,color:"#0288D1",fontWeight:"bold"}}>Add A New ToDo</Text>
<TextInput style={styles.input}
placeholder="Email ID"
autoCapitalize="none"
underlineColorAndroid="transparent"
onChangeText={email => this.setState({ email })}
value={this.state.email}
>
</TextInput>
</Overlay>
</View>
<FlatList
style={{marginTop:"2%"}}
data={this.state.data}
renderItem={this._renderMyList}
keyExtractor={(item, index) => index.toString()}
bounces={true}
/>
</SafeAreaView>
)
}
}
If you set your width or height with percentage, then it is prone to change when some changes in UI layout like a keyboard appearing happens. so you need to give them pixel values.
Moreover, you could use the import {Dimension} from 'react-native' to give you the width and height of the device and then calculate the percentage of those values and give them to your view.

Changing Visibility of a button inside the component dynamically

I am using React-Navigation but I guess You don't really need to have a prior knowledge about it.
So I have a header Component which looks like this
const Header = (props) => {
return (
<View style={headerContainer}>
<View>
<Button onPress={() => props.navigation.navigate('Home')}
title="Go Back"/>
</View>
<Text style={header}> Knicx
<Text style={headerSecondary}> Crypto Ticker </Text>
</Text>
</View>
)
}
Now, In the above notice the button, Which I am currently showing on all the pages
<Button onPress={() => props.navigation.navigate('Home')}
title="Go Back"/>
But I don't want it to be there on some specific pages, like HomeScreen to say the least.
Now, One solution is to remove the <Header /> component in my homepage, Copy the above code snippet, past it in my HomeScreen and remove the Component ( sort of like hardcoding ) or two create two Header component, one with button and one without button
[Question:] But I was thinking if we could toggle the visibility of button dynamically or stack it on the top of <Header /> ? Can someone please tell me how can we do it? (No, We can set the opacity of the button to zero and change it whenever we need it)
[Update:] We can use redux to manage/pass the state but the problem is that in React-native we do not have display: none and I don't want to change use the opacity
Send showHomeButton: boolean as a prop to header
const Header = props => (
<View style={headerContainer}>
{this.props.showHomeButton && (
<View>
<Button onPress={() => props.navigation.navigate('Home')} title="Go Back" />
</View>
)}
<Text style={header}>
{' '}
Knicx
<Text style={headerSecondary}> Crypto Ticker </Text>
</Text>
</View>
);

Resources