Skip to content

Commit 267ccfb

Browse files
nathanajahFacebook Github Bot
authored andcommitted
Enabled flow on ListView.js
Reviewed By: javache Differential Revision: D3476167 fbshipit-source-id: 25ca5fe5063c5d19a96357338235a251a5839dcd
1 parent 9bd80cb commit 267ccfb

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

Libraries/CustomComponents/ListView/ListView.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*
3030
* @providesModule ListView
31+
* @flow
3132
*/
3233
'use strict';
3334

@@ -102,6 +103,13 @@ var DEFAULT_SCROLL_CALLBACK_THROTTLE = 50;
102103
*/
103104

104105
var ListView = React.createClass({
106+
_childFrames: ([]: Array<Object>),
107+
_sentEndForContentLength: (null: ?number),
108+
_scrollComponent: (null: any),
109+
_prevRenderedRowsCount: 0,
110+
_visibleRows: ({}: Object),
111+
scrollProperties: ({}: Object),
112+
105113
mixins: [ScrollResponder.Mixin, TimerMixin],
106114

107115
statics: {
@@ -148,7 +156,7 @@ var ListView = React.createClass({
148156
* it so that the first screen worth of data appears at one time instead of
149157
* over the course of multiple frames.
150158
*/
151-
initialListSize: PropTypes.number,
159+
initialListSize: PropTypes.number.isRequired,
152160
/**
153161
* Called when all rows have been rendered and the list has been scrolled
154162
* to within onEndReachedThreshold of the bottom. The native scroll
@@ -158,15 +166,15 @@ var ListView = React.createClass({
158166
/**
159167
* Threshold in pixels (virtual, not physical) for calling onEndReached.
160168
*/
161-
onEndReachedThreshold: PropTypes.number,
169+
onEndReachedThreshold: PropTypes.number.isRequired,
162170
/**
163171
* Number of rows to render per event loop. Note: if your 'rows' are actually
164172
* cells, i.e. they don't span the full width of your view (as in the
165173
* ListViewGridLayoutExample), you should set the pageSize to be a multiple
166174
* of the number of cells per row, otherwise you're likely to see gaps at
167175
* the edge of the ListView as new pages are loaded.
168176
*/
169-
pageSize: PropTypes.number,
177+
pageSize: PropTypes.number.isRequired,
170178
/**
171179
* () => renderable
172180
*
@@ -198,7 +206,7 @@ var ListView = React.createClass({
198206
* How early to start rendering rows before they come on screen, in
199207
* pixels.
200208
*/
201-
scrollRenderAheadDistance: React.PropTypes.number,
209+
scrollRenderAheadDistance: React.PropTypes.number.isRequired,
202210
/**
203211
* (visibleRows, changedRows) => void
204212
*
@@ -223,7 +231,7 @@ var ListView = React.createClass({
223231
* with `horizontal={true}`.
224232
* @platform ios
225233
*/
226-
stickyHeaderIndices: PropTypes.arrayOf(PropTypes.number),
234+
stickyHeaderIndices: PropTypes.arrayOf(PropTypes.number).isRequired,
227235
/**
228236
* Flag indicating whether empty section headers should be rendered. In the future release
229237
* empty section headers will be rendered by default, and the flag will be deprecated.
@@ -260,13 +268,13 @@ var ListView = React.createClass({
260268
*
261269
* See `ScrollView#scrollTo`.
262270
*/
263-
scrollTo: function(...args) {
271+
scrollTo: function(...args: Array<mixed>) {
264272
if (this._scrollComponent && this._scrollComponent.scrollTo) {
265273
this._scrollComponent.scrollTo(...args);
266274
}
267275
},
268276

269-
setNativeProps: function(props) {
277+
setNativeProps: function(props: Object) {
270278
if (this._scrollComponent) {
271279
this._scrollComponent.setNativeProps(props);
272280
}
@@ -290,7 +298,7 @@ var ListView = React.createClass({
290298
getInitialState: function() {
291299
return {
292300
curRenderedRowsCount: this.props.initialListSize,
293-
highlightedRow: {},
301+
highlightedRow: ({} : Object),
294302
};
295303
},
296304

@@ -319,7 +327,7 @@ var ListView = React.createClass({
319327
});
320328
},
321329

322-
componentWillReceiveProps: function(nextProps) {
330+
componentWillReceiveProps: function(nextProps: Object) {
323331
if (this.props.dataSource !== nextProps.dataSource ||
324332
this.props.initialListSize !== nextProps.initialListSize) {
325333
this.setState((state, props) => {
@@ -343,7 +351,7 @@ var ListView = React.createClass({
343351
});
344352
},
345353

346-
_onRowHighlighted: function(sectionID, rowID) {
354+
_onRowHighlighted: function(sectionID: string, rowID: string) {
347355
this.setState({highlightedRow: {sectionID, rowID}});
348356
},
349357

@@ -489,11 +497,11 @@ var ListView = React.createClass({
489497
);
490498
},
491499

492-
_setScrollComponentRef: function(scrollComponent) {
500+
_setScrollComponentRef: function(scrollComponent: Object) {
493501
this._scrollComponent = scrollComponent;
494502
},
495503

496-
_onContentSizeChange: function(width, height) {
504+
_onContentSizeChange: function(width: number, height: number) {
497505
var contentLength = !this.props.horizontal ? height : width;
498506
if (contentLength !== this.scrollProperties.contentLength) {
499507
this.scrollProperties.contentLength = contentLength;
@@ -503,7 +511,7 @@ var ListView = React.createClass({
503511
this.props.onContentSizeChange && this.props.onContentSizeChange(width, height);
504512
},
505513

506-
_onLayout: function(event) {
514+
_onLayout: function(event: Object) {
507515
var {width, height} = event.nativeEvent.layout;
508516
var visibleLength = !this.props.horizontal ? height : width;
509517
if (visibleLength !== this.scrollProperties.visibleLength) {
@@ -514,7 +522,7 @@ var ListView = React.createClass({
514522
this.props.onLayout && this.props.onLayout(event);
515523
},
516524

517-
_maybeCallOnEndReached: function(event) {
525+
_maybeCallOnEndReached: function(event?: Object) {
518526
if (this.props.onEndReached &&
519527
this.scrollProperties.contentLength !== this._sentEndForContentLength &&
520528
this._getDistanceFromEnd(this.scrollProperties) < this.props.onEndReachedThreshold &&
@@ -556,11 +564,11 @@ var ListView = React.createClass({
556564
});
557565
},
558566

559-
_getDistanceFromEnd: function(scrollProperties) {
567+
_getDistanceFromEnd: function(scrollProperties: Object) {
560568
return scrollProperties.contentLength - scrollProperties.visibleLength - scrollProperties.offset;
561569
},
562570

563-
_updateVisibleRows: function(updatedFrames) {
571+
_updateVisibleRows: function(updatedFrames?: Array<Object>) {
564572
if (!this.props.onChangeVisibleRows) {
565573
return; // No need to compute visible rows if there is no callback
566574
}
@@ -596,7 +604,7 @@ var ListView = React.createClass({
596604
var rowID = rowIDs[rowIdx];
597605
var frame = this._childFrames[totalIndex];
598606
totalIndex++;
599-
if(this.props.renderSeparator &&
607+
if (this.props.renderSeparator &&
600608
(rowIdx !== rowIDs.length - 1 || sectionIdx === allRowIDs.length - 1)){
601609
totalIndex++;
602610
}
@@ -636,7 +644,7 @@ var ListView = React.createClass({
636644
visibilityChanged && this.props.onChangeVisibleRows(this._visibleRows, changedRows);
637645
},
638646

639-
_onScroll: function(e) {
647+
_onScroll: function(e: Object) {
640648
var isVertical = !this.props.horizontal;
641649
this.scrollProperties.visibleLength = e.nativeEvent.layoutMeasurement[
642650
isVertical ? 'height' : 'width'

0 commit comments

Comments
 (0)