ReactNative 倒计时组件 react-native-zyCountDown

react-native-zyCountDown

用于react-native的计数组件,倒计时组件

封装的一个倒计时按钮,仅仅使用TouchableOpacity,View和Text.

安装

npm i react-native-zycountdown

或者

yarn add react-native-zycountdown

使用

以下3个使用方式样式分别对应下面3张图片

import CountDown from 'react-native-zycountdown';
...

<CountDown
    onClick={() => {
    ToastAndroid.show('Start counting',ToastAndroid.SHORT);
    return true}}
/>

<CountDown
    style={{backgroundColor: 'blue'}}
    textStyle={{color: 'yellow'}}
    count={10}
    title={'click to start'}
    frontText={'frontText:'}
    behindText={'behindText'}
    onClick={() => {
    ToastAndroid.show('Start counting',ToastAndroid.SHORT);
    return true}}
/>


//下面这种写法,在点击方法内,我进行了逻辑判断,不符合逻辑的情况下不进行计时操作,返回false,
<CountDown
  count={10}
  onClick={this._sendMessage}
  style={{backgroundColor: 'green', height: ScreenUtil.scaleSize(30)}}/>

/**
 * 执行点击方法,并进行逻辑判断,满足条件开始计时
 */
 _sendMessage = () => {
        if (“不是手机号码“) {
        //条件不符,返回false 不开始计时
            ToastAndroid.show('手机号码格式不对', ToastAndroid.SHORT);
            return false; 
        }
        //条件符合开始计时:返回true 走下面发送验证码的方法并开始计时
        this._signInWithPhone();
        return true
 };         

 _signInWithPhone = async () => {...}

这里写图片描述 这里写图片描述
这里写图片描述

属性:

PropTypeDefaultDescription
styleViewPropTypes.style{alignItems: ‘center’,justifyContent: ‘center’,paddingHorizontal: 5,height: 40,backgroundColor:’green’}组件的样式
textStyleViewPropTypes.style{ color: ‘#fff’}文字的样式
onClickfunc-点击组件时触发的方法,返回true则触发计数,返回false则不触发计数
countnumber60初始数字
titlestringsend’未计时的时候显示的文字
frontTextstring‘等待’计数时数字左面的数字,用于计数时显示,可设为空字符串
behindTextstring‘秒’计数时数字右面的数字,用于计数时显示,可设为空字符串
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值