Skip to content

Conversation

@AlenaAlyona
Copy link
Contributor

@AlenaAlyona AlenaAlyona commented Apr 6, 2023

useAnimationLoop hook is a wrapper around requestAnimationFrame function.
This hook will execute the passed callback function every frame.

@leroykorterink leroykorterink force-pushed the feature/use-animation-loop branch from 6a83dd7 to af949e6 Compare May 15, 2023 19:45
@leroykorterink leroykorterink marked this pull request as ready for review May 15, 2023 19:47
@leroykorterink leroykorterink requested a review from ThaNarie May 31, 2023 08:51
Comment on lines +7 to +8
`useAnimationLoop` hook is a wrapper around requestAnimationFrame function. This hook will execute
the passed callback function every frame.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`useAnimationLoop` hook is a wrapper around requestAnimationFrame function. This hook will execute
the passed callback function every frame.
`useAnimationLoop` hook is a wrapper around the `requestAnimationFrame` function. This hook will invoke
the passed `callback` function every frame.

Comment on lines +18 to +19
- `callback` - function accepts `delta` parameter which represents time passed since last
invocation;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `callback` - function accepts `delta` parameter which represents time passed since last
invocation;
- `callback` - a function that receives a `delta` parameter which represents time passed since last
invocation, in milliseconds, as a [DOMHighResTimeStamp](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp)

const [currentTimestamp, setCurrentTimestamp] = useState(Date.now);
const [isRunning, toggleIsRunning] = useToggle(true);
useAnimationLoop(() => {
setCurrentTimestamp(Date.now);
Copy link
Member

Choose a reason for hiding this comment

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

In this example, it might be more useful to do something (e.g. log) the delta that is passed, to better showcase the features of this hook.

* useAnimationLoop hook is a wrapper around requestAnimationFrame method.
* This hook will execute a callback function every next frame.
*
* @param callback - callback function with @param delta which represents time passed since last invocation
Copy link
Member

Choose a reason for hiding this comment

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

This docs (still) say delta, while the implementation (has changed?) returns the actual time.

When running an individual animationFrame, the time might be useful. When you running them in a loop, the delta is often more useful.
I don't mind also forwarding the timestamp, but I feel we should at least calculate and pass the delta.

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.

4 participants