-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TimerMixin] Remove TimerMixin from ListView #21488
Conversation
Thanks for the PR! Please note the comment about the importance of test plans from the main issue. I don't think relying on Flow for this is sufficient. We've seen some surprising errors sneak in after having made these changes when they weren't tested by running the code.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was quick! Thanks for the PR :)
It looks mostly good, but I have a few concerns.
Libraries/Lists/ListView/ListView.js
Outdated
@@ -216,14 +215,15 @@ type Props = $ReadOnly<{| | |||
|
|||
const ListView = createReactClass({ | |||
displayName: 'ListView', | |||
_rafId: (null: ?AnimationFrameID), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_rafIds: Array<AnimationFrameID>
Libraries/Lists/ListView/ListView.js
Outdated
componentDidMount: function() { | ||
// do this in animation frame until componentDidMount actually runs after | ||
// the component is laid out | ||
this.requestAnimationFrame(() => { | ||
this._rafId = requestAnimationFrame(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both componentDidMount
and componentDidUpdate
will write to this._rafId
, which means that the rafId
from componentDidUpdate
will overwrite the rafId
from componentDidMount
. Suppose that both hooks are executed, and then the component is unmounted, all before the first requestAnimationFrame
hook is executed. Then, with the current setup, we'll end up executing this._measureAndUpdateScrollProps();
once.
To get around this, we could add the following function to ListView:
requestAnimationFrame(fn: () => void): void {
const rafId = requestAnimationFrame(() => {
this._rafIds.splice(this._rafIds.indexOf(rafId));
fn();
})
this._rafIds.push(rafId);
},
You're right, I'll update it to have multiple references and come up with a test plan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 🧐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSNara has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Related to #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: #21488 Differential Revision: D10219088 Pulled By: RSNara fbshipit-source-id: 946e4fc1319324c5bf4947a2060b18bebb6fc493
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
Related to #21485
Test Plan:
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:
Release Notes:
[GENERAL] [ENHANCEMENT] [ListView.js] - rm TimerMixin