Skip to content

Commit 711d16e

Browse files
author
Javier Morant
authored
Merge pull request #1 from fjmorant/0.0.1
0.0.1 release
2 parents 035fe53 + 85139cb commit 711d16e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+21412
-12
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react-native"]
3+
}

.eslintcache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"/Users/morant84/Work/react-native-nested-listview/example/index.android.js":{"size":178,"mtime":1506461733000,"hashOfConfig":"18q17kc","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/index.android.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/index.ios.js":{"size":178,"mtime":1506461736000,"hashOfConfig":"18q17kc","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/index.ios.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/ExampleApp.js":{"size":2151,"mtime":1507097693000,"hashOfConfig":"18q17kc","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/ExampleApp.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/index.js":{"size":1963,"mtime":1507071227000,"hashOfConfig":"18q17kc","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/index.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/index.test.js":{"size":3703,"mtime":1507012094000,"hashOfConfig":"18q17kc","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/index.test.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/NodeView.js":{"size":1790,"mtime":1507071227000,"hashOfConfig":"18q17kc","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/NodeView.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}}}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flow-typed

.eslintrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"parser": "babel-eslint",
3+
"parserOptions": {
4+
"sourceType": "module",
5+
"ecmaFeatures": {
6+
"jsx": true
7+
}
8+
},
9+
"plugins": ["react", "react-native", "flowtype"],
10+
"extends": [
11+
"plugin:react/recommended",
12+
"plugin:react-native/all",
13+
"plugin:flowtype/recommended"
14+
],
15+
"rules": {
16+
"react-native/no-color-literals": 0
17+
}
18+
}

.flowconfig

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore unexpected extra "@providesModule"
9+
.*/node_modules/.*/node_modules/fbjs/.*
10+
11+
.*/node_modules/*
12+
13+
; Ignore duplicate module providers
14+
; For RN Apps installed via npm, "Libraries" folder is inside
15+
; "node_modules/react-native" but in the source repo it is in the root
16+
.*/Libraries/react-native/React.js
17+
.*/Libraries/react-native/ReactNative.js
18+
19+
[include]
20+
21+
[libs]
22+
node_modules/react-native/Libraries/react-native/react-native-interface.js
23+
node_modules/react-native/flow
24+
flow/
25+
flow-typed
26+
27+
[options]
28+
emoji=true
29+
30+
module.system=haste
31+
32+
munge_underscores=true
33+
34+
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
35+
36+
suppress_type=$FlowIssue
37+
suppress_type=$FlowFixMe
38+
suppress_type=$FixMe
39+
40+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
41+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
42+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
43+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
44+
45+
unsafe.enable_getters_and_setters=true
46+
47+
[version]

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
example
2+
3+
node_modules

NodeView.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* @flow */
2+
3+
import React from 'react'
4+
import {
5+
TouchableWithoutFeedback,
6+
View,
7+
FlatList,
8+
type Props,
9+
type State,
10+
} from 'react-native'
11+
12+
export type Node = {
13+
id: string,
14+
hidden: boolean,
15+
opened: boolean,
16+
}
17+
18+
export default class NodeView extends React.PureComponent<Props, State> {
19+
props: {
20+
generateIds: Function,
21+
getChildren: Function,
22+
getChildrenName: Function,
23+
node: Node,
24+
level: number,
25+
onNodePressed: Function,
26+
renderNode: Function,
27+
renderChildrenNode: Function,
28+
}
29+
30+
componentWillMount = () => {
31+
this.setState({
32+
node: this.props.node,
33+
})
34+
}
35+
36+
onNodePressed = () => {
37+
this.setState({
38+
node: {
39+
...this.state.node,
40+
opened: !this.state.node.opened,
41+
},
42+
})
43+
44+
this.props.onNodePressed(this.state.node)
45+
}
46+
47+
renderChildren = (item: Node, level: number) => {
48+
return (
49+
<NodeView
50+
getChildrenName={this.props.getChildrenName}
51+
node={item}
52+
level={level + 1}
53+
onNodePressed={this.props.onNodePressed}
54+
renderNode={this.props.renderNode}
55+
/>
56+
)
57+
}
58+
59+
render() {
60+
const rootChildrenName = this.props.getChildrenName(this.state.node)
61+
const rootChildren = this.state.node[rootChildrenName]
62+
63+
return (
64+
<View>
65+
{!this.state.node.hidden ? (
66+
<TouchableWithoutFeedback onPress={this.onNodePressed}>
67+
{this.props.renderNode(this.state.node, this.props.level)}
68+
</TouchableWithoutFeedback>
69+
) : null}
70+
{this.state.node.opened && rootChildren ? (
71+
<FlatList
72+
data={rootChildren}
73+
renderItem={({item}) => this.renderChildren(item, this.props.level)}
74+
keyExtractor={item => item.id}
75+
/>
76+
) : null}
77+
</View>
78+
)
79+
}
80+
}

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,53 @@
11
# react-native-nested-listview
2-
Nested Listview for React native
2+
Nested listview component for React native that it allows to create a listview that has N levels of nesting
3+
4+
5+
## Table of contents
6+
7+
1. [Usage](#usage)
8+
1. [Props](#props)
9+
1. [Example](#example)
10+
1. [Roadmap](#roadmap)
11+
12+
13+
## Usage
14+
15+
```
16+
yarn add react-native-nested-listview
17+
```
18+
19+
```javascript
20+
import NestedListview from 'react-native-nested-listview'
21+
22+
const data = [{title: 'Node 1', items: [{title: 'Node 1.1'}, {title: 'Node 1.2'}]}]
23+
24+
<NestedListView
25+
data={data}
26+
getChildrenName={(node) => 'items'}
27+
onNodePressed={(node) => alert('Selected node')}
28+
renderNode={(node, level) => <Text>{node.name}</Text>}
29+
/>
30+
```
31+
32+
## Props
33+
34+
### Required
35+
36+
Prop | Description | Type | Default
37+
------ | ------ | ------ | ------
38+
**`data`** | Array of nested items | Array | **Required**
39+
**`renderNode`** | Takes a node from data and renders it into the NestedlistView. The function receives `{node, level}` (see [Usage](#usage)) and must return a React element. | Function | **Required**
40+
**`getChildrenName`** | Function to determine in a node where are the children, by default NestedListView will try to find them in **items** | Function | **items**
41+
**`onNodePressed`** | Function called when a node is pressed by a user | Function | Not required
42+
43+
## Example
44+
You can find the following example in the [`/example` folder](https://github.com/fjmorant/react-native-nested-listview/tree/master/example).
45+
46+
![react-native-nested-listview](https://imgur.com/OqvopyK.gif)
47+
48+
## Roadmap
49+
50+
- Autoscrolling optionally
51+
- Expand/contract nodes programatically
52+
- Support animations
53+
- Add more examples of usage

0 commit comments

Comments
 (0)