Skip to content
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

refactor: requestAnimationFrame #420

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

NormanV41
Copy link

Migrating from setInterval to requestAnimationFrame for a more smooth animation

Migrating from setInterval to requestAnimationFrame for a more optimize animation
Copy link
Owner

@Nolanus Nolanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @NormanV41,
thank you very much for the PR. I only have two notes that have to be checked. Feel free to do that, otherwise I'll try to squeeze that into my schedule this week.

}

}, this.config._interval, pageScrollInstance);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the config _interval is not needed any longer to "customize" the animation/repaint, it should be removed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have deleted everything related with config._interval

@@ -198,7 +198,14 @@ export class PageScrollService {
// .. and calculate the end time (when we need to finish at last)
pageScrollInstance.endTime = pageScrollInstance.startTime + pageScrollInstance.executionDuration;

pageScrollInstance.timer = setInterval((instance: PageScrollInstance) => {
pageScrollInstance.requestFrameId = window.requestAnimationFrame(this.updateScrollPostion(pageScrollInstance))
Copy link
Owner

@Nolanus Nolanus Feb 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global window object shouldn't be access directly, rather the little bit more complicated angular way via document object, that we already got hold of at the pageScrollInstance config
https://stackoverflow.com/a/50023378/2225619 , https://stackoverflow.com/a/52620181/2225619)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I changed it, now I am using pageScrollInstance.pageScrollOptions.document.defalutView instead of window

Now use the injected document to reference the window object.
the _interval option is no longer needed
@NormanV41 NormanV41 requested a review from Nolanus April 8, 2021 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants