Skip to content

Commit bf5bb6e

Browse files
excedfacebook-github-bot
authored andcommitted
Remove TimerMixin from ListView (facebook#21488)
Summary: Related to facebook#21485 - Remove TimerMixin from ListView - All flow tests succeed. - RNTester: <ListView> iOS (this change should only affect iOS because calculateChildFrames is iOS only) Show perf monitor, show ListView* screen, start scrolling. UI frame Rate is used at the beginning. When scrolling there is no drop in FPS rate. TODO: I think a load test would be more relevant: - Update props multiple times and scroll [GENERAL] [ENHANCEMENT] [ListView.js] - rm TimerMixin Pull Request resolved: facebook#21488 Differential Revision: D10219088 Pulled By: RSNara fbshipit-source-id: 946e4fc1319324c5bf4947a2060b18bebb6fc493
1 parent 9f176b5 commit bf5bb6e

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Libraries/Lists/ListView/ListView.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const RCTScrollViewManager = require('NativeModules').ScrollViewManager;
1818
const ScrollView = require('ScrollView');
1919
const ScrollResponder = require('ScrollResponder');
2020
const StaticRenderer = require('StaticRenderer');
21-
const TimerMixin = require('react-timer-mixin');
2221
const View = require('View');
2322
const cloneReferencedElement = require('react-clone-referenced-element');
2423
const createReactClass = require('create-react-class');
@@ -216,14 +215,15 @@ type Props = $ReadOnly<{|
216215

217216
const ListView = createReactClass({
218217
displayName: 'ListView',
218+
_rafIds: ([]: Array<AnimationFrameID>),
219219
_childFrames: ([]: Array<Object>),
220220
_sentEndForContentLength: (null: ?number),
221221
_scrollComponent: (null: ?React.ElementRef<typeof ScrollView>),
222222
_prevRenderedRowsCount: 0,
223223
_visibleRows: ({}: Object),
224224
scrollProperties: ({}: Object),
225225

226-
mixins: [ScrollResponder.Mixin, TimerMixin],
226+
mixins: [ScrollResponder.Mixin],
227227

228228
statics: {
229229
DataSource: ListViewDataSource,
@@ -347,16 +347,23 @@ const ListView = createReactClass({
347347
contentLength: null,
348348
offset: 0,
349349
};
350+
351+
this._rafIds = [];
350352
this._childFrames = [];
351353
this._visibleRows = {};
352354
this._prevRenderedRowsCount = 0;
353355
this._sentEndForContentLength = null;
354356
},
355357

358+
componentWillUnmount: function() {
359+
this._rafIds.forEach(cancelAnimationFrame);
360+
this._rafIds = [];
361+
},
362+
356363
componentDidMount: function() {
357364
// do this in animation frame until componentDidMount actually runs after
358365
// the component is laid out
359-
this.requestAnimationFrame(() => {
366+
this._requestAnimationFrame(() => {
360367
this._measureAndUpdateScrollProps();
361368
});
362369
},
@@ -384,7 +391,7 @@ const ListView = createReactClass({
384391
},
385392

386393
componentDidUpdate: function() {
387-
this.requestAnimationFrame(() => {
394+
this._requestAnimationFrame(() => {
388395
this._measureAndUpdateScrollProps();
389396
});
390397
},
@@ -535,6 +542,14 @@ const ListView = createReactClass({
535542
* Private methods
536543
*/
537544

545+
_requestAnimationFrame: function(fn: () => void): void {
546+
const rafId = requestAnimationFrame(() => {
547+
this._rafIds.splice(this._rafIds.indexOf(rafId));
548+
fn();
549+
});
550+
this._rafIds.push(rafId);
551+
},
552+
538553
_measureAndUpdateScrollProps: function() {
539554
const scrollComponent = this.getScrollResponder();
540555
if (!scrollComponent || !scrollComponent.getInnerViewNode) {

0 commit comments

Comments
 (0)