I have to build 5 pages but as they have all the same layout I want to use a flatlist to populate the fields, my doubt us vary basic, I read the documentation and had problems to fully understand, here is my code
const DATA = [
{
picture: '../../Components/Images/wellbeing.png',
text1: 'Get weekly overviews and find',
text2: 'out whats impacting your health',
text3: 'and wellness',
percent: 20,
},
];
const Item = ({picture, text1, text2, text3, percent}) => (
<View style={styles.container}>
<View>
<Image source={require({picture})} style={styles.image} />
</View>
<View style={styles.text_field}>
<Text style={styles.textContent}> {text1} </Text>
<Text style={styles.textContent}> {text2} </Text>
<Text style={styles.textContent}> {text3} </Text>
</View>
<View style={styles.footer}>
<TouchableOpacity onPress={() => navigation.navigate('HabitTracking')}>
<ProgressCircle
percent={{percent}}
radius={30}
borderWidth={3}
color="#3399FF"
shadowColor="white"
bgColor="blue">
<Icon name="arrowright" size={25} color="white"></Icon>
</ProgressCircle>
</TouchableOpacity>
</View>
</View>
);
I'm having trouble on how to populate this in the class, here is what I have so far
const Wellcome = () => {
const renderItem = ({picture, text1, text2, text3, percent}) => (
<Item picture={Item.picture}
/>
);
return (
);
};
export default Wellcome;
am I doing everything wrong?
please let me know if you need any further information
const renderItem = (item) => (
<Item picture={item.picture} />
);
and call renderItem in your render method
...
{renderItem(item)}
...
where item looks something like...
{
picture: 'something',
text1: 'something',
text2: 'something',
text3: 'something',
percent: 'something'
}
Related
I'm trying to wrap my flat list and trying to show an Icon after last index of Flatlist. I had tried but it works fine on a single row. when we data goes to next row it would not work.
Here is my flat list code. Modal and Input both are my custom component.
const renderItem = ({item}) => {
return (
<TouchableOpacity style={[styles.tagPostContainer, styles.viewTagContainer]}>
<AppText
type={'input'}
label={`#${item}`}
color={colors.placeholder}
containerStyle={[styles.tagPostInactiveTxt, styles.BgAddedTag]}
/>
</TouchableOpacity>
);
};
return(
<>
<View style={{flexDirection:'row',justifyContent:'flex-start'}}>
<FlatList
data={tags}
renderItem={renderItem}
keyExtractor={keyExtractor}
contentContainerStyle={styles.TagFlatlist}
/>
<TouchableOpacity
style={styles.plusIconContainer}
onPress={() => setVisible(true)}>
<CreateBuildIconFocus height={13} width={13} />
</TouchableOpacity>
</View>
<Modal
visible={visible}
buttonLabel={'Done'}
containerWidth={width / 1.7}
onCancel={onCancel}
onSubmit={onClick}
containerHeight={Platform.OS === 'android' ? 200 : 200}>
<Input
placeholder={'Add Tags'}
autoFocus={true}
minWidth={120}
maxWidth={150}
value={tag}
onChangeText={text => setTag(text)}
/>
</Modal>
</>
)
FlatList styles:
TagFlatlist: {
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'center',
},
Here is my design screen.
I find a solution for this. You can implement ListFooterComponent that used for showing something on end of flatlist. Here you can see more details of ListFooterComponent.
Here are the code of Flatlist.
return(
<FlatList
data={tags}
renderItem={renderItem}
keyExtractor={keyExtractor}
ListFooterComponent={
<TouchableOpacity
style={styles.plusIconContainer}
onPress={() => setVisible(true)}>
<CreateBuildIconFocus height={13} width={13} />
</TouchableOpacity>
}
contentContainerStyle={styles.TagFlatlist}
/>
)
I am making an app where anyone can join a fantasy golf tournament. On my homepage there is a flatlist which is receiving data from api. There will be many tournaments but the user can only join the upcoming one. Now what i want to do is disable the functionality of every other tournament that means there is a join button through which user can join so i want to disable every other button and only enable the upcoming tournament button. What should i do?
here's my code
const Item = ({ title, location, date, Id }) => (
<View style={styles.renderItemView}>
<View style={styles.imageView}>
<Image style={styles.imageView2} source={require('../../assets/golf.png')} />
</View>
<View style={styles.TextView}>
<Text style={styles.Text}>Name: {title}</Text>
<Text style={styles.Text}>Location: {location}</Text>
<Text style={styles.Text}>StartDate: {moment(date).format('DD-MM-YYYY')}</Text>
<Text style={styles.Text}>Contest Fee: $49</Text>
</View>
<View style={styles.JoinView}>
<TouchableOpacity onPress={() =>{
navigation.navigate('Join', {key:Id, date});
}} style={styles.Touch1}>
<Text style={styles.JoinText}>Join</Text>
</TouchableOpacity>
</View>
</View>
);
const renderItem = ({ item }) => (
<View>
<Item title={item.name} location={item.location} date={item.startDate} Id={item.Id} />
</View>
);```
You could use row index and modulus operator to define the disabled prop like this:
const renderItem = ({ item, index }) => (
<View>
<Item title={item.name} disabled={index % 1 === 1} location={item.location} date={item.startDate} Id={item.Id} />
</View>
);`
And the use it in the Item component on the TouchableOpacity like this:
const Item = ({ disabled }) => (
<View>
...other stuff
<TouchableOpacity disabled={disabled} />
</View>
)
<TouchableOpacity disabled={props.disabled} />
Below in a code I have describe the question as comment
//This is MessagesScreen.js
<FlatList
data={messages}
keyExtractor={messages => messages.id.toString()}
renderItem={({ item }) =>
<ListItem style={styles.listItem}
title={item.title}
subTitle={item.description}
image={item.image}
DeleteIconView={ListItemDeleteAction} /*Here ListItemDeleteAction.js
is component want to pass it to
the ListItem.js. Note: I have
imported all the nessory
labries*/
onPress={() => handleDelete(item)}
//renderRightActions={ListItemDeleteAction}
/>
}
ItemSeparatorComponent={ListItemSeparator}
refreshing={refreshing}
onRefresh={() => {
setMessages([
{
id: 2,
title: 'Komail',
description: 'React-Native Developer',
image: require("../asserts/komail.jpg"),
}
])
}}
/>
This is ListItemDeleteAction.js, which I want to render in ItemList.js
//This is ListItemDeleteAction.js
function ListItemDeleteAction(props) {
return (
<View style={styles.container}>
<MaterialCommunityIcons name="trash-can" size={30} color={Colors.danger} />
</View>
);
}
Now, in ListItem.js I want to render the ListItemDeleteAction.js as I have passed as a argument. Below in code I have described as comment.
Note: I am strict to this method, render the ListItemDeleteAction as it passed as argument, which is "DeleteIconView" as parameter in ListItem.js
function ListItem({ image, title, subTitle, ImageComponent, style, onPress, DeleteIconView}) {
return (
<TouchableHighlight
//onPress={onPress}
underlayColor={Colors.light}
>
<View style={[styles.container, style]}>
{ImageComponent}
{image && <Image style={styles.image} source={image} />}
<View style={styles.parentDeatailContainer}>
<View style={styles.detailContainer}>
<Text style={{ fontWeight: "bold" }}>{title}</Text>
{subTitle && <Text>{subTitle}</Text>}
</View>
<TouchableOpacity style={styles.deleteIconContainer} onPress={onPress}>
{DeleteIconView} /* This is the place where I want to render the
ListItemDeleteAction components as I passed as argument but How? */
</TouchableOpacity>
</View>
</View>
</TouchableHighlight>
);
}
You are passing the prop wrong. When you write DeleteIconView={ListItemDeleteAction}, you aren't actually creating a JSX component. This can be solved by writing the following.
renderItem={({ item }) =>
<ListItem style={styles.listItem}
title={item.title}
subTitle={item.description}
image={item.image}
DeleteIconView={<ListItemDeleteAction />}
onPress={() => handleDelete(item)}
/>
}
Now, the prop DeleteIconView is an actual JSX component which can be rendered as usual.
Hi i am hitting to a problem. In the Homepage, I am creating a list of cards where show name, amount, and image, and those cards are created by another function from InfoCard.js.
Now I am not sure how to pass the data ( name, amount) and link to another page
Homepage:
import InfoCard from "../components/test";
const Home = ({ navigation }) => {
return (
{data.map((item, index) => (
<InfoCard {...item} key={index} />
))}
);
};
export default Home;
InfoCard js
export default InfoCard = ({ image, brand, amount }) => {
return (
<TouchableOpacity onPress={() => navigation.navigate("Detail")}>
<View style={externalStyle.home_company_list}>
<Image source={image} />
<View style={externalStyle.card}>
<Text style={externalStyle.home_company_text}>{brand}</Text>
<Text style={externalStyle.home_company_text}>{amount}</Text>
</View>
</View>
</TouchableOpacity>
);
};
Detail Page
Once the TouchableOpacity clicked from home page which created by InFoCard.js, will pass the data(brand,amount) to Detail page and display the data
You can pass it as params:
export default InfoCard = ({ image, brand, amount }) => {
return (
<TouchableOpacity onPress={() => navigation.navigate("Detail", {brand: brand,
amount: amount,})}>
<View style={externalStyle.home_company_list}>
<Image source={image} />
<View style={externalStyle.card}>
<Text style={externalStyle.home_company_text}>{brand}</Text>
<Text style={externalStyle.home_company_text}>{amount}</Text>
</View>
</View>
</TouchableOpacity>
);
};
And get it in details as:
this.props.navigation.state.params.brand,
this.props.navigation.state.params.amount
You can simply pass the parameter after the "Detail" Route name.
Take a look here: https://reactnavigation.org/docs/params/
Please I'm struggling to read this data of the json file on a simple flatlist, I tried to do item.content or item.description and item.medias but it doesnt work please could someone help me
[
{
"medias": [
"iVBORw0KGgoAAAANSUhEUgAAALYAAACvCAYAAABQKSRXAAAABGdBTUEAALGPC/x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P4dm60AAAAASUVORK5CYII="
],
"description": "ccc",
"id": 3,
"user": {
"id": 1,
"nom": "user",
"prenom": "user",
"tel": "2126548390",
"url": null,
"departement": "RH",
"username": "admin"
},
"content": "cccc"
}
]
and this is my code (I want to display the image too )
<FlatList
style={{ marginTop: 20 }}
data={this.state.data}
refreshing={this.state.isLoading}
onRefresh={this.makeRemoteRequest}
renderItem={({ item, index })=>
<View>
{item.published == true ? <Card>
<TouchableOpacity onPress={this.onRemove}>
<Animated.View style={rowStyles}>
<View>
<Text style={styles.email}>{item.data[0].content}</Text>
</View>
</Animated.View>
<Animated.View style={rowStyles}>
<Text style={styles.email}>{item.description}</Text>
</Animated.View>
</TouchableOpacity></Card> : <Text></Text> }
</View>
}
keyExtractor={(item) => item.id}
ItemSeparatorComponent={this.renderSeparator}
ListHeaderComponent={this.renderHeader}
ListFooterComponent={this.renderFooter}
/>
First of all, keyExtractor expects a return of string and you are supplying an int (id);
You could either change your id in the data store to a string if possible, or do a map to convert the id to a string or you could do this:
keyExtractor={(item) => item.id.toString()}
which I don't recommend because it will always be rerun on render.
Also if the data from json is not changing, you could put it on the class as shown below:
The choices are yours but I believe the keyExtractor is your major issue.
// read the json file on import
const jsonData = require('path/to/file.json');
// set the data on mount to convert id to string
this.dataWithStringId = jsonData.map((item) => ({
...item,
id: item.id.toString(),
}));
render() {
return (
<FlatList
keyExtractor={(item) => item.id}
data={this.dataWithStringId}
renderItem={({item}) => (
<Card>
<TouchableOpacity>
<View>
<View>
<Text>{item.content}</Text>
</View>
</View>
<Animated.View>
<Text>{item.description}</Text>
</Animated.View>
</TouchableOpacity>
</Card>
)}
/>
)
}
EDIT:
here is a link to keyExtrctor