项目作者: Cnilton

项目描述 :
A customizable react-native Expandable ListView (Accordion) component. Resembles the native Android ExpandableListView component, but for react-native (iOS and Android).
高级语言: TypeScript
项目地址: git://github.com/Cnilton/react-native-expandable-list-view.git
创建时间: 2020-02-03T00:49:09Z
项目社区:https://github.com/Cnilton/react-native-expandable-list-view

开源协议:MIT License

下载


npm
npm
npm

About

This is a React-Native ExpandableListView component that you can freely modify its styles.

Instalation

To install just input the following command:

  1. npm i react-native-expandable-listview

or

  1. yarn add react-native-expandable-listview

Data Structure

  1. const CONTENT = [
  2. {
  3. id: '1', // required, id of item
  4. categoryName: 'Item 1', // label of item expandable item
  5. subCategory: [
  6. // required, array containing inner objects
  7. {
  8. id: '3', // required, of inner object
  9. name: 'Sub Cat 1', // required, label of inner object
  10. },
  11. {
  12. id: '4',
  13. name: 'Sub Cat 3',
  14. },
  15. ],
  16. },
  17. {
  18. id: '2',
  19. categoryName: 'Item 8',
  20. subCategory: [{id: '22', name: 'Sub Cat 22'}],
  21. },
  22. ];

Basic Usage

  1. //...
  2. import React, {Component} from 'react';
  3. import {ExpandableListView} from 'react-native-expandable-listview';
  4. const CONTENT = [
  5. {
  6. id: '42',
  7. categoryName: 'Item 1',
  8. subCategory: [
  9. {
  10. id: '1',
  11. name:
  12. "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged",
  13. },
  14. {id: '2', name: 'Sub Item 2'},
  15. ],
  16. },
  17. {
  18. id: '95',
  19. categoryName: 'Item 2',
  20. subCategory: [{id: '1', name: 'Sub Item 1'}],
  21. },
  22. {
  23. id: '94',
  24. categoryName: 'Item 3',
  25. subCategory: [{id: '1', name: 'Sub Item 1'}],
  26. },
  27. {
  28. id: '93',
  29. categoryName: 'Item 4',
  30. subCategory: [{id: '1', name: 'Sub Item 1'}],
  31. },
  32. {
  33. id: '92',
  34. categoryName: 'Item 5',
  35. subCategory: [{id: '1', name: 'Sub Item 1'}],
  36. },
  37. {
  38. id: '96',
  39. categoryName: 'Item 6',
  40. subCategory: [{id: '1', name: 'Sub Item 1'}],
  41. },
  42. ];
  43. function YourComponent() {
  44. function handleItemClick({index}) {
  45. console.log(index);
  46. };
  47. function handleInnerItemClick({innerIndex, item, itemIndex}) {
  48. console.log(innerIndex);
  49. };
  50. render() {
  51. return (
  52. <ExpandableListView
  53. data={CONTENT} // required
  54. onInnerItemClick={handleInnerItemClick}
  55. onItemClick={handleItemClick}
  56. ></ExpandableListView>
  57. );
  58. }
  59. }

Advanced Usage

  1. //...
  2. import React, {Component} from 'react';
  3. import {Text, Image} from 'react-native';
  4. import {ExpandableListView} from 'react-native-expandable-listview';
  5. const CONTENT = [
  6. {
  7. id: '42',
  8. categoryName: 'Item 1',
  9. customItem: (
  10. <View style={{flexDirection: 'column'}}>
  11. <Text>Custom Item</Text>
  12. <Text>With</Text>
  13. <Text>what you</Text>
  14. <Text>want</Text>
  15. </View>
  16. ),
  17. subCategory: [
  18. {
  19. customInnerItem: (
  20. <View style={{flexDirection: 'column', marginLeft: 15}}>
  21. <Text>Inner Item</Text>
  22. <Text>With whatever you need</Text>
  23. </View>
  24. ),
  25. id: '1',
  26. name: '',
  27. },
  28. {id: '2', name: 'Sub Item 2'},
  29. ],
  30. },
  31. {
  32. id: '96',
  33. categoryName: 'Item 2',
  34. subCategory: [{id: '1', name: 'Sub Item 1'}],
  35. },
  36. {
  37. id: '12',
  38. categoryName: 'Item 3',
  39. subCategory: [
  40. {id: '1', name: 'Category 1'},
  41. {id: '2', name: 'Category 2'},
  42. {id: '3', name: 'Category 3'},
  43. ],
  44. },
  45. ];
  46. function YourComponent() {
  47. const [listDataSource, setListDataSource] = useState([])
  48. function handleItemClick({index}) {
  49. console.log(index);
  50. };
  51. function handleInnerItemClick({innerIndex, item, itemIndex}) {
  52. console.log(innerIndex);
  53. };
  54. render() {
  55. return (
  56. <ExpandableListView
  57. // ExpandableListViewStyles={{borderTopWidth:1}} // styles to expandable listview
  58. // renderInnerItemSeparator={false} // true or false, render separator between inner items
  59. // renderItemSeparator={false} // true or false, render separator between Items
  60. // itemContainerStyle={{}} // add your styles to all item container of your list
  61. // itemLabelStyle={{}} // add your styles to all item text of your list
  62. // customChevron={{}} // your custom image to the indicator
  63. // chevronColor="white" // color of the default indicator
  64. // innerItemContainerStyle={{}} // add your styles to all inner item containers of your list
  65. // itemLabelStyle={{}} // add your styles to all inner item text of your list
  66. // itemImageIndicatorStyle={{}} // add your styles to the image indicator of your list
  67. // animated={true} // sets all animations on/off, default on
  68. // defaultLoaderStyles?: ViewStyle; // Set your styles to default loader (only for animated={true})
  69. // customLoader?: JSX.Element; Pass your custom loader, while your content is measured and rendered (only for animated={true})
  70. data={listDataSource}
  71. onInnerItemClick={handleInnerItemClick}
  72. onItemClick={handleItemClick}
  73. ></ExpandableListView>
  74. );
  75. }
  76. }
  • All commented options above are optional.

  • If you want to use the “customLoader” prop, provide JSX.Element or a Component, for example:

  1. import {View, ActivityIndicator} from 'react-native';
  2. // ...
  3. const myLoader = (<View><ActivityIndicator ></ActivityIndicator></View>)
  • If you want to use the “customChevron” prop, provide a image path, for example:
  1. import chevron from '../assets/images/yourImage';
  2. // ...
  3. customChevron = {chevron};

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.