From 480f277519473c8228536c3183f2e4999835e76f Mon Sep 17 00:00:00 2001 From: Thomas BARRAS Date: Thu, 4 Oct 2018 16:10:58 -0400 Subject: [PATCH 1/2] UPDATE: remove TimerMixin --- Libraries/Lists/ListView/ListView.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Libraries/Lists/ListView/ListView.js b/Libraries/Lists/ListView/ListView.js index b240620b1504c1..66a5c261f89ead 100644 --- a/Libraries/Lists/ListView/ListView.js +++ b/Libraries/Lists/ListView/ListView.js @@ -18,7 +18,6 @@ const RCTScrollViewManager = require('NativeModules').ScrollViewManager; const ScrollView = require('ScrollView'); const ScrollResponder = require('ScrollResponder'); const StaticRenderer = require('StaticRenderer'); -const TimerMixin = require('react-timer-mixin'); const View = require('View'); const cloneReferencedElement = require('react-clone-referenced-element'); const createReactClass = require('create-react-class'); @@ -216,6 +215,7 @@ type Props = $ReadOnly<{| const ListView = createReactClass({ displayName: 'ListView', + _rafId: (null: ?AnimationFrameID), _childFrames: ([]: Array), _sentEndForContentLength: (null: ?number), _scrollComponent: (null: ?React.ElementRef), @@ -223,7 +223,7 @@ const ListView = createReactClass({ _visibleRows: ({}: Object), scrollProperties: ({}: Object), - mixins: [ScrollResponder.Mixin, TimerMixin], + mixins: [ScrollResponder.Mixin], statics: { DataSource: ListViewDataSource, @@ -347,16 +347,23 @@ const ListView = createReactClass({ contentLength: null, offset: 0, }; + this._childFrames = []; this._visibleRows = {}; this._prevRenderedRowsCount = 0; this._sentEndForContentLength = null; }, + componentWillUnmount: function() { + if (this._rafId != null) { + cancelAnimationFrame(this._rafId); + } + }, + componentDidMount: function() { // do this in animation frame until componentDidMount actually runs after // the component is laid out - this.requestAnimationFrame(() => { + this._rafId = requestAnimationFrame(() => { this._measureAndUpdateScrollProps(); }); }, @@ -384,7 +391,7 @@ const ListView = createReactClass({ }, componentDidUpdate: function() { - this.requestAnimationFrame(() => { + this._rafId = requestAnimationFrame(() => { this._measureAndUpdateScrollProps(); }); }, From 90a31646db6143232ff5ec4173ff500b6413e7da Mon Sep 17 00:00:00 2001 From: Thomas BARRAS Date: Thu, 4 Oct 2018 21:33:13 -0400 Subject: [PATCH 2/2] UPDATE: request animation frame list --- Libraries/Lists/ListView/ListView.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Libraries/Lists/ListView/ListView.js b/Libraries/Lists/ListView/ListView.js index 66a5c261f89ead..9d1443e8fe484e 100644 --- a/Libraries/Lists/ListView/ListView.js +++ b/Libraries/Lists/ListView/ListView.js @@ -215,7 +215,7 @@ type Props = $ReadOnly<{| const ListView = createReactClass({ displayName: 'ListView', - _rafId: (null: ?AnimationFrameID), + _rafIds: ([]: Array), _childFrames: ([]: Array), _sentEndForContentLength: (null: ?number), _scrollComponent: (null: ?React.ElementRef), @@ -348,6 +348,7 @@ const ListView = createReactClass({ offset: 0, }; + this._rafIds = []; this._childFrames = []; this._visibleRows = {}; this._prevRenderedRowsCount = 0; @@ -355,15 +356,14 @@ const ListView = createReactClass({ }, componentWillUnmount: function() { - if (this._rafId != null) { - cancelAnimationFrame(this._rafId); - } + this._rafIds.forEach(cancelAnimationFrame); + this._rafIds = []; }, componentDidMount: function() { // do this in animation frame until componentDidMount actually runs after // the component is laid out - this._rafId = requestAnimationFrame(() => { + this._requestAnimationFrame(() => { this._measureAndUpdateScrollProps(); }); }, @@ -391,7 +391,7 @@ const ListView = createReactClass({ }, componentDidUpdate: function() { - this._rafId = requestAnimationFrame(() => { + this._requestAnimationFrame(() => { this._measureAndUpdateScrollProps(); }); }, @@ -542,6 +542,14 @@ const ListView = createReactClass({ * Private methods */ + _requestAnimationFrame: function(fn: () => void): void { + const rafId = requestAnimationFrame(() => { + this._rafIds.splice(this._rafIds.indexOf(rafId)); + fn(); + }); + this._rafIds.push(rafId); + }, + _measureAndUpdateScrollProps: function() { const scrollComponent = this.getScrollResponder(); if (!scrollComponent || !scrollComponent.getInnerViewNode) {