计时器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 '========= ...
随机推荐
- Web 版 powerdesigner (Canvas) 技术分享
演示地址:http://www.netuml.com:8088 <canvas></canvas>是HTML5出现的新标签,像所有的dom对象一样它有自己本身的属性.方法和事 ...
- 拖拽系列二、利用JS面向对象OOP思想实现拖拽封装
接着上一篇拖拽系列一.JavaScript实现简单的拖拽效果这一篇博客将接着对上一节实现代码利用JS面向对象(OOP)思维对上一节代码进行封装; 使其模块化.避免全局函数污染.方便后期维护和调用:写到 ...
- 谈谈我的session跨域处理方法
情景:公司的一个网站有一个模块(测试模块)需要单独用另外的一个域名(www.btest.com)去访问,即网站需要用两个不同的域名去访问,如首页(www.abc.com)和测试模块(www.xyz.c ...
- JAVA Semaphore详解
Semaphore(信号量):是一种计数器,用来保护一个或者多个共享资源的访问.如果线程要访问一个资源就必须先获得信号量.如果信号量内部计数器大于0,信号量减1,然后允许共享这个资源:否则,如果信号量 ...
- call,apply和bind,其实很简单
call和apply call和aplly作用完全一样,都是在特定的上下文中调用函数,或者说改变函数内部的this指向:区别仅在于接收参数的方式不同. var dog = { name: " ...
- Unable open dabase as spfile parameter incorrect
Error desc: ORA-00821: Specified value of sga_target 16M is too small, needs to be at least 4832M ...
- Vuejs实例-02Vue.js项目集成ElementUI
Vuejs实例-02Vue.js项目集成ElementUI 0:前言 vue.js的UI组件库,在git上有多个项目,我见的使用者比较多的是iView和Element.两个组件库,组件都很丰富. 官网 ...
- Python的join()函数和split()函数
join()方法 ------------------------------------------------------------------------------------------- ...
- 《JAVA与模式》之命令模式
在阎宏博士的<JAVA与模式>一书中开头是这样描述命令(Command)模式的: 命令模式属于对象的行为模式.命令模式又称为行动(Action)模式或交易(Transaction)模式. ...
- centos6.5 ssh免密码登陆
ssh-keygen -t rsa ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop1