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?










share|improve this question


























    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?










    share|improve this question
























      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 at 14:14









      Oswald Alee

      12




      12
























          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>
          )
          }





          share|improve this answer





















          • 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


















          up vote
          0
          down vote













          The renderItem function receives an object containing the keys item and index.



          Thus, you should have



          renderBestOfTheWeek = ({ item }) => {





          share|improve this answer






























            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>
            )
            }





            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              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

























              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>
              )
              }





              share|improve this answer





















              • 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















              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>
              )
              }





              share|improve this answer





















              • 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













              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>
              )
              }





              share|improve this answer












              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>
              )
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              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


















              • 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












              up vote
              0
              down vote













              The renderItem function receives an object containing the keys item and index.



              Thus, you should have



              renderBestOfTheWeek = ({ item }) => {





              share|improve this answer



























                up vote
                0
                down vote













                The renderItem function receives an object containing the keys item and index.



                Thus, you should have



                renderBestOfTheWeek = ({ item }) => {





                share|improve this answer

























                  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 }) => {





                  share|improve this answer














                  The renderItem function receives an object containing the keys item and index.



                  Thus, you should have



                  renderBestOfTheWeek = ({ item }) => {






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 19 at 22:41

























                  answered Nov 19 at 22:22









                  Foyarash

                  1262




                  1262






















                      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>
                      )
                      }





                      share|improve this answer

























                        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>
                        )
                        }





                        share|improve this answer























                          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>
                          )
                          }





                          share|improve this answer












                          Based on @Foyarash suggestion and help, here's the solution:



                          renderBestOfTheWeek = ({ item }) => {
                          return (
                          <View>
                          {item.map((songs, index) => <SongItemHorizontalScroll item={songs} key={index} />)}
                          </View>
                          )
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 19 at 23:50









                          Oswald Alee

                          12




                          12






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Tonle Sap (See)

                              I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                              Guatemaltekische Davis-Cup-Mannschaft