React Native简介中的计时器

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有四类:

  1. Delay

    延迟
  2. Repeat

    重复
  3. Immediate

    即时
  4. Animation Schedule

    动画时间表

Now, let’s dive into the different Timers regarding React Native and Mozilla official documentation.

现在,让我们深入了解有关React NativeMozilla官方文档的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值