1.0.2 • Published 5 years ago

@captain-omega/react-native-tree-view v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

react-native-tree-view

React Native component for hierarchical data representation. Has expandable row, which useful for displaying large amounts of information in vertical space.

Show Cases

demo.gif

Getting Started

Installation

Install main package:

$ npm i --save @captain-omega/react-native-tree-view

Install related icons package react-native-vector-icons:

$ npm i --save react-native-vector-icons

Add settings for your platform, see more here

IOS

react-native link react-native-vector-icons

Android

Edit android/app/build.gradle ( NOT android/build.gradle ) and add the following:

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

Basic Usage

  • Install @captain-omega/react-native-tree-view package to project

  • Import module to file

import TreeView from '@captain-omega/react-native-tree-view';
  • Then, use component like this:
<TreeView  
  cells={level1}
  data={data}  
  renderExpand={(item) => (
    <TreeView
      hideHeaders
      cells={level2}
      data={item.children}
      hideArrow
    />
  )}
/>

You can watch more examples in example directory

Properties

Basic props of TreeView

PropDefaultTypeDescription
cells-arrayAn array of objects that each describe a cell. See the cells property definition here.
contentStyle{}styleSee default style in source.
data-arrayThe array of table rows.
headerStyle{}styleSee default style in source.
hideArrowfalseboolHide column with arrows if this parameter is true.
hideHeadersfalseboolHide component headers.
isExpandablenullfunctionFunction that return true if row is expandable and false if it doesn't.
openfalseboolOpen all expandable rows by default.
onPressnullfunctionHandle row press event.
renderExpandnullfunctionRender function for expandable content. If this parameter is null, then row not expandable.

Cells definition

PropDefaultTypeDescription
cellStyle{}styleSet row cell style.
headerCellStyle{}styleSet header cell style.
renderHeaderCell-functionRender header cell content.
renderRowCell-functionRender row cell content.
width30numberWidth of column.

Run example

To run example call this commands in terminal:

$ cd example
$ npm i
$ react-native run-android
$ react-native run-ios

Notice!

If your npm not support symlinks, then call this code from repository root directory:

$ mkdir example/node_modules/@captain-omega
$ cp -alf $PWD example/node_modules/@captain-omega
$ rm -R example/node_modules/@captain-omega/react-native-tree-view/example
$ cd example
$ react-native run-android
$ react-native run-ios