2016-12-20 23:44:54 +00:00
|
|
|
/**
|
2017-03-24 21:18:39 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-12-20 23:44:54 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @flow
|
2017-06-13 05:32:58 +00:00
|
|
|
* @format
|
2016-12-20 23:44:54 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const ListViewDataSource = require('ListViewDataSource');
|
|
|
|
const React = require('React');
|
|
|
|
const ScrollView = require('ScrollView');
|
|
|
|
const StaticRenderer = require('StaticRenderer');
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ListViewMock extends React.Component<$FlowFixMeProps> {
|
2016-12-20 23:44:54 +00:00
|
|
|
static latestRef: ?ListViewMock;
|
|
|
|
static defaultProps = {
|
2017-06-13 05:32:58 +00:00
|
|
|
renderScrollComponent: props => <ScrollView {...props} />,
|
|
|
|
};
|
2016-12-20 23:44:54 +00:00
|
|
|
componentDidMount() {
|
|
|
|
ListViewMock.latestRef = this;
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
const {dataSource, renderFooter, renderHeader} = this.props;
|
|
|
|
const rows = [renderHeader && renderHeader()];
|
|
|
|
const allRowIDs = dataSource.rowIdentities;
|
|
|
|
for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
|
|
|
const sectionID = dataSource.sectionIdentities[sectionIdx];
|
|
|
|
const rowIDs = allRowIDs[sectionIdx];
|
|
|
|
for (let rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) {
|
|
|
|
const rowID = rowIDs[rowIdx];
|
2017-06-06 05:26:20 +00:00
|
|
|
// Row IDs are only unique in a section
|
2016-12-20 23:44:54 +00:00
|
|
|
rows.push(
|
|
|
|
<StaticRenderer
|
2017-06-06 05:26:20 +00:00
|
|
|
key={'section_' + sectionID + '_row_' + rowID}
|
2016-12-20 23:44:54 +00:00
|
|
|
shouldUpdate={true}
|
|
|
|
render={this.props.renderRow.bind(
|
|
|
|
null,
|
|
|
|
dataSource.getRowData(sectionIdx, rowIdx),
|
|
|
|
sectionID,
|
2017-06-13 05:32:58 +00:00
|
|
|
rowID,
|
2016-12-20 23:44:54 +00:00
|
|
|
)}
|
2017-06-13 05:32:58 +00:00
|
|
|
/>,
|
2016-12-20 23:44:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
renderFooter && rows.push(renderFooter());
|
2017-01-12 18:44:00 +00:00
|
|
|
return this.props.renderScrollComponent({...this.props, children: rows});
|
2016-12-20 23:44:54 +00:00
|
|
|
}
|
|
|
|
static DataSource = ListViewDataSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ListViewMock;
|