计时器60s
计时器是经常用到的功能,下面以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的更多相关文章
- [FPGA]Verilog 60s秒表计时器(最大可计时间长达9min)
[FPGA]Verilog 60s秒表计时器 1.引述 这次的实验来自于本人本科课程数电结课时的自选题目.由于这次上传是后知后觉,学校已将小脚丫板子回收,所以在这篇文章中没法贴出代码结果的效果图了,但 ...
- 计时器(Chronometer)的使用
安卓提供了一个计时器组件:Chronometer,该组件extends TextView,因此都会显示一段文本,但是它显示的时间是从某个起始时间开始过去了多少时间,它只提供了android:forma ...
- 【咸鱼教程】基于系统时间的计时器DateTimer(不受FPS影响)
教程目录一 计时器简介二 计时器实现三 Demo下载 一 计时器简介在手机上跑游戏时,可能由于运动物体过多,导致帧频太低,计时不准确.比如一些倒计时的游戏,可能倒计时30s,变成了35s.比如ipho ...
- TCP协议有几大计时器?
1)超时重传计时器 目的:避免无限等待确认报文 创建时间:在发送TCP报文段时,会为该报文段设置一个超时重传计时器 可能发生的情况:在超时时间到达之前,收到了该报文段的确认则撤销计时器,否则重传该报文 ...
- android 两种实现计时器时分秒的实现,把时间放在你的手中~
可能我们在开发中会时常用到计时器这玩意儿,比如在录像的时候,我们可能需要在右上角显示一个计时器.这个东西其实实现起来非常简单. 只需要用一个控件Chronometer,是的,就这么简单,我都不好意思讲 ...
- TCP四种计时器
TCP共使用以下四种计时器,即重传计时器.坚持计时器.保活计时器和时间等待计时器 .这几个计时器的主要特点如下: 1.重传计时器 当TCP发送报文段时,就创建该特定报文段的重传计时 ...
- C# - 计时器Timer
System.Timers.Timer 服务器计时器,允许指定在应用程序中引发事件的重复时间间隔. using System.Timers: // 在应用程序中生成定期事件 public class ...
- JavaScript学习笔记5 之 计时器 & scroll、offset、client系列属性 & 图片无缝滚动
一.计时器 setInterval ( 函数/名称 , 毫秒数 )表示每经过一定的毫秒后,执行一次相应的函数(重复) setTimeout ( 函数/名称 , 毫秒数 ) 表示经过一定的毫秒后,只执行 ...
- VBA中使用计时器的两种方法
'================================ ' VBA采用Application.OnTime实现计时器 ' ' http://www.cnhup.com '========= ...
随机推荐
- Java static 关键字详解
引言 在<Java编程思想>中有这样一段话:static方法就是没有this的方法.在static方法内部不能调用非静态方法,反过来是可以的.而且可以在没有创建任何对象的前提下,仅仅通过类 ...
- linux服务器远程链接排错
查看服务器是否能正常访问: xshell下本地shell操作: ping <ip> 关闭服务器iptables防火墙: 查看服务器端口是否正常开启: telnet <ip> & ...
- javascript设计模式详解之命令模式
每种设计模式的出现都是为了弥补语言在某方面的不足,解决特定环境下的问题.思想是相通的.只不过不同的设计语言有其特定的实现.对javascript这种动态语言来说,弱类型的特性,与生俱来的多态性,导致某 ...
- Alamofire源码解读系列(十二)之请求(Request)
本篇是Alamofire中的请求抽象层的讲解 前言 在Alamofire中,围绕着Request,设计了很多额外的特性,这也恰恰表明,Request是所有请求的基础部分和发起点.这无疑给我们一个Req ...
- struts2总体介绍
这篇博客开始将总结一下有关框架的知识,在开发中合适的利用框架会使我们的开发效率大大提高.当今比较流行的开源框架: 关注数据流程的MVC框架 (Struts1/2, WebWork, Spring MV ...
- Eclipse中启动tomcat时内存溢出
今天在启动自己项目的时候遇到一个永久带(permgen space)内存溢出,查找了很多资料和请教了许多大神,最终才解决问题. 一.什么原因造成了永久带溢出: 1.项目使用了太多的静态变量 2.加载了 ...
- MySQL编译安装错误提示合集
1>安装mysql在初始化的时候,出现/usr/local/mysql/bin/mysqld:error while loading shared libraries:libaio.so.1 : ...
- FutureTask——另一种闭锁的实现
关于多线程,我们接触对多的,最基础,入门的可能就是实现Runnable接口继承Thead类,因为Java单继承的原因,通常建议是实现Runnable接口.但这种"简单"的线程会带来 ...
- 重构了cxlt-vue2-toastr插件
距离上篇文章已经过去一个多月了,期间有很多想法,但时间真不是想挤就能挤出来的.其实这段时间我就做了一件事,一个小程序的项目,已上线半月有余,也迭代了几个版本,现在还在不断完善. 先说点题外话,我们做了 ...
- IPad分屏,当电脑第二显示屏
最在在网上看到使用IPad可以做为电脑的第二个显示屏,对于我这样一个程序猿来说,这真是我的福音呀!因此在网上搜了许多关于Ipad投屏的信息,下面简单说明一下,包括怎么使用! 1.根据在网上搜索的结果, ...