1.1.3 • Published 4 years ago

react-native-customizable-countdown v1.1.3

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

npm NPM npm GitHub issues

Preview

1

2

3

Installation

from npm:\ npm install react-native-customizable-countdown --save

or from yarn:\ yarn add react-native-customizable-countdown

What's new in v1.1.3

new Prop

animate1 animate2

endingAlert: {
        initiateAt: number (seconds),
        animate:bool, 
        backgroundColor: string,
        digitColor: string,
        labelColor: string
        }
changed Prop names
Previous Prop NameNew Prop Name
textColorlabelColor
textFontWeightlabelFontSize
textFontWeightlabelFontWeight
hoursTextFontStylehoursLabelFontStyle
minutesTextFontStyleminutesLabelFontStyle
secondsTextFontStylesecondsLabelFontStyle
textPositionlabelPosition
enableTextenableLabel
hoursTexthoursLabel
minutesTextminutesLabel
secondsTextsecondsLabel

Props

NameDescriptionRequiredTypedefault
initialSecondsseconds to start the countdownnonumber0
refuse to handle reset, addSeconds and deductSeconds methods. (usage shown below)nofuncnone
onTimeOuttriggers after finishing the countdownyesfuncnone
onChangeget seconds, minutes and hoursnofuncnone
gapgaps between each digit containersnostring or number5
widthwidth of the countdown componentnostring or number200
heightheight of the countdown componentnostring or number80
borderRadiusborderRadius of all digit containersnostring or number5
backgroundColorbackground color of each digit containernostring'white'
hoursBackgroundStylestyling hours digit containernoobjectnone
minutesBackgroundStylestyling minutes digit containernoobjectnone
secondsBackgroundStylestyling seconds digit containernoobjectnone
digitColorchange all digits' colornostring'black'
digitFontSizechange all digits' font sizesnonumber or string18
digitFontWeightchange all digits' colornostringnone
hoursDigitFontStylestyling hours digitsnoobjectnone
minutesDigitFontStylestyling minutes digitsnoobjectnone
secondsDigitFontStylestyling seconds digitsnoobjectnone
labelColorchange all texts' colornostring'black'
labelFontSizechange all texts' font sizesnonumber or string10
labelFontWeightchange all texts' font weightnostringnone
hoursLabelFontStylestyling hours textnoobjectnone
minutesLabelFontStylestyling minutes textnoobjectnone
secondsLabelFontStylestyling seconds textnoobjectnone
enableLabelhide or show text with digitsnoboolnone
labelPostionposition of the texts in each container. 'top' or 'bottom'nostring'bottom'
hoursLabeltext which should display in hours containernostring'Hours'
minutesLabeltext which should display in minutes containernostring'Minutes'
secondsLabeltext which should display in seconds containernostring'Seconds'
showHoursshow or hide hours container if necessory (can hide only if hours digit is zero)nobooltrue
showMinutesshow or hide minutes container if necessory (can hide only if minutes digit is zero)nobooltrue
showSeparatorshow or hide separator between containersnoboolfalse
animateSeparatoronly works when showSeparator is truenoboolfalse
separatorStylestyle the separatornoobjectnone
pausepause the countdownnoboolfalse
activeInBackgroundcountdown works even if the app is in backgroundnobooltrue
endingAlertchange UI colors when countdown hits a certian seconds (initiateAt is required). Allows animation aswell.noobjnone

Usage

import {CountDown} from 'react-native-customizable-countdown'

<CountDown
    ref = {(ref) => this.myRef=ref}
    initialSeconds = {4500}
    onTimeOut = {()=>{}}
    digitFontSize={30}
    labelFontSize = {15}
    width={300}
    height={100}
    hoursLabel={'hrs'}
    minutesLabel={'min'}
    enableLabel = {true}
    backgroundColor={'yellow'}
    hoursBackgroundStyle={{borderWidth:2, backgroundColor:null, borderColor: 'blue'}}
    secondsBackgroundStyle={{borderWidth:0, backgroundColor:null, borderColor: 'blue'}}
    secondsDigitFontStyle={{color:'pink'}}
    secondsLabelFontStyle={{color:'green'}}
    labelColor='red'
    labelFontWeight='bold'
    labelPosition = 'top'/> 
<CountDown
        initialSeconds = {50}
        onTimeOut = {()=>{}}        
        showSeparator = {true}
        animateSeparator = {true}   
        separatorStyle={{color:'red', fontSize: 50}}
        pause = {this.state.pause}
        activeInBackground = {false}
        endingAlert={{
          backgroundColor:'red',
          initiateAt:120, 
          animate:true, 
          digitColor:'blue',
          labelColor:'yellow'
        }}     
        />

onChange

onChange = (hours, minutes, seconds) => {
  console.log('hours: '+hours+' minutes: '+minutes+' seconds: '+seconds);
}

  render() {   
    return ( 
    <CountDown
        ref = {(ref) => this.myRef=ref}
        initialSeconds = {4500}
        onTimeOut = {()=>{alert('time out!')}}
        onChange = {this.onChange}
        digitFontSize={30}
        labelFontSize = {15}
        width={300}
        height={100}/>

Methods

using ref property you can access below mentioned all methods.

resetCountDown

this.myRef.resetCountDown()

addSeconds

this.myRef.addSeconds(number)

deductSeconds

this.myRef.deductSeconds(number)