1

I need a nested List View like Safari's adding bookmark list. React for of that: https://ej2.syncfusion.com/react/documentation/listview/nested-list/

My data is nested it is shown below (small part of that):

const data = [
  {
    title: 'Computer',
  },
  {
    title: 'Software',
    items: [
      {
        title: 'JS',
      },
      {
        title: 'React JS',
        items: [
          {
            title: 'Components',
          },
          {
            title: 'Hooks',
          },
        ],
      },
    ],
  },
];

Nested list view ex.

Which package do you suggest ?

5
  • Check section list reactnative.dev/docs/sectionlist Commented May 11, 2020 at 12:26
  • It is not enough deeper and not navigating to see sub folder. I added a photo to explain what I want. @GuruparanGiritharan Commented May 11, 2020 at 12:31
  • you dont need a package for this, you can simply have two views and navigate using your navigation library Commented May 11, 2020 at 12:35
  • I didnt want to write too long data for the explanation. My data's nested level would be 4,5,6.. it depends. Because of that I mentioned about the apple's safari bookmark folder structure. Your answer is for small data. @GuruparanGiritharan Commented May 11, 2020 at 12:42
  • I agree with @GuruparanGiritharan, using several views is simpler and would allow you to go as deep as you want. Commented May 11, 2020 at 14:41

1 Answer 1

3

You can use sectionList or map property for your array

using map:

<View style={{flex: 1}}>
    {data.map((item, index) => (
        <View key={index} style={{borderBottomColor: 'black', borderBottomWidth: 2}}>
            <Text style={{fontSize: 30, fontWeight: 'bold'}}>{item.title}</Text>
            {item.items && <>
            {item.items.map((item, index) => (
                <View key={index} style={{backgroundColor: '#7fc', borderBottomColor: 'blue', borderBottomWidth: 2}}>
                      <Text style={{fontSize: 20, marginLeft: 40, color: 'blue'}}>{item.title}</Text>
                     {item.items && <>
                     {item.items.map((item, index) => (
                       <View key={index}  style={{backgroundColor: 'yellow', borderBottomColor: 'red', borderBottomWidth: 2}}>
                           <Text style={{fontSize: 16, marginLeft: 80,}}>{item.title}</Text>
                       </View>
                    ))}
                   </>}
               </View>
            ))}
           </>}
        </View>
     ))}
</View>

this is how you can apply this code to your required view you can make your parent view to button and show or hide it with button press child component should be seperate component

I hope this will help you!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.