Timers are a crucial section of an application. React Native implements the browser Timers.
计时器是应用程序的关键部分。 React Native实现了浏览器Timers。
A JavaScript code block is normally accomplished synchronously. But there are some JavaScript native functions (Timers) that allow us to delay the execution.
JavaScript代码块通常是同步完成的。 但是,有些JavaScript本机函数( Timers )使我们可以延迟执行。
There are four categories of React Native Timers:
React Native Timers有四类:
- Delay 延迟
- Repeat 重复
- Immediate 即时
- Animation Schedule 动画时间表
Now, let’s dive into the different Timers regarding React Native and Mozilla official documentation.
现在,让我们深入了解有关React Native和Mozilla官方文档的Timers。
DELAY
延迟
Calling the function or executing the code block after the stated delay.
在指定的延迟后调用函数或执行代码块。
var timeoutID = setTimeout(function, delay in milliseconds)
Removing the delay, set by setTimeout().
消除由setTimeout()设置的延迟。
clearTimeout(timeoutID)
timeoutID: The ID is returned by calling the setTimeout
timeoutID:通过调用setTimeout返回ID
REPEAT
重复
Calling the function or executing the code block repeatedly, with a fixed time delay between each call.
重复调用函数或执行代码块,每次调用之间有固定的时间延迟。
var intervalID = setInterval(function, delay in milliseconds);
Canceling the repeated action that was created by setInterval().
取消由setInterval()创建的重复操作。
clearInterval(intervalID);
IMMEDIATE
即时
Calling the function or execution as soon as possible.
尽快调用函数或执行。
var immediateID = setImmediate(function);
Canceling the immediate actions that were set by setImmediate().
取消由setImmediate()设置的立即操作。
clearImmediate(immediateID);
ANIMATION SCHEDULE
动画时间表
It is the standard way to perform animations.
这是执行动画的标准方法。
Calling a function to update an animation before the next animation frame.
在下一个动画帧之前调用一个函数来更新动画。
var requestID = requestAnimationFrame(function);
Canceling the function that was set by requestAnimationFrame().
取消由requestAnimationFrame()设置的功能。
cancelAnimationFrame(requesetID);
Happy coding. 👩💻👨💻
快乐的编码。 👩💻👨💻
Please let me know in the comments if I missed any part.
如果我错过任何部分,请在评论中让我知道。
翻译自: https://medium.com/swlh/react-native-timers-introduction-3d1ecabcb6d1