Skip to content

timerMgr

brainpoint edited this page Mar 2, 2017 · 2 revisions

Example


使用TimerMgr来管理计时器有助于解决在页面切换时原计时器还存在而造成错误的情况

'use strict';
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, } from 'react-native';
import { TimerMGr } from 'react-componet'

class  extends Component {
  constructor(props) {
    super(props);

    // new object.
    this.timerMgr = new TimerMgr();
  }

  componentWillUnmount() {
    // dispose obejct and cancel all timer.
    this.timerMgr.dispose();
  }

  doTimer() {
    // start timer.
    this.timerMgr.setTimeout((tm)=>{}, 2000);
    this.timerMgr.requestAnimationFrame((tm)=>{})
  }
}

Method


构造

在组件的constructor函数中调用 this.timerMgr = new TimerMgr();

析构

在组件的componentWillUnmount方法中调用 this.timerMgr.dispose();

setTimeout(fn, tm)

启动计时器, 并返回计时器对象.

clearTimeout(t)

停止计时器对象

requestAnimationFrame(fn)

启动动画帧, 动画帧将会在渲染后执行一次, 可以根据业务递归调用此函数完成平滑动画.

cancelAnimationFrame(t)

停止动画帧对象

clearAllTimeout()

停止所有计时器

clearAllAnimationFrame()

停止所有动画帧

clearAll()

停止所有计时器与动画帧

Clone this wiki locally