mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-05 03:09:23 +00:00
[fix] Prevent props warnings from ScrollView in ListView
This commit is contained in:
committed by
Nicolas Gallagher
parent
c2501f2bc2
commit
e06d7a9650
@@ -107,20 +107,42 @@ class ListView extends Component {
|
|||||||
render() {
|
render() {
|
||||||
const children = [];
|
const children = [];
|
||||||
|
|
||||||
const dataSource = this.props.dataSource;
|
const {
|
||||||
|
dataSource,
|
||||||
|
enableEmptySections,
|
||||||
|
renderFooter,
|
||||||
|
renderHeader,
|
||||||
|
renderScrollComponent,
|
||||||
|
renderSectionHeader,
|
||||||
|
renderSeparator,
|
||||||
|
/* eslint-disable */
|
||||||
|
initialListSize,
|
||||||
|
onEndReachedThreshold,
|
||||||
|
onKeyboardDidHide,
|
||||||
|
onKeyboardDidShow,
|
||||||
|
onKeyboardWillHide,
|
||||||
|
onKeyboardWillShow,
|
||||||
|
pageSize,
|
||||||
|
renderRow,
|
||||||
|
scrollRenderAheadDistance,
|
||||||
|
stickyHeaderIndices,
|
||||||
|
/* eslint-enable */
|
||||||
|
...scrollProps
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
const allRowIDs = dataSource.rowIdentities;
|
const allRowIDs = dataSource.rowIdentities;
|
||||||
let rowCount = 0;
|
let rowCount = 0;
|
||||||
const sectionHeaderIndices = [];
|
const sectionHeaderIndices = [];
|
||||||
|
|
||||||
const header = this.props.renderHeader && this.props.renderHeader();
|
const header = renderHeader && renderHeader();
|
||||||
const footer = this.props.renderFooter && this.props.renderFooter();
|
const footer = renderFooter && renderFooter();
|
||||||
let totalIndex = header ? 1 : 0;
|
let totalIndex = header ? 1 : 0;
|
||||||
|
|
||||||
for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
||||||
const sectionID = dataSource.sectionIdentities[sectionIdx];
|
const sectionID = dataSource.sectionIdentities[sectionIdx];
|
||||||
const rowIDs = allRowIDs[sectionIdx];
|
const rowIDs = allRowIDs[sectionIdx];
|
||||||
if (rowIDs.length === 0) {
|
if (rowIDs.length === 0) {
|
||||||
if (this.props.enableEmptySections === undefined) {
|
if (enableEmptySections === undefined) {
|
||||||
const warning = require('fbjs/lib/warning');
|
const warning = require('fbjs/lib/warning');
|
||||||
warning(false, 'In next release empty section headers will be rendered.' +
|
warning(false, 'In next release empty section headers will be rendered.' +
|
||||||
' In this release you can use \'enableEmptySections\' flag to render empty section headers.');
|
' In this release you can use \'enableEmptySections\' flag to render empty section headers.');
|
||||||
@@ -128,7 +150,7 @@ class ListView extends Component {
|
|||||||
} else {
|
} else {
|
||||||
const invariant = require('fbjs/lib/invariant');
|
const invariant = require('fbjs/lib/invariant');
|
||||||
invariant(
|
invariant(
|
||||||
this.props.enableEmptySections,
|
enableEmptySections,
|
||||||
'In next release \'enableEmptySections\' flag will be deprecated,' +
|
'In next release \'enableEmptySections\' flag will be deprecated,' +
|
||||||
' empty section headers will always be rendered. If empty section headers' +
|
' empty section headers will always be rendered. If empty section headers' +
|
||||||
' are not desirable their indices should be excluded from sectionIDs object.' +
|
' are not desirable their indices should be excluded from sectionIDs object.' +
|
||||||
@@ -137,7 +159,7 @@ class ListView extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.renderSectionHeader) {
|
if (renderSectionHeader) {
|
||||||
const shouldUpdateHeader = rowCount >= this._prevRenderedRowsCount &&
|
const shouldUpdateHeader = rowCount >= this._prevRenderedRowsCount &&
|
||||||
dataSource.sectionHeaderShouldUpdate(sectionIdx);
|
dataSource.sectionHeaderShouldUpdate(sectionIdx);
|
||||||
children.push(
|
children.push(
|
||||||
@@ -171,14 +193,14 @@ class ListView extends Component {
|
|||||||
children.push(row);
|
children.push(row);
|
||||||
totalIndex++;
|
totalIndex++;
|
||||||
|
|
||||||
if (this.props.renderSeparator &&
|
if (renderSeparator &&
|
||||||
(rowIdx !== rowIDs.length - 1 || sectionIdx === allRowIDs.length - 1)) {
|
(rowIdx !== rowIDs.length - 1 || sectionIdx === allRowIDs.length - 1)) {
|
||||||
const adjacentRowHighlighted =
|
const adjacentRowHighlighted =
|
||||||
this.state.highlightedRow.sectionID === sectionID && (
|
this.state.highlightedRow.sectionID === sectionID && (
|
||||||
this.state.highlightedRow.rowID === rowID ||
|
this.state.highlightedRow.rowID === rowID ||
|
||||||
this.state.highlightedRow.rowID === rowIDs[rowIdx + 1]
|
this.state.highlightedRow.rowID === rowIDs[rowIdx + 1]
|
||||||
);
|
);
|
||||||
const separator = this.props.renderSeparator(
|
const separator = renderSeparator(
|
||||||
sectionID,
|
sectionID,
|
||||||
rowID,
|
rowID,
|
||||||
adjacentRowHighlighted
|
adjacentRowHighlighted
|
||||||
@@ -196,24 +218,9 @@ class ListView extends Component {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scrollProps.onScroll = this._onScroll;
|
||||||
|
|
||||||
const {
|
return React.cloneElement(renderScrollComponent(scrollProps), {
|
||||||
renderScrollComponent,
|
|
||||||
...props
|
|
||||||
} = this.props;
|
|
||||||
Object.assign(props, {
|
|
||||||
onScroll: this._onScroll,
|
|
||||||
stickyHeaderIndices: this.props.stickyHeaderIndices.concat(sectionHeaderIndices),
|
|
||||||
|
|
||||||
// Do not pass these events downstream to ScrollView since they will be
|
|
||||||
// registered in ListView's own ScrollResponder.Mixin
|
|
||||||
onKeyboardWillShow: undefined,
|
|
||||||
onKeyboardWillHide: undefined,
|
|
||||||
onKeyboardDidShow: undefined,
|
|
||||||
onKeyboardDidHide: undefined
|
|
||||||
});
|
|
||||||
|
|
||||||
return React.cloneElement(renderScrollComponent(props), {
|
|
||||||
ref: this._setScrollViewRef,
|
ref: this._setScrollViewRef,
|
||||||
onContentSizeChange: this._onContentSizeChange,
|
onContentSizeChange: this._onContentSizeChange,
|
||||||
onLayout: this._onLayout
|
onLayout: this._onLayout
|
||||||
|
|||||||
Reference in New Issue
Block a user