|
1 | 1 | /* @flow */ |
2 | 2 |
|
3 | 3 | import React from 'react' |
4 | | -import {ScrollView} from 'react-native' |
| 4 | +import {ScrollView, FlatList} from 'react-native' |
5 | 5 | import NodeView from './NodeView' |
6 | 6 | import shortid from 'shortid' |
7 | 7 |
|
@@ -100,13 +100,13 @@ export default class NestedListView extends React.Component { |
100 | 100 | } |
101 | 101 |
|
102 | 102 | searchTree = (element: any, otherElement: any) => { |
103 | | - const childrenName = this.props.getChildrenName(element) |
104 | | - |
105 | | - if (element.id == otherElement.id) { |
| 103 | + if (element.id === otherElement.id) { |
106 | 104 | element.opened = !element.opened |
107 | 105 |
|
108 | 106 | return element |
109 | 107 | } |
| 108 | + |
| 109 | + const childrenName = this.props.getChildrenName(element) |
110 | 110 |
|
111 | 111 | if (childrenName) { |
112 | 112 | const children = element[childrenName] |
@@ -154,45 +154,28 @@ export default class NestedListView extends React.Component { |
154 | 154 | this.props.onNodePressed(node) |
155 | 155 | } |
156 | 156 |
|
157 | | - onLayoutSelectedNode = (event: any) => { |
158 | | - const {x, y} = event.nativeEvent.layout |
159 | | - |
160 | | - this.scrollview.scrollTo({x, y, animated: true}) |
161 | | - } |
162 | | - |
163 | 157 | onCreateChildren = (item: any, level: number) => { |
164 | | - const autoScrollToNodeId = this.props.autoScrollToNodeId |
165 | | - |
166 | 158 | return ( |
167 | 159 | <NodeView |
168 | 160 | getChildren={(node: Object) => node[this.props.getChildrenName(node)]} |
169 | 161 | key={item.id} |
170 | 162 | node={item} |
171 | | - onLayout={ |
172 | | - autoScrollToNodeId && item.id_video === autoScrollToNodeId |
173 | | - ? this.onLayoutSelectedNode |
174 | | - : null |
175 | | - } |
| 163 | + searchTree={this.searchTree} |
| 164 | + generateIds={this.generateIds} |
176 | 165 | onNodePressed={() => this.onNodePressed(item)} |
177 | | - renderChildrenNode={(childrenNode: Object) => |
178 | | - this.onCreateChildren(childrenNode, level + 1)} |
| 166 | + renderChildrenNode={(childrenNode: Object) => this.onCreateChildren(childrenNode, level + 1)} |
179 | 167 | renderNode={() => this.props.renderNode(item, level)} |
180 | 168 | /> |
181 | 169 | ) |
182 | 170 | } |
183 | 171 |
|
184 | 172 | render = () => { |
185 | | - |
186 | 173 | return ( |
187 | | - <ScrollView |
188 | | - ref={ref => { |
189 | | - this.scrollview = ref |
190 | | - }} |
191 | | - style={this.props.style}> |
192 | | - {this.state.data |
193 | | - ? this.state.data.map((item: Object) => this.onCreateChildren(item, 0)) |
194 | | - : null} |
195 | | - </ScrollView> |
| 174 | + <FlatList |
| 175 | + data={this.state.data} |
| 176 | + style={this.props.style} |
| 177 | + renderItem={({item}) => this.onCreateChildren(item, 0)} |
| 178 | + keyExtractor={(item) => item.id}/> |
196 | 179 | ) |
197 | 180 | } |
198 | 181 | } |
0 commit comments