React Native - Horizontal scroll with columns
up vote
0
down vote
favorite
I'm trying to implement the following view where each column is limited to 4 rows of song details in a horizontal FlatList. I have managed to create each row with song details + purchase button in a single component.
However, I'm struggling to limit each column to just 4 row of results. I'm currently rendering each component with a map function:
renderBestOfTheWeek = (items) => {
return (
<View>
{items.map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
render() {
return (
<FlatList
data={this.state.bestOfTheWeek}
horizontal={true}
renderItem={this.renderBestOfTheWeek}
/>
)
}
SongItemHorizontalScroll component:
<View style={containerStyle}>
<Image
source={{ uri: thumbnail_image }}
style={albumImageStyle}
/>
<View style={songDetailButtonContainer}>
<View style={songInfoStyle}>
<Text
style={{ fontSize: 12, lineHeight: 14, width: 160 }}
numberOfLines={1}>
{title}
</Text>
<Text
style={{ color: '#666', fontSize: 12, lineHeight: 14, width: 160 }} numberOfLines={1}
>{artist} - {album}</Text>
</View>
<Button onPress={() => Linking.openURL(url)} price={price} />
</View>
</View>
My data have been structured as such and is currently stored in state.
0: (4) [{…}, {…}, {…}, {…}]
1: (4) [{…}, {…}, {…}, {…}]
2: (4) [{…}, {…}, {…}, {…}]
3: (4) [{…}, {…}, {…}, {…}]
However I'm receiving the following error message (TypeError: items.map is not a function).
Where did I go wrong and what would be the proper method of achieving this?
react-native react-native-ios react-native-flatlist
add a comment |
up vote
0
down vote
favorite
I'm trying to implement the following view where each column is limited to 4 rows of song details in a horizontal FlatList. I have managed to create each row with song details + purchase button in a single component.
However, I'm struggling to limit each column to just 4 row of results. I'm currently rendering each component with a map function:
renderBestOfTheWeek = (items) => {
return (
<View>
{items.map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
render() {
return (
<FlatList
data={this.state.bestOfTheWeek}
horizontal={true}
renderItem={this.renderBestOfTheWeek}
/>
)
}
SongItemHorizontalScroll component:
<View style={containerStyle}>
<Image
source={{ uri: thumbnail_image }}
style={albumImageStyle}
/>
<View style={songDetailButtonContainer}>
<View style={songInfoStyle}>
<Text
style={{ fontSize: 12, lineHeight: 14, width: 160 }}
numberOfLines={1}>
{title}
</Text>
<Text
style={{ color: '#666', fontSize: 12, lineHeight: 14, width: 160 }} numberOfLines={1}
>{artist} - {album}</Text>
</View>
<Button onPress={() => Linking.openURL(url)} price={price} />
</View>
</View>
My data have been structured as such and is currently stored in state.
0: (4) [{…}, {…}, {…}, {…}]
1: (4) [{…}, {…}, {…}, {…}]
2: (4) [{…}, {…}, {…}, {…}]
3: (4) [{…}, {…}, {…}, {…}]
However I'm receiving the following error message (TypeError: items.map is not a function).
Where did I go wrong and what would be the proper method of achieving this?
react-native react-native-ios react-native-flatlist
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to implement the following view where each column is limited to 4 rows of song details in a horizontal FlatList. I have managed to create each row with song details + purchase button in a single component.
However, I'm struggling to limit each column to just 4 row of results. I'm currently rendering each component with a map function:
renderBestOfTheWeek = (items) => {
return (
<View>
{items.map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
render() {
return (
<FlatList
data={this.state.bestOfTheWeek}
horizontal={true}
renderItem={this.renderBestOfTheWeek}
/>
)
}
SongItemHorizontalScroll component:
<View style={containerStyle}>
<Image
source={{ uri: thumbnail_image }}
style={albumImageStyle}
/>
<View style={songDetailButtonContainer}>
<View style={songInfoStyle}>
<Text
style={{ fontSize: 12, lineHeight: 14, width: 160 }}
numberOfLines={1}>
{title}
</Text>
<Text
style={{ color: '#666', fontSize: 12, lineHeight: 14, width: 160 }} numberOfLines={1}
>{artist} - {album}</Text>
</View>
<Button onPress={() => Linking.openURL(url)} price={price} />
</View>
</View>
My data have been structured as such and is currently stored in state.
0: (4) [{…}, {…}, {…}, {…}]
1: (4) [{…}, {…}, {…}, {…}]
2: (4) [{…}, {…}, {…}, {…}]
3: (4) [{…}, {…}, {…}, {…}]
However I'm receiving the following error message (TypeError: items.map is not a function).
Where did I go wrong and what would be the proper method of achieving this?
react-native react-native-ios react-native-flatlist
I'm trying to implement the following view where each column is limited to 4 rows of song details in a horizontal FlatList. I have managed to create each row with song details + purchase button in a single component.
However, I'm struggling to limit each column to just 4 row of results. I'm currently rendering each component with a map function:
renderBestOfTheWeek = (items) => {
return (
<View>
{items.map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
render() {
return (
<FlatList
data={this.state.bestOfTheWeek}
horizontal={true}
renderItem={this.renderBestOfTheWeek}
/>
)
}
SongItemHorizontalScroll component:
<View style={containerStyle}>
<Image
source={{ uri: thumbnail_image }}
style={albumImageStyle}
/>
<View style={songDetailButtonContainer}>
<View style={songInfoStyle}>
<Text
style={{ fontSize: 12, lineHeight: 14, width: 160 }}
numberOfLines={1}>
{title}
</Text>
<Text
style={{ color: '#666', fontSize: 12, lineHeight: 14, width: 160 }} numberOfLines={1}
>{artist} - {album}</Text>
</View>
<Button onPress={() => Linking.openURL(url)} price={price} />
</View>
</View>
My data have been structured as such and is currently stored in state.
0: (4) [{…}, {…}, {…}, {…}]
1: (4) [{…}, {…}, {…}, {…}]
2: (4) [{…}, {…}, {…}, {…}]
3: (4) [{…}, {…}, {…}, {…}]
However I'm receiving the following error message (TypeError: items.map is not a function).
Where did I go wrong and what would be the proper method of achieving this?
react-native react-native-ios react-native-flatlist
react-native react-native-ios react-native-flatlist
asked Nov 15 at 14:14
Oswald Alee
12
12
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
It looks like somewhere items became an Object instead of an Array like it was meant to be. Try making it an Array again.
renderBestOfTheWeek = (items) => {
return (
<View>
{Array.from(items).map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
That seems to do away with the error message. However, I'm now passing an array of 4 objects into each SongItemHorizontalScroll component rather than each object.
– Oswald Alee
Nov 15 at 23:03
add a comment |
up vote
0
down vote
The renderItem function receives an object containing the keys item and index.
Thus, you should have
renderBestOfTheWeek = ({ item }) => {
add a comment |
up vote
0
down vote
accepted
Based on @Foyarash suggestion and help, here's the solution:
renderBestOfTheWeek = ({ item }) => {
return (
<View>
{item.map((songs, index) => <SongItemHorizontalScroll item={songs} key={index} />)}
</View>
)
}
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It looks like somewhere items became an Object instead of an Array like it was meant to be. Try making it an Array again.
renderBestOfTheWeek = (items) => {
return (
<View>
{Array.from(items).map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
That seems to do away with the error message. However, I'm now passing an array of 4 objects into each SongItemHorizontalScroll component rather than each object.
– Oswald Alee
Nov 15 at 23:03
add a comment |
up vote
0
down vote
It looks like somewhere items became an Object instead of an Array like it was meant to be. Try making it an Array again.
renderBestOfTheWeek = (items) => {
return (
<View>
{Array.from(items).map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
That seems to do away with the error message. However, I'm now passing an array of 4 objects into each SongItemHorizontalScroll component rather than each object.
– Oswald Alee
Nov 15 at 23:03
add a comment |
up vote
0
down vote
up vote
0
down vote
It looks like somewhere items became an Object instead of an Array like it was meant to be. Try making it an Array again.
renderBestOfTheWeek = (items) => {
return (
<View>
{Array.from(items).map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
It looks like somewhere items became an Object instead of an Array like it was meant to be. Try making it an Array again.
renderBestOfTheWeek = (items) => {
return (
<View>
{Array.from(items).map((item, index) => <SongItemHorizontalScroll item={item} key={index} />)}
</View>
)
}
answered Nov 15 at 14:27
Smarticles101
465312
465312
That seems to do away with the error message. However, I'm now passing an array of 4 objects into each SongItemHorizontalScroll component rather than each object.
– Oswald Alee
Nov 15 at 23:03
add a comment |
That seems to do away with the error message. However, I'm now passing an array of 4 objects into each SongItemHorizontalScroll component rather than each object.
– Oswald Alee
Nov 15 at 23:03
That seems to do away with the error message. However, I'm now passing an array of 4 objects into each SongItemHorizontalScroll component rather than each object.
– Oswald Alee
Nov 15 at 23:03
That seems to do away with the error message. However, I'm now passing an array of 4 objects into each SongItemHorizontalScroll component rather than each object.
– Oswald Alee
Nov 15 at 23:03
add a comment |
up vote
0
down vote
The renderItem function receives an object containing the keys item and index.
Thus, you should have
renderBestOfTheWeek = ({ item }) => {
add a comment |
up vote
0
down vote
The renderItem function receives an object containing the keys item and index.
Thus, you should have
renderBestOfTheWeek = ({ item }) => {
add a comment |
up vote
0
down vote
up vote
0
down vote
The renderItem function receives an object containing the keys item and index.
Thus, you should have
renderBestOfTheWeek = ({ item }) => {
The renderItem function receives an object containing the keys item and index.
Thus, you should have
renderBestOfTheWeek = ({ item }) => {
edited Nov 19 at 22:41
answered Nov 19 at 22:22
Foyarash
1262
1262
add a comment |
add a comment |
up vote
0
down vote
accepted
Based on @Foyarash suggestion and help, here's the solution:
renderBestOfTheWeek = ({ item }) => {
return (
<View>
{item.map((songs, index) => <SongItemHorizontalScroll item={songs} key={index} />)}
</View>
)
}
add a comment |
up vote
0
down vote
accepted
Based on @Foyarash suggestion and help, here's the solution:
renderBestOfTheWeek = ({ item }) => {
return (
<View>
{item.map((songs, index) => <SongItemHorizontalScroll item={songs} key={index} />)}
</View>
)
}
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Based on @Foyarash suggestion and help, here's the solution:
renderBestOfTheWeek = ({ item }) => {
return (
<View>
{item.map((songs, index) => <SongItemHorizontalScroll item={songs} key={index} />)}
</View>
)
}
Based on @Foyarash suggestion and help, here's the solution:
renderBestOfTheWeek = ({ item }) => {
return (
<View>
{item.map((songs, index) => <SongItemHorizontalScroll item={songs} key={index} />)}
</View>
)
}
answered Nov 19 at 23:50
Oswald Alee
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321388%2freact-native-horizontal-scroll-with-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown