All files / react-native-mock/src/mocks ListView.js

85.71% Statements 18/21
50% Branches 2/4
100% Functions 1/1
85.71% Lines 18/21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                          1x 1x 1x 1x             3x 1x 1x 1x 1x 1x 1x 1x                                 1x   1x               1x 1x     1x   1x  
/**
 * Copyright (c) 2013-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of react-native. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @flow
 */
 
/* eslint-disable react/prop-types */
 
const React = require('react');
const ScrollView = require('ScrollView');  // eslint-disable-line import/no-unresolved
const StaticRenderer = require('StaticRenderer'); // eslint-disable-line import/no-unresolved
const View = require('View'); // eslint-disable-line import/no-unresolved
 
class ListViewMock extends React.Component {
  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];
        rows.push(
          <StaticRenderer
            shouldUpdate
            key={rowID}
            render={this.props.renderRow.bind(
              null,
              dataSource.getRowData(sectionIdx, rowIdx),
              sectionID,
              rowID
            )}
          />
        );
      }
    }
 
    renderFooter && rows.push(renderFooter());
 
    return (
      <View>
        {this.props.renderScrollComponent({ children: rows })}
      </View>
    );
  }
}
 
ListViewMock.defaultProps = {
  renderScrollComponent: (props) => <ScrollView {...props} />
};
 
ListViewMock.DataSource = require('ListViewDataSource'); // eslint-disable-line import/no-unresolved
 
module.exports = ListViewMock;