Fix ListViewMock unique key error (#14894)

Summary:
Add key prop to renderHeader and renderFooter in ListViewMock.
Fix unique key error when using jest snapshots.

It closes #12762
Pull Request resolved: https://github.com/facebook/react-native/pull/14894

Reviewed By: TheSavior

Differential Revision: D13396721

Pulled By: cpojer

fbshipit-source-id: 5bbcb8157e3cd98fe07f2a037e1dbc06ab599c87
This commit is contained in:
Luis Flores 2018-12-10 17:08:39 -08:00 коммит произвёл Facebook Github Bot
Родитель 6a483495c8
Коммит f14edd8a0c
1 изменённых файлов: 34 добавлений и 17 удалений

Просмотреть файл

@ -24,34 +24,51 @@ class ListViewMock extends React.Component<$FlowFixMeProps> {
* Flow. */
renderScrollComponent: props => <ScrollView {...props} />,
};
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];
// Row IDs are only unique in a section
rows.push(
let rows = [
renderHeader && (
<StaticRenderer
key={'section_' + sectionID + '_row_' + rowID}
key="renderHeader"
shouldUpdate={true}
render={renderHeader}
/>
),
];
const dataSourceRows = dataSource.rowIdentities.map(
(rowIdentity, rowIdentityIndex) => {
const sectionID = dataSource.sectionIdentities[rowIdentityIndex];
return rowIdentity.map((row, rowIndex) => (
<StaticRenderer
key={'section_' + sectionID + '_row_' + rowIndex}
shouldUpdate={true}
render={this.props.renderRow.bind(
null,
dataSource.getRowData(sectionIdx, rowIdx),
dataSource.getRowData(rowIdentityIndex, rowIndex),
sectionID,
rowID,
row,
)}
/>
));
},
);
rows = [...rows, ...dataSourceRows];
renderFooter &&
rows.push(
<StaticRenderer
key="renderFooter"
shouldUpdate={true}
render={renderFooter}
/>,
);
}
}
renderFooter && rows.push(renderFooter());
return this.props.renderScrollComponent({...this.props, children: rows});
}
static DataSource = ListViewDataSource;