计时器是经常用到的功能,下面以react nativ的例子简介来写一个倒计时60s的小demo。

代码如下:

import React, { Component } from 'react';
import {
Text,
View,
TouchableOpacity
} from 'react-native';
import {
Button,
Content,
Container,
Header,
InputGroup,
Input,
List,
ListItem,
Thumbnail,
Title,
} from 'native-base'; import MyTheme from '../../themes/myTheme';
import SetNewPasswordView from './../login-register/set-newPassword-view' export default class FindPasswordView extends Component {
constructor(props) {
super(props);
this.state = {
data: 60,
sendButton: true
};
this._index = 60;
this._timer = null;
} countTime() {
this.setState({sendButton: false}); this._timer = setInterval(()=> {
this.setState({data: this._index--});
if (this.state.data <= 0) {
this._timer && clearInterval(this._timer);
this.setState({sendButton: true});
}
}, 1000);
} componentWillUnmount() {
this._timer && clearInterval(this._timer);
} _navigate(name, component, role, type = 'Normal') {
this.props.navigator.push({
component: component,
name: name,
passProps: {
name: name,
role: role
},
onPress: this._onPress,
rightText: '右边',
type: type
})
} render() {
return (
<Container theme={MyTheme}>
<Header>
<Button transparent onPress={()=>this.props.navigator.pop()}>
<Text style={{color:'#35b873'}}>取消</Text>
</Button>
<Title>找回密码</Title>
</Header>
<Content style={{backgroundColor:'#eff2f3'}}>
<View
style={{flex:1,flexDirection:'row',backgroundColor:'#fff',marginTop:20,borderBottomWidth:0.5,borderColor:'#ccc'}}>
<Text style={{marginTop:13,marginLeft:15}}>手机号</Text>
<Input style={{marginLeft:20}} placeholderTextColor={'#ccc'} placeholder="请输入手机号..."/>
</View>
<ListItem
style={{backgroundColor:'#fff',paddingLeft:0,marginLeft:0,marginTop:20,borderBottomWidth:0}}>
<InputGroup>
<Input style={{marginLeft:5,marginRight:10}} placeholderTextColor={'#ccc'}
placeholder="请输入验证码..."/>
{
this.state.sendButton ? <Button style={{marginLeft:5,marginRight:10}} small success
onPress={this.countTime.bind(this)}>发送验证码</Button> :
<Button disabled style={{marginLeft:5,marginRight:10}}
small>请等待{this.state.data}s</Button>
} </InputGroup>
</ListItem>
<Button block success onPress={()=>this._navigate('找回密码',SetNewPasswordView)}
style={{marginLeft:15,marginRight:15,marginTop:40,padding:15,height:45}}>
验证
</Button>
</Content>
</Container>
)
}
}

  

计时器60s的更多相关文章

  1. [FPGA]Verilog 60s秒表计时器(最大可计时间长达9min)

    [FPGA]Verilog 60s秒表计时器 1.引述 这次的实验来自于本人本科课程数电结课时的自选题目.由于这次上传是后知后觉,学校已将小脚丫板子回收,所以在这篇文章中没法贴出代码结果的效果图了,但 ...

  2. 计时器(Chronometer)的使用

    安卓提供了一个计时器组件:Chronometer,该组件extends TextView,因此都会显示一段文本,但是它显示的时间是从某个起始时间开始过去了多少时间,它只提供了android:forma ...

  3. 【咸鱼教程】基于系统时间的计时器DateTimer(不受FPS影响)

    教程目录一 计时器简介二 计时器实现三 Demo下载 一 计时器简介在手机上跑游戏时,可能由于运动物体过多,导致帧频太低,计时不准确.比如一些倒计时的游戏,可能倒计时30s,变成了35s.比如ipho ...

  4. TCP协议有几大计时器?

    1)超时重传计时器 目的:避免无限等待确认报文 创建时间:在发送TCP报文段时,会为该报文段设置一个超时重传计时器 可能发生的情况:在超时时间到达之前,收到了该报文段的确认则撤销计时器,否则重传该报文 ...

  5. android 两种实现计时器时分秒的实现,把时间放在你的手中~

    可能我们在开发中会时常用到计时器这玩意儿,比如在录像的时候,我们可能需要在右上角显示一个计时器.这个东西其实实现起来非常简单. 只需要用一个控件Chronometer,是的,就这么简单,我都不好意思讲 ...

  6. TCP四种计时器

    TCP共使用以下四种计时器,即重传计时器.坚持计时器.保活计时器和时间等待计时器 .这几个计时器的主要特点如下:      1.重传计时器      当TCP发送报文段时,就创建该特定报文段的重传计时 ...

  7. C# - 计时器Timer

    System.Timers.Timer 服务器计时器,允许指定在应用程序中引发事件的重复时间间隔. using System.Timers: // 在应用程序中生成定期事件 public class ...

  8. JavaScript学习笔记5 之 计时器 & scroll、offset、client系列属性 & 图片无缝滚动

    一.计时器 setInterval ( 函数/名称 , 毫秒数 )表示每经过一定的毫秒后,执行一次相应的函数(重复) setTimeout ( 函数/名称 , 毫秒数 ) 表示经过一定的毫秒后,只执行 ...

  9. VBA中使用计时器的两种方法

    '================================ ' VBA采用Application.OnTime实现计时器 ' ' http://www.cnhup.com '========= ...

随机推荐

  1. Docker - 终端交互

    进入容器交互终端 使用docker attach命令进入容器交互终端. 注意:如果多个窗口同时attach到同一个容器,那么所有窗口都会同步显示.如果某个窗口因命令阻塞时,那么其他窗口将无法执行操作. ...

  2. 将字符串当做是php代码执行的函数eavl()

  3. Commonjs规范及Node模块实现

    前面的话 Node在实现中并非完全按照CommonJS规范实现,而是对模块规范进行了一定的取舍,同时也增加了少许自身需要的特性.本文将详细介绍NodeJS的模块实现 引入 nodejs是区别于java ...

  4. maven 聚合工程的创建和打包

    ---恢复内容开始--- 使用eclipse创建maven项目 第一步:创建父工程hg-parent,如图; 右击空白处,new创建新maven工程: 搜索maven项目 父工程使用pom打包方式 第 ...

  5. Redis学习-SortedSet

    Sorted-Sets和Sets类型极为相似,它们都是字符串的集合,都不允许重复的成员出现在一个Set中.它们之间的主要差别是Sorted-Sets中的每一个成员都会有一个分数(score)与之关联, ...

  6. [转]GET,POST,PUT,DELETE的区别

    原文链接:http://blog.csdn.net/mfe10714022/article/details/39692305 Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,P ...

  7. 同步文件的利器-rsync

    即使你只是个人用户而不是一个企业,备份你自己的数据也是非常重要的,我不想失去任何这些数据. rsync是同步文件的利器,一般用于多个机器之间的文件同步与备份,同时也支持在本地的不同目录之间互相同步文件 ...

  8. (one) 条件判断的总结

    第一:if语句的一般形式: if(expression)   statement1; statement2; 对于条件判断,我觉得要点在于“条件”(expression),它是一个结果为false或t ...

  9. Linux 常 用 命 令

    一:关机命令 1:shutdown 语 法:shutdown [-efFhknr][-t 秒数][时间][警告信息] 说明:shutdown指令可以关闭所有程序,并依用户的需要,进行重新开机或关机的动 ...

  10. SparkMLlib回归算法之决策树

    SparkMLlib回归算法之决策树 (一),决策树概念 1,决策树算法(ID3,C4.5 ,CART)之间的比较: 1,ID3算法在选择根节点和各内部节点中的分支属性时,采用信息增益作为评价标准.信 ...