mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
dbe555ba78
Summary: Hi, The (as of yet unreleased) commit https://github.com/facebook/react-native/commit/5537055bf87c8b19e9fa8413486eef6a7ac5017f added some ListView and ScrollView mocks, but they leave out the original properties passed into them, which broke some of my tests (e.g. by excluding some properties like `testID`, for example, from the render tree) and I assume might break others' as well. This PR makes it so the ListView mock directly returns the scroll component (instead of wrapping it in a View), and has ListViewMock and ScrollViewMock pass their given properties through. Closes https://github.com/facebook/react-native/pull/11847 Differential Revision: D4408497 Pulled By: sahrens fbshipit-source-id: 7ec01c35d6b8efeb97761cddffdb4075d09c7d70
56 lines
1.7 KiB
JavaScript
56 lines
1.7 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');
|
|
|
|
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 this.props.renderScrollComponent({...this.props, children: rows});
|
|
}
|
|
static DataSource = ListViewDataSource;
|
|
}
|
|
|
|
module.exports = ListViewMock;
|