FlatList does not scroll down to the end - react-native

I have a flatlist in my react native code. It does not scroll all the way down. I want to scroll it down till the end, but when I tried scrolling it down, it came back up again. Below is my entire code with style sheets:
FlatListItemSeparator = () => {
return (
<View
style={{
height: .9,
width: "100%",
backgroundColor: "#607D8B",
}}
/>
);
}
_renderItem = ({item, index}) => {
var destUrl = 'https://www.google.com/maps/dir/Current+Location/' + item.addr;
var geodist = require('geodist')
var dist = geodist({lat: item.cLat, lon:item.cLong}, {lat: item.LatL, lon: item.Long2}, 'mi')
var imagevar = item.image;
if (isNaN(dist)) {
dist = 0;
}
return(
<View style={{ backgroundColor: index %2 ===0? '#DDBC95':'#EBDCB2'}} >
<View style={{ flexDirection: 'row', alignItems:'center' }}>
<Image source={Icons[imagevar]} style = {styles.imageView}/>
<View style={{ flex: 1, alignItems: "center"}}>
<Text style={styles.Address1}>{item.addr} </Text>
<View style={styles.phoneImg}>
<TouchableOpacity
onPress={() => { this.handleClick(`tel:${item.phone}`)}}>
<Image source={require('../images/Phone.png')} style={styles.actionImage}/>
</TouchableOpacity>
<Text style={styles.Address1}>{item.phone}</Text>
</View>
<View style={styles.AddressRow}>
{
item.Online != ''? <TouchableOpacity onPress={() => Linking.openURL( item.Online )}>
<Image source={require('../images/www-icon.png')} style={styles.actionImage1}/>
</TouchableOpacity>: null
}
<TouchableOpacity onPress={() => Linking.openURL(item.Online)}>
<Text style={styles.underLineText}>Online</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => Linking.openURL(destUrl)}>
<Text style={styles.underLineText}>Directions</Text>
</TouchableOpacity>
<Text style={styles.AddressSpace} >Miles:{dist}</Text>
</View>
</View>
</View>
</View>
);
}
componentDidCatch
render()
{
var x = this.props.navigation.state.params.item.id ;
var newList = ServiceDetails.filter(obj => obj.fk === x)
return(
<View >
<View>
<Text style={styles.title}>{this.props.navigation.state.params.item.ser}</Text>
<Text style={styles.SerContent} >Services are available in the following locations:</Text>
</View>
<View>
<FlatList
data={newList.sort((a, b) => {
var geodist = require('geodist')
const aDist = geodist(
{ lat: a.cLat, lon: a.cLong },
{ lat: a.LatL, lon: a.Long2 },
"mi"
);
const bDist = geodist(
{ lat: b.cLat, lon: b.cLong },
{ lat: b.LatL, lon: b.Long2 },
"mi"
);
return aDist - bDist;
})}
ItemSeparatorComponent = {this.FlatListItemSeparator}
renderItem={this._renderItem}
keyExtractor={(item, index) => index}
/>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
MainContainer :{
// Setting up View inside content in Vertically center.
justifyContent: 'center',
flex:1,
margin: 10
},
item: {
padding: 10,
fontSize: 18,
height: 44,
},
container2:
{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 15
},
underLineText: {
fontSize: 17,
textDecorationLine: 'underline',
color: 'black',
alignSelf: 'center',
marginLeft: 20,
paddingTop:10
},
underLineTextOnline: {
fontSize: 17,
textDecorationLine: 'underline',
color: 'black',
alignSelf: 'center',
marginLeft: 20,
paddingTop:5
},
title:{
justifyContent: 'center',
paddingTop: 10,
alignItems: 'center',
alignSelf: 'center',
fontWeight: 'bold',
fontSize: 22,
color: 'black',
},
Address1:{
alignSelf: 'center',
marginRight: 20,
fontSize: 19,
fontWeight:'bold',
fontWeight: 'bold',
color: 'black'
},
SerContent:{
fontWeight: 'bold',
fontSize: 16,
paddingTop: 10,
alignSelf: 'center',
color: 'black',
paddingBottom: 10
},
Address1:{
alignSelf: 'center',
marginRight: 20,
fontSize: 15,
flexDirection:'column',
color: 'black',
marginLeft:10,
textAlignVertical:'center'
},
AddressRow:{
alignSelf: 'center',
marginRight: 20,
fontSize: 15,
flexDirection: 'row',
color: 'black'
},
phoneImg:{
flexDirection: 'row',
alignSelf: 'center',
textAlignVertical:'center'
},
AddressSpace:{
alignSelf: 'center',
marginLeft: 20,
fontSize: 15,
marginLeft: 20,
paddingTop:5,
color: 'black'
},
actionImage:{
flex:0,
height:30,
width:30,
backgroundColor:'transparent',
justifyContent:'center',
alignItems:'center',
marginTop:10,
alignSelf:'center',
flexDirection:'column',
textAlignVertical:'center'
},
sepBoxes:{
flex: 1,
flexDirection: 'column'
},
box: {
height: 55,
width:400,
},
box1: {
backgroundColor: 'white'
},
actionImage1:{
flex:0,
height:40,
width:40,
backgroundColor:'transparent',
justifyContent:'center',
alignItems:'center',
paddingLeft:5,
alignSelf:'center',
flexDirection:'column'
},
imageView:{
width:'30%',
height:100,
margin:7,
borderRadius: 7
},
textView: {
width:'50%',
textAlignVertical:'center',
padding:10,
color: '#000'
}
});
AppRegistry.registerComponent('ServiceListDetails', () => ServiceListDetails);
Above code has all the stylesheets and complete code.
Any help will be greatly appreciated.

Related

Touchable Opacity not working when nested inside View component but works if Touchable opacity is made the parent component to wrap other components

I have the following component created for showing an image card on screen. Inside this card there is an image that I am trying to make touchable, however, its does seem to work and when I try clicking on it, nothing happens.
But if I make the Touchable opacity as a parent component below, then the complete image card component becomes touchable and it works on screen. However, I do not want that and only want to target sub elements in this below card component. Not sure how to fix this!
import React, { useState } from "react";
import {
View,
Image,
Text,
StyleSheet,
TouchableOpacity,
} from "react-native";
const ImageCardView = ({
title,
category,
Price,
description,
imageUrl,
rating,
}) => {
return (
<View style={{ backgroundColor: "#d3c4de" }}>
<View style={styles.cardContainer}>
<RedCircle />
<TouchableOpacity onPress={() => navigation.navigate("showCase")}>
<Image
source={{
uri: imageUrl,
}}
style={styles.image}
/>
</TouchableOpacity>
<SeparatorVertical />
<View style={styles.textContainer}>
<Text style={styles.title}>{title}</Text>
<Text style={styles.category}>{category}</Text>
<Text style={styles.price}>${Price}</Text>
<SeparatorHorizontal />
<Text numberOfLines={2} style={styles.description}>
{description}
</Text>
<View style={styles.rightBottom}>
<TouchableOpacity
style={styles.button}
onPress={() => setIsPressed(!isPressed)}
>
<Text>Add To Cart</Text>
</TouchableOpacity>
{/* {isPressed && (
<View
style={{
backgroundColor: "white",
paddingLeft: 16,
paddingRight: 16,
}}
>
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingBottom: 12,
}}
>
<TouchableOpacity
disabled={!items.length}
onPress={removeItemFromBasket}
>
<Icon
name="minus-circle"
size={40}
color={items.length > 0 ? "#00CCBB" : "gray"}
/>
</TouchableOpacity>
<Text>{items.length}</Text>
<TouchableOpacity onPress={addItemToBasket}>
<Icon name="plus-circle" size={40} color="#00CCBB" />
</TouchableOpacity>
</View>
</View>
)} */}
<View style={styles.ratingContainer}>
{[...Array(5)].map((star, i) => {
const ratingValue = i + 1;
return (
<Text
key={i}
style={[
styles.star,
ratingValue <= rating && styles.filledStar,
]}
>
★
</Text>
);
})}
</View>
</View>
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
cardContainer: {
flexDirection: "row",
alignItems: "center",
backgroundColor: "white",
borderRadius: 5,
overflow: "hidden",
marginVertical: 10,
marginLeft: 3,
width: "98%",
height: 300,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
image: {
width: 150,
height: 228,
resizeMode: "cover",
},
textContainer: {
paddingLeft: 10,
},
title: {
fontWeight: "bold",
fontSize: 20,
marginBottom: 10,
},
category: {
color: "#d6c3b9",
},
price: {
fontSize: 20,
fontWeight: "bold",
color: "#05c3fa",
},
description: {
flexDirection: "row",
flexWrap: "wrap",
fontSize: 15,
color: "#666",
marginBottom: 20,
},
ratingContainer: {
flexDirection: "row",
alignItems: "center",
},
button: {
alignItems: "center",
backgroundColor: "#5cb85c",
borderRadius: 5,
padding: 10,
},
rightBottom: {
flexDirection: "row",
},
star: {
fontSize: 18,
color: "#888",
},
filledStar: {
color: "#ffd700",
},
});
export default ImageCardView;
Without seeing the all the code, my suggestion is to make sure your TouchableOpacity is being imported from "react-native" and not from "react-native-gesture-handler" or some other npm package like "react-native-web".
Check the below code and logs, it's working fine:
import React, { useState } from "react";
import {
View,
Image,
Text,
StyleSheet,
TouchableOpacity,
} from "react-native";
const App = ({
title,
category,
Price,
description,
imageUrl,
rating,
}) => {
const [isPressed, setIsPressed] = useState(false)
return (
<View style={{ backgroundColor: "#d3c4de" }}>
<View style={styles.cardContainer}>
<TouchableOpacity onPress={() => {
console.log("on pressed!!!!")
navigation.navigate("showCase")
}
}>
<Image
source={{
uri: imageUrl,
}}
style={styles.image}
/>
</TouchableOpacity>
<View style={styles.textContainer}>
<Text style={styles.title}>{title}</Text>
<Text style={styles.category}>{category}</Text>
<Text style={styles.price}>${Price}</Text>
<Text numberOfLines={2} style={styles.description}>
{description}
</Text>
<View style={styles.rightBottom}>
<TouchableOpacity
style={styles.button}
onPress={() => {
console.log("Add to card pressed!!!!")
setIsPressed(!isPressed)
}}>
<Text>Add To Cart</Text>
</TouchableOpacity>
{isPressed && (
<View
style={{
backgroundColor: "white",
paddingLeft: 16,
paddingRight: 16,
}}
>
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingBottom: 12,
}}
>
<TouchableOpacity
disabled={!items.length}
onPress={removeItemFromBasket}
>
<Icon
name="minus-circle"
size={40}
color={items.length > 0 ? "#00CCBB" : "gray"}
/>
</TouchableOpacity>
<Text>{items.length}</Text>
<TouchableOpacity onPress={addItemToBasket}>
<Icon name="plus-circle" size={40} color="#00CCBB" />
</TouchableOpacity>
</View>
</View>
)}
<View style={styles.ratingContainer}>
{[...Array(5)].map((star, i) => {
const ratingValue = i + 1;
return (
<Text
key={i}
style={[
styles.star,
ratingValue <= rating && styles.filledStar,
]}
>
★
</Text>
);
})}
</View>
</View>
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
cardContainer: {
flexDirection: "row",
alignItems: "center",
backgroundColor: "white",
borderRadius: 5,
overflow: "hidden",
marginVertical: 10,
marginLeft: 3,
width: "98%",
height: 300,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
image: {
width: 150,
height: 228,
resizeMode: "cover",
},
textContainer: {
paddingLeft: 10,
},
title: {
fontWeight: "bold",
fontSize: 20,
marginBottom: 10,
},
category: {
color: "#d6c3b9",
},
price: {
fontSize: 20,
fontWeight: "bold",
color: "#05c3fa",
},
description: {
flexDirection: "row",
flexWrap: "wrap",
fontSize: 15,
color: "#666",
marginBottom: 20,
},
ratingContainer: {
flexDirection: "row",
alignItems: "center",
},
button: {
alignItems: "center",
backgroundColor: "#5cb85c",
borderRadius: 5,
padding: 10,
},
rightBottom: {
flexDirection: "row",
},
star: {
fontSize: 18,
color: "#888",
},
filledStar: {
color: "#ffd700",
},
});
export default App;
For navigation, you need to get it referenced from parent props.
Thanks everyone. I got it fixed, in my case somehow the component was blocking the Touchable opacity, so included that inside my Touchable capacity to include the with the image and it started working

Why my I can not see my textinput when keyboard is open?

title says
const showFooter = () => {
return (
<View style={s.footerContainer}>
<Pressable style={s.btnInput}>
<FontAwesome name="photo" size={22} color="#eee" />
</Pressable>
<TextInput
onContentSizeChange={(e) => {
const { height } = e.nativeEvent.contentSize;
height > 45 && height < 100 && setHH(height);
height === 43 && setHH(45);
}}
value={input}
onChangeText={e => handleChangeInput(e)}
multiline
placeholder='Gebe eine Textnachricht ein...'
style={[s.footerInput, { height: hh }]}
/>
<Pressable style={s.btnInput}>
<AntDesign name="camerao" size={26} color="#eee" />
</Pressable>
<Pressable style={[s.btnInput, s.marginMinus]}>
<Fontisto name="paper-plane" size={22} style={s.paper} color="#eee" />
</Pressable>
</View>
)
};
return (
<KeyboardAvoidingView behavior='padding' style={{flex: 1}}>
<FlashList
data={message}
keyExtractor={i => i.id.toString()}
renderItem={rowRenderer}
extraData={message}
estimatedItemSize={200}
inverted
/>
{ /* INPUT */ }
<View style={[s.footer]}>
{ showFooter() }
</View>
</KeyboardAvoidingView>
)
};
container: {
flex: 1,
// backgroundColor: '#eee'
},
footer: {
paddingHorizontal: 4,
backgroundColor: '#fff',
width: '100%',
alignItems: 'center',
justifyContent: 'center'
},
footerContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 5,
width: widthScreen - 8,
borderWidth: 1,
borderRadius: 20,
maxHeight: 100,
borderColor: '#eee',
},
footerInput: {
width: widthScreen - 152,
padding: 12,
paddingLeft: 0,
textAlignVertical: 'top',
},
btnInput: {
height: 38,
width: 38,
backgroundColor: '#C71FF7',
borderRadius: 200,
alignItems: 'center',
justifyContent: 'center'
},
I am very thankful for your help!!
.......................................................................................................................................................................................................................................................................................
Use KeyboardAvoidingView to adjust the view when the keyboard is opening.
https://reactnative.dev/docs/keyboardavoidingview

Issues with Flexbox in React Native not displaying the Full Text

I'm having some troubles displaying information which I believe they have to do with the Flexbox Properties, but no matter how I play around with the Styles I don't get to fit everything in some components.
First I have this Component which is a Simple Card Component where I pass my data from API:
<PartidoItem
localImage={logoLocal}
marcadorLocal={marcadorLocal}
time={date}
partidoId={partidoId}
estatus={estatus}
minute={elapsed}
estadio={estadio}
marcadorVisita={marcadorVisita}
visitImage={logoVisita}
onSelect={estatus !== 'NS' && estatus !== 'TBD' ? () => {
selectPartidoHandler(partidoId, tituloPartido)
}
: () => { }
}
/>
This comes from this Component:
import React from 'react';
import { View, Text, Image, StyleSheet, TouchableNativeFeedback, TouchableOpacity, Platform } from 'react-native';
import Card from '../UI/Card';
import Colors from '../../constants/Colors';
const PartidoItem = props => {
let TouchableCmp = TouchableOpacity;
if (Platform.OS === 'android' && Platform.Version >= 21) {
TouchableCmp = TouchableNativeFeedback;
}
return (
<Card style={styles.product}>
<View style={styles.touchable}>
<TouchableCmp onPress={props.onSelect} useForeground>
<View style={styles.container}>
<View style={styles.column}>
<View style={styles.imageContainer}>
<Image
resizeMode="cover"
style={styles.image}
source={{ uri: props.localImage }}
/>
</View>
</View>
<View style={styles.column}>
<Text style={styles.number}>{props.marcadorLocal}</Text>
</View>
{props.estatus === 'NS' || props.estatus === 'TBD'
? <View style={styles.column}>
<Text style={styles.date}>{props.time}</Text>
<Text style={styles.title}>{props.estadio}</Text>
</View>
: props.estatus === 'FT' ?
<View style={styles.column}>
<Text style={styles.title2}>Final</Text>
<Text style={styles.title}>{props.estadio}</Text>
</View>
:
<View style={styles.column}>
<Text style={styles.title}>Tiempo:</Text>
<Text style={styles.title}>{props.minute} '</Text>
</View>
}
<View style={styles.column}>
<Text style={styles.number}>{props.marcadorVisita}</Text>
</View>
<View style={styles.column}>
<View style={styles.imageContainer}>
<Image
resizeMode="cover"
style={styles.image}
source={{ uri: props.visitImage }}
/>
</View>
</View>
</View>
</TouchableCmp>
</View>
</Card>
);
};
const styles = StyleSheet.create({
product: {
height: 100,
margin: 20,
justifyContent: 'center',
alignItems: 'center',
},
touchable: {
borderRadius: 10,
},
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
column: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
width: '20%',
},
space_between_columns: {
width: 100
},
box: {
height: 50,
width: 50
},
imageContainer: {
width: '100%',
height: '70%',
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
overflow: 'hidden',
marginHorizontal: 10,
overflow: 'hidden',
},
image: {
width: '100%',
height: '100%',
flex: 1,
},
hora: {
fontSize: 14,
color: '#888',
fontWeight: 'bold',
textAlign: 'center',
},
number: {
fontSize: 50,
marginVertical: 4,
fontWeight: 'bold',
justifyContent: 'center',
color: Colors.secondary,
},
title: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
//flexWrap: 'wrap',
flex: 2,
flexGrow: 1,
},
title2: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
color: 'red',
},
date: {
fontSize: 14,
marginVertical: 4,
textAlign: 'center',
flex: 1,
flexGrow: 1,
marginHorizontal: 2,
},
});
export default PartidoItem;
Which Holds this Component as well:
import React from 'react';
import { View, StyleSheet } from 'react-native';
//Importacion de los colores
import Colors from "../../constants/Colors";
const Card = props => {
return (
<View style={{...styles.card, ...props.style}}>
{props.children}
</View>
);
};
const styles = StyleSheet.create({
card: {
shadowColor: 'black',
shadowOpacity: 0.26,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 8,
elevation: 5,
borderRadius: 10,
backgroundColor: Colors.background,
}
});
export default Card;
Now the problem is that when I see it in the Android Emulator and it has large Strings I see this:
As you can see the Component is the one in the Primary Box and the Property "Estadio" is too big that doesn't show completely
The same happens when I check this on my iOS device (through Expo):
Is there a way to get this info to fit into that space so it shows the Full Name?
Kind Regards
PD: After Change Advise on first Answer this is the result with the Logos not showing correctly:
Try this for your styles :
const styles = StyleSheet.create({
product: {
height: 120,
margin: 20,
justifyContent: 'center',
alignItems: 'center',
},
touchable: {
borderRadius: 10,
},
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
column: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
},
space_between_columns: {
width: 100
},
box: {
height: 50,
width: 50
},
imageContainer: {
width: 100,
height: 100,
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
overflow: 'hidden',
marginHorizontal: 10,
overflow: 'hidden',
},
image: {
width: '100%',
height: '100%',
flex: 1,
},
hora: {
fontSize: 14,
color: '#888',
fontWeight: 'bold',
textAlign: 'center',
},
number: {
fontSize: 50,
marginVertical: 4,
fontWeight: 'bold',
justifyContent: 'center',
color: Colors.secondary,
},
title: {
fontSize: 14,
margin: 5,
fontWeight: 'bold',
textAlign: 'center',
//flexWrap: 'wrap',
flex: 2,
flexGrow: 1,
},
title2: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
color: 'red',
},
date: {
fontSize: 14,
marginVertical: 4,
textAlign: 'center',
flex: 1,
flexGrow: 1,
marginHorizontal: 2,
},
});

My React native button text is not appearing in iOS but in android it works fine

Problem:
In my react native application I have used tochableOpacity for my buttons. I have created a custom button component and Have reused it through out the Application. My Custom button component is look like this.
const SubmitButton = (props) => {
const { onpress, btext, loadding, disabled, scrollView } = props;
const isLargeScreen = useIsLargeDevice();
return (
<TouchableOpacity
style={scrollView ? styles.sendButtonScrollView : styles.sendButton}
onPress={onpress}
disabled={disabled}>
{loadding ? (
<Image
source={spinner}
style={scrollView ? styles.bimageScrollview : styles.bimage}
/>
) : (
<Text
style={[
styles.sendButtonText,
isLargeScreen ? styles.largeText : styles.text,
]}>
{btext}
</Text>
)}
</TouchableOpacity>
);
};
export default SubmitButton;
const styles = StyleSheet.create({
sendButton: {
flex: 1,
backgroundColor: '#3e92ff',
paddingTop: '6%',
paddingBottom: '6%',
alignItems: 'center',
borderRadius: 50,
marginTop: 25,
justifyContent: 'center',
// flexWrap: 'wrap'
},
sendButtonScrollView: {
flex: 1,
backgroundColor: '#3e92ff',
paddingTop: '3%',
paddingBottom: '3%',
alignItems: 'center',
borderRadius: 50,
marginTop: 25,
justifyContent: 'center',
},
sendButtonText: {
fontFamily: 'Montserrat-Medium',
color: '#ffffff',
fontWeight: '300',
textAlign: 'center',
letterSpacing: 2,
},
text: {
fontSize: normalize(14),
},
largeText: {
fontSize: normalize(13),
},
bimage: {
width: 48,
height: 48,
},
bimageScrollview: {
width: 25,
height: 25,
},
});
And I have used it in another component like this.
Platform.OS === 'ios' ? Icon.loadFont() : null;
const handleBackButton = () => {
return true;
};
const _navigateToLogin = (navigation) => {
navigation.navigate('Login');
};
const _onPress = (values, validateToken) => {
validateToken(values.token);
};
const Tocken = (props) => {
useEffect(() => {
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
}, [props.navigation]);
useEffect(() => {
if (props.validtoken === true) {
_navigateToLogin(props.navigation);
props.cleardata();
}
}, [props]);
return (
<KeyboardAvoidingView style={styles.container} enabled behavior={Platform.OS === 'ios' ? 'height' : null}>
<View style={styles.colmty} />
<View style={styles.formContainer}>
<AppText styles={styles.loginFormTitle}>
{strings('token.title')}
</AppText>
<Formik
initialValues={{
token: '',
}}
validationSchema={Yup.object({
token: Yup.string().required(strings('token.token-validation')),
})}
onSubmit={(values, formikActions) => {
_onPress(values, props.validatetoken);
setTimeout(() => {
formikActions.setSubmitting(false);
}, 500);
}}>
{(formprops) => (
<View>
<View
style={
!formprops.values.token &&
!formprops.errors.token &&
!props.hasError
? styles.inputView
: formprops.values.token &&
!formprops.errors.token &&
!props.hasError
? styles.validInputView
: styles.inputViewError
}>
<TextInput
style={styles.textField}
placeholder={strings('token.token_place_holder')}
placeholderTextColor="#bbbbbb"
value={formprops.values.token}
onChangeText={formprops.handleChange('token')}
onBlur={formprops.handleBlur('token')}
keyboardType="default"
/>
{formprops.errors.token || props.hasError ? (
<Icon
name="times"
size={normalize(15)}
style={styles.errorIcon}
/>
) : null}
{formprops.values.token &&
!formprops.errors.token &&
!props.hasError ? (
<Icon
name="check"
size={normalize(15)}
style={styles.validIcon}
/>
) : null}
</View>
{formprops.touched.token &&
formprops.errors.token &&
!props.hasError ? (
<View style={styles.errorMessage}>
<AppText styles={styles.errorMessageText}>
{formprops.errors.token}
</AppText>
</View>
) : null}
{props.hasError ? (
<View style={styles.errorMessage}>
<AppText styles={styles.errorMessageText}>
{props.error}
</AppText>
</View>
) : null}
<View style={styles.submitButtonView}>
<SubmitButton
btext={strings('token.submit')}
onpress={formprops.handleSubmit}
loadding={props.loadding}
disabled={props.loadding}
/>
</View>
</View>
)}
</Formik>
</View>
<View style={styles.colmty2} />
<View style={styles.hr} />
<View style={styles.versionContainer}>
<AppText styles={styles.version}>version: {version}</AppText>
</View>
</KeyboardAvoidingView>
);
};
const mapStateToProps = (state) => {
return {
loadding: state.signin.loadding,
validtoken: state.signin.validtoken,
hasError: state.signin.tokenEr,
error: state.signin.error,
};
};
const mapDispatchToProps = (dispatch) => {
return {
validatetoken: (value) => dispatch(signinActions.validatetoken(value)),
cleardata: () => dispatch(signinActions.cleardata()),
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Tocken);
styles that I have used in the Token component is looks like this.
import {StyleSheet} from 'react-native';
import normalize from '_utils/fontsize';
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#ffffff',
},
colmty: {
height: '20%',
},
formContainer: {
height: '55%',
// backgroundColor: '#f2f2f2',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
// elevation: 5,
padding: '10%',
justifyContent: 'center',
paddingBottom: '5%',
},
colmty2: {
height: '10%',
},
bottom: {
height: '15%',
justifyContent: 'center',
alignItems: 'center',
},
hr: {
borderBottomColor: '#c3c3c3',
borderBottomWidth: 2.0,
marginRight: '10%',
marginLeft: '10%',
},
validIcon: {
marginTop: 15,
color: '#3e92ff',
},
errorIcon: {
marginTop: 15,
color: '#ff3d3d',
},
textField: {
flex: 1,
fontFamily: 'Montserrat-Medium',
fontSize: normalize(15),
fontWeight: '500',
paddingLeft: 0,
},
inputView: {
marginTop: '5%',
flexDirection: 'row',
borderBottomColor: '#cccccc',
borderBottomWidth: 2,
},
validInputView: {
marginTop: '5%',
flexDirection: 'row',
borderBottomColor: '#3e92ff',
borderBottomWidth: 2,
},
inputViewError: {
marginTop: '5%',
flexDirection: 'row',
borderBottomColor: '#ff3d3d',
borderBottomWidth: 2,
},
patientFormTitle: {
fontSize: 30,
fontWeight: '200',
fontStyle: 'normal',
textAlign: 'center',
color: '#444444',
alignItems: 'center',
},
bottomLinkText: {
fontSize: 13,
color: '#484848',
borderBottomWidth: 2,
borderBottomColor: '#c3c3c3',
},
loginFormTitle: {
fontSize: normalize(16),
fontWeight: '200',
fontStyle: 'normal',
textAlign: 'center',
color: '#444444',
alignItems: 'center',
marginTop: '-10%',
},
errorMessageText: {
color: '#ff3d3d',
fontSize: normalize(13),
marginTop: 10,
},
spinnerContainer: {
marginTop: '50%',
alignItems: 'center',
},
versionContainer: {
marginRight: '10%',
marginLeft: '10%',
marginTop: '10%',
},
version: {
textAlign: 'center',
fontSize: normalize(12),
},
});
export default styles;
But button is not showing the text it looks like this.
I tried lot to find out where I have done wrong but I was unable to do so. Can someone help me to solve this issue.Thank you

Is there a way that I can hide multiple textinput components in react native

So I’m making an app and the first screen it asks for a number and when the number is given it shows textinput’s the amount of the number. So let’s say num==1 the textinput component will be one on the next screen. I found out how to hide and show up to 2 textinput’s but I’m stuck at three. Please help me.
Homescreen.js
render() {
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={styles.container}>
<Text style={styles.header}>GFM Calculator</Text>
<TextInput
style={styles.input}
keyboardType="number-pad"
placeholder="Enter the number of elements..."
placeholderTextColor="#A8A8A8"
onChangeText={(elements) => this.setState({ elements })}
value={this.state.elements}
/>
<View style={{ alignItems: "flex-end", marginTop: 64 }}>
<TouchableOpacity
style={styles.continue}
onPress={() => {
this.props.navigation.navigate('Calculate', {
data: this.state.elements,
});
}}
>
<Ionicons name="md-arrow-round-forward" size={24} color="#fff" />
</TouchableOpacity>
</View>
<Text style={styles.header2}>Made By Godson Umoren</Text>
</View>
</TouchableWithoutFeedback>
);
}
}
Calculatescreen.js
showtextinput = function (options) {
return {
color: "#fff",
fontWeight: "600",
justifyContent: "flex-end",
marginLeft: 40,
height: 50,
width: "40%",
borderWidth: StyleSheet.hairlineWidth,
borderColor: "#fff",
borderRadius: 30,
paddingHorizontal: 20,
alignItems: "center",
alignSelf: "center",
alignContent: "center",
//display: 'none',
}
}
showtextinput2 = function (options) {
if (this.state.data == "2") {
return {
color: "#fff",
fontWeight: "600",
justifyContent: "flex-end",
marginLeft: 40,
height: 50,
width: "40%",
borderWidth: StyleSheet.hairlineWidth,
borderColor: "#fff",
borderRadius: 30,
paddingHorizontal: 20,
alignItems: "center",
alignSelf: "center",
alignContent: "center",
//display: 'none',
};
} else {
return {
display: "none",
};
}
};
showtextinput3 = function (options) {
if (this.state.data == "3") {
return {
color: "#fff",
fontWeight: "600",
justifyContent: "flex-end",
marginLeft: 40,
height: 50,
width: "40%",
borderWidth: StyleSheet.hairlineWidth,
borderColor: "#fff",
borderRadius: 30,
paddingHorizontal: 20,
alignItems: "center",
alignSelf: "center",
alignContent: "center",
//display: 'none',
};
} else {
return {
display: "none",
};
}
};
showtextinput4 = function (options) {
if (this.state.data == "4") {
return {
color: "#fff",
fontWeight: "600",
justifyContent: "flex-end",
marginLeft: 40,
height: 50,
width: "40%",
borderWidth: StyleSheet.hairlineWidth,
borderColor: "#fff",
borderRadius: 30,
paddingHorizontal: 20,
alignItems: "center",
alignSelf: "center",
alignContent: "center",
//display: 'none',
};
} else {
return {
display: "none",
};
}
};
showtextinput5 = function (options) {
if (this.state.data == "5") {
return {
color: "#fff",
fontWeight: "600",
justifyContent: "flex-end",
marginLeft: 40,
height: 50,
width: "40%",
borderWidth: StyleSheet.hairlineWidth,
borderColor: "#fff",
borderRadius: 30,
paddingHorizontal: 20,
alignItems: "center",
alignSelf: "center",
alignContent: "center",
//display: 'none',
};
} else {
return {
display: "none",
};
}
};
//......
<TextInput
style={this.showtextinput()}
placeholder="Number of Moles"
placeholderTextColor="#fff"
onChangeText={(moles1) => this.setState({ moles1 })}
value={this.state.moles1}
/>
<TextInput
style={this.showtextinput2()}
placeholder="Number of Moles"
placeholderTextColor="#fff"
onChangeText={(moles2) => this.setState({ moles2 })}
value={this.state.moles2}
/>
<TextInput
style={this.showtextinput3()}
placeholder="Number of Moles"
placeholderTextColor="#fff"
onChangeText={(moles3) => this.setState({ moles3 })}
value={this.state.moles3}
/>
<TextInput
style={this.showtextinput4()}
placeholder="Number of Moles"
placeholderTextColor="#fff"
onChangeText={(moles4) => this.setState({ moles4 })}
value={this.state.moles4}
/>
<TextInput
style={this.showtextinput5()}
placeholder="Number of Moles"
placeholderTextColor="#fff"
onChangeText={(moles5) => this.setState({ moles5 })}
value={this.state.moles5}
/>
You can use map() function like this:
let elements = new Array(this.state.elements)
render(){
<View>
{
elements.map(e => <Text>'test'</Text>)
}
</View>
}