mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Convert react-native-github/Libraries to let/const
Reviewed By: sahrens Differential Revision: D7956042 fbshipit-source-id: 221851aa311f3cdd6326497352b366048db0a1bb
This commit is contained in:
committed by
Facebook Github Bot
parent
266016c521
commit
8f5ebe5952
@@ -9,34 +9,34 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var ListViewDataSource = require('ListViewDataSource');
|
||||
var Platform = require('Platform');
|
||||
var React = require('React');
|
||||
var PropTypes = require('prop-types');
|
||||
var ReactNative = require('ReactNative');
|
||||
var RCTScrollViewManager = require('NativeModules').ScrollViewManager;
|
||||
var ScrollView = require('ScrollView');
|
||||
var ScrollResponder = require('ScrollResponder');
|
||||
var StaticRenderer = require('StaticRenderer');
|
||||
const ListViewDataSource = require('ListViewDataSource');
|
||||
const Platform = require('Platform');
|
||||
const React = require('React');
|
||||
const PropTypes = require('prop-types');
|
||||
const ReactNative = require('ReactNative');
|
||||
const RCTScrollViewManager = require('NativeModules').ScrollViewManager;
|
||||
const ScrollView = require('ScrollView');
|
||||
const ScrollResponder = require('ScrollResponder');
|
||||
const StaticRenderer = require('StaticRenderer');
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
||||
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
||||
* run Flow. */
|
||||
var TimerMixin = require('react-timer-mixin');
|
||||
var View = require('View');
|
||||
const TimerMixin = require('react-timer-mixin');
|
||||
const View = require('View');
|
||||
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
||||
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
||||
* run Flow. */
|
||||
var cloneReferencedElement = require('react-clone-referenced-element');
|
||||
var createReactClass = require('create-react-class');
|
||||
var isEmpty = require('isEmpty');
|
||||
var merge = require('merge');
|
||||
const cloneReferencedElement = require('react-clone-referenced-element');
|
||||
const createReactClass = require('create-react-class');
|
||||
const isEmpty = require('isEmpty');
|
||||
const merge = require('merge');
|
||||
|
||||
var DEFAULT_PAGE_SIZE = 1;
|
||||
var DEFAULT_INITIAL_ROWS = 10;
|
||||
var DEFAULT_SCROLL_RENDER_AHEAD = 1000;
|
||||
var DEFAULT_END_REACHED_THRESHOLD = 1000;
|
||||
var DEFAULT_SCROLL_CALLBACK_THROTTLE = 50;
|
||||
const DEFAULT_PAGE_SIZE = 1;
|
||||
const DEFAULT_INITIAL_ROWS = 10;
|
||||
const DEFAULT_SCROLL_RENDER_AHEAD = 1000;
|
||||
const DEFAULT_END_REACHED_THRESHOLD = 1000;
|
||||
const DEFAULT_SCROLL_CALLBACK_THROTTLE = 50;
|
||||
|
||||
/**
|
||||
* DEPRECATED - use one of the new list components, such as [`FlatList`](docs/flatlist.html)
|
||||
@@ -95,7 +95,7 @@ var DEFAULT_SCROLL_CALLBACK_THROTTLE = 50;
|
||||
* rendering rows.
|
||||
*/
|
||||
|
||||
var ListView = createReactClass({
|
||||
const ListView = createReactClass({
|
||||
displayName: 'ListView',
|
||||
_childFrames: ([]: Array<Object>),
|
||||
_sentEndForContentLength: (null: ?number),
|
||||
@@ -405,28 +405,28 @@ var ListView = createReactClass({
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var bodyComponents = [];
|
||||
const bodyComponents = [];
|
||||
|
||||
var dataSource = this.props.dataSource;
|
||||
var allRowIDs = dataSource.rowIdentities;
|
||||
var rowCount = 0;
|
||||
var stickySectionHeaderIndices = [];
|
||||
const dataSource = this.props.dataSource;
|
||||
const allRowIDs = dataSource.rowIdentities;
|
||||
let rowCount = 0;
|
||||
const stickySectionHeaderIndices = [];
|
||||
|
||||
const {renderSectionHeader} = this.props;
|
||||
|
||||
var header = this.props.renderHeader && this.props.renderHeader();
|
||||
var footer = this.props.renderFooter && this.props.renderFooter();
|
||||
var totalIndex = header ? 1 : 0;
|
||||
const header = this.props.renderHeader && this.props.renderHeader();
|
||||
const footer = this.props.renderFooter && this.props.renderFooter();
|
||||
let totalIndex = header ? 1 : 0;
|
||||
|
||||
for (var sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
||||
var sectionID = dataSource.sectionIdentities[sectionIdx];
|
||||
var rowIDs = allRowIDs[sectionIdx];
|
||||
for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
||||
const sectionID = dataSource.sectionIdentities[sectionIdx];
|
||||
const rowIDs = allRowIDs[sectionIdx];
|
||||
if (rowIDs.length === 0) {
|
||||
if (this.props.enableEmptySections === undefined) {
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses
|
||||
* an error found when Flow v0.54 was deployed. To see the error
|
||||
* delete this comment and run Flow. */
|
||||
var warning = require('fbjs/lib/warning');
|
||||
const warning = require('fbjs/lib/warning');
|
||||
warning(
|
||||
false,
|
||||
'In next release empty section headers will be rendered.' +
|
||||
@@ -434,7 +434,7 @@ var ListView = createReactClass({
|
||||
);
|
||||
continue;
|
||||
} else {
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
invariant(
|
||||
this.props.enableEmptySections,
|
||||
"In next release 'enableEmptySections' flag will be deprecated, empty section headers will always be rendered." +
|
||||
@@ -460,13 +460,13 @@ var ListView = createReactClass({
|
||||
}
|
||||
}
|
||||
|
||||
for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) {
|
||||
var rowID = rowIDs[rowIdx];
|
||||
var comboID = sectionID + '_' + rowID;
|
||||
var shouldUpdateRow =
|
||||
for (let rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) {
|
||||
const rowID = rowIDs[rowIdx];
|
||||
const comboID = sectionID + '_' + rowID;
|
||||
const shouldUpdateRow =
|
||||
rowCount >= this._prevRenderedRowsCount &&
|
||||
dataSource.rowShouldUpdate(sectionIdx, rowIdx);
|
||||
var row = (
|
||||
const row = (
|
||||
<StaticRenderer
|
||||
key={'r_' + comboID}
|
||||
shouldUpdate={!!shouldUpdateRow}
|
||||
@@ -486,11 +486,11 @@ var ListView = createReactClass({
|
||||
this.props.renderSeparator &&
|
||||
(rowIdx !== rowIDs.length - 1 || sectionIdx === allRowIDs.length - 1)
|
||||
) {
|
||||
var adjacentRowHighlighted =
|
||||
const adjacentRowHighlighted =
|
||||
this.state.highlightedRow.sectionID === sectionID &&
|
||||
(this.state.highlightedRow.rowID === rowID ||
|
||||
this.state.highlightedRow.rowID === rowIDs[rowIdx + 1]);
|
||||
var separator = this.props.renderSeparator(
|
||||
const separator = this.props.renderSeparator(
|
||||
sectionID,
|
||||
rowID,
|
||||
adjacentRowHighlighted,
|
||||
@@ -509,7 +509,7 @@ var ListView = createReactClass({
|
||||
}
|
||||
}
|
||||
|
||||
var {renderScrollComponent, ...props} = this.props;
|
||||
const {renderScrollComponent, ...props} = this.props;
|
||||
if (!props.scrollEventThrottle) {
|
||||
props.scrollEventThrottle = DEFAULT_SCROLL_CALLBACK_THROTTLE;
|
||||
}
|
||||
@@ -550,7 +550,7 @@ var ListView = createReactClass({
|
||||
*/
|
||||
|
||||
_measureAndUpdateScrollProps: function() {
|
||||
var scrollComponent = this.getScrollResponder();
|
||||
const scrollComponent = this.getScrollResponder();
|
||||
if (!scrollComponent || !scrollComponent.getInnerViewNode) {
|
||||
return;
|
||||
}
|
||||
@@ -570,7 +570,7 @@ var ListView = createReactClass({
|
||||
},
|
||||
|
||||
_onContentSizeChange: function(width: number, height: number) {
|
||||
var contentLength = !this.props.horizontal ? height : width;
|
||||
const contentLength = !this.props.horizontal ? height : width;
|
||||
if (contentLength !== this.scrollProperties.contentLength) {
|
||||
this.scrollProperties.contentLength = contentLength;
|
||||
this._updateVisibleRows();
|
||||
@@ -581,8 +581,8 @@ var ListView = createReactClass({
|
||||
},
|
||||
|
||||
_onLayout: function(event: Object) {
|
||||
var {width, height} = event.nativeEvent.layout;
|
||||
var visibleLength = !this.props.horizontal ? height : width;
|
||||
const {width, height} = event.nativeEvent.layout;
|
||||
const visibleLength = !this.props.horizontal ? height : width;
|
||||
if (visibleLength !== this.scrollProperties.visibleLength) {
|
||||
this.scrollProperties.visibleLength = visibleLength;
|
||||
this._updateVisibleRows();
|
||||
@@ -622,7 +622,7 @@ var ListView = createReactClass({
|
||||
return;
|
||||
}
|
||||
|
||||
var distanceFromEnd = this._getDistanceFromEnd(this.scrollProperties);
|
||||
const distanceFromEnd = this._getDistanceFromEnd(this.scrollProperties);
|
||||
if (distanceFromEnd < this.props.scrollRenderAheadDistance) {
|
||||
this._pageInNewRows();
|
||||
}
|
||||
@@ -631,7 +631,7 @@ var ListView = createReactClass({
|
||||
_pageInNewRows: function() {
|
||||
this.setState(
|
||||
(state, props) => {
|
||||
var rowsToRender = Math.min(
|
||||
const rowsToRender = Math.min(
|
||||
state.curRenderedRowsCount + props.pageSize,
|
||||
props.enableEmptySections
|
||||
? props.dataSource.getRowAndSectionCount()
|
||||
@@ -666,32 +666,32 @@ var ListView = createReactClass({
|
||||
this._childFrames[newFrame.index] = merge(newFrame);
|
||||
});
|
||||
}
|
||||
var isVertical = !this.props.horizontal;
|
||||
var dataSource = this.props.dataSource;
|
||||
var visibleMin = this.scrollProperties.offset;
|
||||
var visibleMax = visibleMin + this.scrollProperties.visibleLength;
|
||||
var allRowIDs = dataSource.rowIdentities;
|
||||
const isVertical = !this.props.horizontal;
|
||||
const dataSource = this.props.dataSource;
|
||||
const visibleMin = this.scrollProperties.offset;
|
||||
const visibleMax = visibleMin + this.scrollProperties.visibleLength;
|
||||
const allRowIDs = dataSource.rowIdentities;
|
||||
|
||||
var header = this.props.renderHeader && this.props.renderHeader();
|
||||
var totalIndex = header ? 1 : 0;
|
||||
var visibilityChanged = false;
|
||||
var changedRows = {};
|
||||
for (var sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
||||
var rowIDs = allRowIDs[sectionIdx];
|
||||
const header = this.props.renderHeader && this.props.renderHeader();
|
||||
let totalIndex = header ? 1 : 0;
|
||||
let visibilityChanged = false;
|
||||
const changedRows = {};
|
||||
for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
||||
const rowIDs = allRowIDs[sectionIdx];
|
||||
if (rowIDs.length === 0) {
|
||||
continue;
|
||||
}
|
||||
var sectionID = dataSource.sectionIdentities[sectionIdx];
|
||||
const sectionID = dataSource.sectionIdentities[sectionIdx];
|
||||
if (this.props.renderSectionHeader) {
|
||||
totalIndex++;
|
||||
}
|
||||
var visibleSection = this._visibleRows[sectionID];
|
||||
let visibleSection = this._visibleRows[sectionID];
|
||||
if (!visibleSection) {
|
||||
visibleSection = {};
|
||||
}
|
||||
for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) {
|
||||
var rowID = rowIDs[rowIdx];
|
||||
var frame = this._childFrames[totalIndex];
|
||||
for (let rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) {
|
||||
const rowID = rowIDs[rowIdx];
|
||||
const frame = this._childFrames[totalIndex];
|
||||
totalIndex++;
|
||||
if (
|
||||
this.props.renderSeparator &&
|
||||
@@ -702,9 +702,9 @@ var ListView = createReactClass({
|
||||
if (!frame) {
|
||||
break;
|
||||
}
|
||||
var rowVisible = visibleSection[rowID];
|
||||
var min = isVertical ? frame.y : frame.x;
|
||||
var max = min + (isVertical ? frame.height : frame.width);
|
||||
const rowVisible = visibleSection[rowID];
|
||||
const min = isVertical ? frame.y : frame.x;
|
||||
const max = min + (isVertical ? frame.height : frame.width);
|
||||
if ((!min && !max) || min === max) {
|
||||
break;
|
||||
}
|
||||
@@ -737,7 +737,7 @@ var ListView = createReactClass({
|
||||
},
|
||||
|
||||
_onScroll: function(e: Object) {
|
||||
var isVertical = !this.props.horizontal;
|
||||
const isVertical = !this.props.horizontal;
|
||||
this.scrollProperties.visibleLength =
|
||||
e.nativeEvent.layoutMeasurement[isVertical ? 'height' : 'width'];
|
||||
this.scrollProperties.contentLength =
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
var isEmpty = require('isEmpty');
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
const isEmpty = require('isEmpty');
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
||||
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
||||
* run Flow. */
|
||||
var warning = require('fbjs/lib/warning');
|
||||
const warning = require('fbjs/lib/warning');
|
||||
|
||||
function defaultGetRowData(
|
||||
dataBlob: any,
|
||||
@@ -142,7 +142,7 @@ class ListViewDataSource {
|
||||
dataBlob: $ReadOnlyArray<any> | {+[key: string]: any},
|
||||
rowIdentities: ?$ReadOnlyArray<string>,
|
||||
): ListViewDataSource {
|
||||
var rowIds = rowIdentities ? [[...rowIdentities]] : null;
|
||||
const rowIds = rowIdentities ? [[...rowIdentities]] : null;
|
||||
if (!this._sectionHeaderHasChanged) {
|
||||
this._sectionHeaderHasChanged = () => false;
|
||||
}
|
||||
@@ -184,7 +184,7 @@ class ListViewDataSource {
|
||||
'row and section ids lengths must be the same',
|
||||
);
|
||||
|
||||
var newSource = new ListViewDataSource({
|
||||
const newSource = new ListViewDataSource({
|
||||
getRowData: this._getRowData,
|
||||
getSectionHeaderData: this._getSectionHeaderData,
|
||||
rowHasChanged: this._rowHasChanged,
|
||||
@@ -237,7 +237,7 @@ class ListViewDataSource {
|
||||
* Returns if the row is dirtied and needs to be rerendered
|
||||
*/
|
||||
rowShouldUpdate(sectionIndex: number, rowIndex: number): boolean {
|
||||
var needsUpdate = this._dirtyRows[sectionIndex][rowIndex];
|
||||
const needsUpdate = this._dirtyRows[sectionIndex][rowIndex];
|
||||
warning(
|
||||
needsUpdate !== undefined,
|
||||
'missing dirtyBit for section, row: ' + sectionIndex + ', ' + rowIndex,
|
||||
@@ -249,8 +249,8 @@ class ListViewDataSource {
|
||||
* Gets the data required to render the row.
|
||||
*/
|
||||
getRowData(sectionIndex: number, rowIndex: number): any {
|
||||
var sectionID = this.sectionIdentities[sectionIndex];
|
||||
var rowID = this.rowIdentities[sectionIndex][rowIndex];
|
||||
const sectionID = this.sectionIdentities[sectionIndex];
|
||||
const rowID = this.rowIdentities[sectionIndex][rowIndex];
|
||||
warning(
|
||||
sectionID !== undefined && rowID !== undefined,
|
||||
'rendering invalid section, row: ' + sectionIndex + ', ' + rowIndex,
|
||||
@@ -263,8 +263,8 @@ class ListViewDataSource {
|
||||
* or null of out of range indexes.
|
||||
*/
|
||||
getRowIDForFlatIndex(index: number): ?string {
|
||||
var accessIndex = index;
|
||||
for (var ii = 0; ii < this.sectionIdentities.length; ii++) {
|
||||
let accessIndex = index;
|
||||
for (let ii = 0; ii < this.sectionIdentities.length; ii++) {
|
||||
if (accessIndex >= this.rowIdentities[ii].length) {
|
||||
accessIndex -= this.rowIdentities[ii].length;
|
||||
} else {
|
||||
@@ -279,8 +279,8 @@ class ListViewDataSource {
|
||||
* or null for out of range indexes.
|
||||
*/
|
||||
getSectionIDForFlatIndex(index: number): ?string {
|
||||
var accessIndex = index;
|
||||
for (var ii = 0; ii < this.sectionIdentities.length; ii++) {
|
||||
let accessIndex = index;
|
||||
for (let ii = 0; ii < this.sectionIdentities.length; ii++) {
|
||||
if (accessIndex >= this.rowIdentities[ii].length) {
|
||||
accessIndex -= this.rowIdentities[ii].length;
|
||||
} else {
|
||||
@@ -294,8 +294,8 @@ class ListViewDataSource {
|
||||
* Returns an array containing the number of rows in each section
|
||||
*/
|
||||
getSectionLengths(): Array<number> {
|
||||
var results = [];
|
||||
for (var ii = 0; ii < this.sectionIdentities.length; ii++) {
|
||||
const results = [];
|
||||
for (let ii = 0; ii < this.sectionIdentities.length; ii++) {
|
||||
results.push(this.rowIdentities[ii].length);
|
||||
}
|
||||
return results;
|
||||
@@ -305,7 +305,7 @@ class ListViewDataSource {
|
||||
* Returns if the section header is dirtied and needs to be rerendered
|
||||
*/
|
||||
sectionHeaderShouldUpdate(sectionIndex: number): boolean {
|
||||
var needsUpdate = this._dirtySections[sectionIndex];
|
||||
const needsUpdate = this._dirtySections[sectionIndex];
|
||||
warning(
|
||||
needsUpdate !== undefined,
|
||||
'missing dirtyBit for section: ' + sectionIndex,
|
||||
@@ -320,7 +320,7 @@ class ListViewDataSource {
|
||||
if (!this._getSectionHeaderData) {
|
||||
return null;
|
||||
}
|
||||
var sectionID = this.sectionIdentities[sectionIndex];
|
||||
const sectionID = this.sectionIdentities[sectionIndex];
|
||||
warning(
|
||||
sectionID !== undefined,
|
||||
'renderSection called on invalid section: ' + sectionIndex,
|
||||
@@ -353,9 +353,9 @@ class ListViewDataSource {
|
||||
prevRowIDs: Array<Array<string>>,
|
||||
): void {
|
||||
// construct a hashmap of the existing (old) id arrays
|
||||
var prevSectionsHash = keyedDictionaryFromArray(prevSectionIDs);
|
||||
var prevRowsHash = {};
|
||||
for (var ii = 0; ii < prevRowIDs.length; ii++) {
|
||||
const prevSectionsHash = keyedDictionaryFromArray(prevSectionIDs);
|
||||
const prevRowsHash = {};
|
||||
for (let ii = 0; ii < prevRowIDs.length; ii++) {
|
||||
var sectionID = prevSectionIDs[ii];
|
||||
warning(
|
||||
!prevRowsHash[sectionID],
|
||||
@@ -368,12 +368,12 @@ class ListViewDataSource {
|
||||
this._dirtySections = [];
|
||||
this._dirtyRows = [];
|
||||
|
||||
var dirty;
|
||||
for (var sIndex = 0; sIndex < this.sectionIdentities.length; sIndex++) {
|
||||
let dirty;
|
||||
for (let sIndex = 0; sIndex < this.sectionIdentities.length; sIndex++) {
|
||||
var sectionID = this.sectionIdentities[sIndex];
|
||||
// dirty if the sectionHeader is new or _sectionHasChanged is true
|
||||
dirty = !prevSectionsHash[sectionID];
|
||||
var sectionHeaderHasChanged = this._sectionHeaderHasChanged;
|
||||
const sectionHeaderHasChanged = this._sectionHeaderHasChanged;
|
||||
if (!dirty && sectionHeaderHasChanged) {
|
||||
dirty = sectionHeaderHasChanged(
|
||||
this._getSectionHeaderData(prevDataBlob, sectionID),
|
||||
@@ -384,11 +384,11 @@ class ListViewDataSource {
|
||||
|
||||
this._dirtyRows[sIndex] = [];
|
||||
for (
|
||||
var rIndex = 0;
|
||||
let rIndex = 0;
|
||||
rIndex < this.rowIdentities[sIndex].length;
|
||||
rIndex++
|
||||
) {
|
||||
var rowID = this.rowIdentities[sIndex][rIndex];
|
||||
const rowID = this.rowIdentities[sIndex][rIndex];
|
||||
// dirty if the section is new, row is new or _rowHasChanged is true
|
||||
dirty =
|
||||
!prevSectionsHash[sectionID] ||
|
||||
@@ -404,9 +404,9 @@ class ListViewDataSource {
|
||||
}
|
||||
|
||||
function countRows(allRowIDs) {
|
||||
var totalRows = 0;
|
||||
for (var sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
||||
var rowIDs = allRowIDs[sectionIdx];
|
||||
let totalRows = 0;
|
||||
for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) {
|
||||
const rowIDs = allRowIDs[sectionIdx];
|
||||
totalRows += rowIDs.length;
|
||||
}
|
||||
return totalRows;
|
||||
@@ -416,9 +416,9 @@ function keyedDictionaryFromArray(arr) {
|
||||
if (isEmpty(arr)) {
|
||||
return {};
|
||||
}
|
||||
var result = {};
|
||||
for (var ii = 0; ii < arr.length; ii++) {
|
||||
var key = arr[ii];
|
||||
const result = {};
|
||||
for (let ii = 0; ii < arr.length; ii++) {
|
||||
const key = arr[ii];
|
||||
warning(!result[key], 'Value appears more than once in array: ' + key);
|
||||
result[key] = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user