2016-12-20 23:44:54 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-12-20 23:44:54 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-12-20 23:44:54 +00:00
|
|
|
*
|
2018-08-09 15:32:04 +00:00
|
|
|
* @flow strict-local
|
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-11-11 05:03:52 +00:00
|
|
|
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an
|
|
|
|
* error caught by Flow 0.59 which was not caught before. Most likely, this
|
|
|
|
* error is because an exported function parameter is missing an
|
|
|
|
* annotation. Without an annotation, these parameters are uncovered by
|
|
|
|
* Flow. */
|
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;
|