Skip to content

Commit 5f07d97

Browse files
committed
Fixed flow errors
1 parent 3aca30a commit 5f07d97

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

example/.eslintcache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/index.js":{"size":2551,"mtime":1506461476000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/index.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/NodeView.js":{"size":1522,"mtime":1506462022000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/NodeView.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.android.js":{"size":284,"mtime":1499290295000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.android.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.ios.js":{"size":280,"mtime":1499290295000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.ios.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/index.android.js":{"size":178,"mtime":1506461733000,"hashOfConfig":"2mvhf3","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":"2mvhf3","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":2055,"mtime":1506462030000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/ExampleApp.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}}}
1+
{"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/index.js":{"size":1635,"mtime":1506925357000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/index.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/NodeView.js":{"size":1790,"mtime":1506925316000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/NodeView.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.android.js":{"size":284,"mtime":1499290295000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.android.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.ios.js":{"size":280,"mtime":1499290295000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.ios.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/index.android.js":{"size":178,"mtime":1506461733000,"hashOfConfig":"2mvhf3","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":"2mvhf3","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":2139,"mtime":1506924997000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/ExampleApp.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}}}

example/.eslintignore

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

example/ExampleApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class ExampleApp extends React.Component<Props, State> {
8080
}
8181

8282
onNodePressed = (node: any) => {
83-
// alert(node)
83+
alert(node.name)
8484
}
8585

8686
getChildrenName = (node: Object) => {

example/nestedListView/NodeView.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ import {
99
type State,
1010
} from 'react-native'
1111

12+
export type Node = {
13+
id: string,
14+
hidden: boolean,
15+
opened: boolean,
16+
}
17+
1218
export default class NodeView extends React.PureComponent<Props, State> {
1319
props: {
1420
generateIds: Function,
1521
getChildren: Function,
16-
node: any,
22+
getChildrenName: Function,
23+
node: Node,
24+
level: number,
1725
onNodePressed: Function,
18-
onLayout: Function,
1926
renderNode: Function,
2027
renderChildrenNode: Function,
2128
}
@@ -33,15 +40,18 @@ export default class NodeView extends React.PureComponent<Props, State> {
3340
opened: !this.state.node.opened,
3441
},
3542
})
43+
44+
this.props.onNodePressed(this.state.node)
3645
}
3746

38-
renderChildren = (item: any, level: number) => {
47+
renderChildren = (item: Node, level: number) => {
3948
return (
4049
<NodeView
4150
getChildrenName={this.props.getChildrenName}
4251
node={item}
4352
level={level + 1}
44-
renderNode={(item, level) => this.props.renderNode(item, level)}
53+
onNodePressed={this.props.onNodePressed}
54+
renderNode={this.props.renderNode}
4555
/>
4656
)
4757
}

example/nestedListView/index.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React from 'react'
44
import {FlatList, type Props, type State, View} from 'react-native'
5-
import NodeView from './NodeView'
5+
import NodeView, {type Node} from './NodeView'
66
import shortid from 'shortid'
77

88
export default class NestedListView extends React.PureComponent<Props, State> {
@@ -15,9 +15,9 @@ export default class NestedListView extends React.PureComponent<Props, State> {
1515
}
1616

1717
componentWillMount = () => {
18-
const root = {
19-
id: 1,
20-
items: this.props.data.map((child, index) =>
18+
const root: Node = {
19+
id: shortid.generate(),
20+
items: this.props.data.map((child: Node, index: number) =>
2121
this.generateIds(this.props.data[index])
2222
),
2323
name: 'root',
@@ -28,29 +28,29 @@ export default class NestedListView extends React.PureComponent<Props, State> {
2828
this.setState({root})
2929
}
3030

31-
generateIds = (element: any) => {
32-
if (!element) {
31+
generateIds = (node: Node) => {
32+
if (!node) {
3333
return
3434
}
3535

36-
const childrenName = this.props.getChildrenName(element)
36+
const childrenName: string = this.props.getChildrenName(node)
3737

3838
if (childrenName) {
39-
const children = element[childrenName]
39+
const children = node[childrenName]
4040

4141
if (children) {
42-
element[childrenName] = children.map((child, index) =>
42+
node[childrenName] = children.map((child, index) =>
4343
this.generateIds(children[index])
4444
)
4545
}
4646
}
4747

48-
element.id = shortid.generate()
48+
node.id = shortid.generate()
4949

50-
return element
50+
return node
5151
}
5252

53-
getChildrenName = node => {
53+
getChildrenName = (node: Node) => {
5454
if (node.name === 'root') {
5555
return 'items'
5656
}
@@ -64,9 +64,10 @@ export default class NestedListView extends React.PureComponent<Props, State> {
6464
<NodeView
6565
getChildrenName={this.getChildrenName}
6666
node={this.state.root}
67+
onNodePressed={this.props.onNodePressed}
6768
generateIds={this.generateIds}
6869
level={0}
69-
renderNode={(item, level) => this.props.renderNode(item, level)}
70+
renderNode={this.props.renderNode}
7071
/>
7172
</View>
7273
)

0 commit comments

Comments
 (0)