mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-07 22:40:55 +08:00
Summary: `Fake` components are simplified so snapshots are stable and reliable, and references are exported so that interactions like `onRefresh` and `onScroll` can be called manually. Currently there is just one global export for each class, but we may change this in the future if we need to manage multiple `Fake`s of the same type in one render tree. Right now these must be installed explicitly, but I might move them into `__mocks__` folders if it seems reasonable to make them defaults. Reviewed By: cpojer Differential Revision: D4318207 fbshipit-source-id: 62802353a98b09ca1c80804ef7201ea63091f94a
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
/**
|
|
* 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 this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
const ListViewDataSource = require('ListViewDataSource');
|
|
const React = require('React');
|
|
const ScrollView = require('ScrollView');
|
|
const StaticRenderer = require('StaticRenderer');
|
|
const View = require('View');
|
|
|
|
class ListViewMock extends React.Component {
|
|
static latestRef: ?ListViewMock;
|
|
static defaultProps = {
|
|
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];
|
|
rows.push(
|
|
<StaticRenderer
|
|
key={rowID}
|
|
shouldUpdate={true}
|
|
render={this.props.renderRow.bind(
|
|
null,
|
|
dataSource.getRowData(sectionIdx, rowIdx),
|
|
sectionID,
|
|
rowID
|
|
)}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
renderFooter && rows.push(renderFooter());
|
|
return (
|
|
<View>
|
|
{this.props.renderScrollComponent({children: rows})}
|
|
</View>
|
|
);
|
|
}
|
|
static DataSource = ListViewDataSource;
|
|
}
|
|
|
|
module.exports = ListViewMock;
|