Hello friends, In today’s tutorial we would learn about Countdown timer component in react native. We have all seen countdown timer in our mobile apps, Where after a certain given time we can fire a Event or function and does some work. This timer also does the same but it comes in very beautiful look. Now many of us thinks, How we can use this timer in our mobile application, So we have seen sometimes when a company or individual starts a new application or website then they have sometimes given us a Timer. When this timer finished then automatically new application would appear on screen. So in this tutorial we would learn about Example of React Native Countdown Component Timer.
Contents in this project Example of React Native Countdown Component Timer :-
1. First of all we have to install the React Native Countdown Component Timer in our current react native application. So open your App’s main Root directory in CMD in windows and Terminal in MAC and execute below command
1 |
npm install react-native-countdown-component --save |
OR
1 |
yarn add react-native-countdown-component |
Screenshots :-

1 2 3 4 5 |
import React from "react"; import { Alert, SafeAreaView, StyleSheet, Text, View } from 'react-native'; import CountDown from 'react-native-countdown-component'; |
3. Creating our main App component.
1 2 3 4 5 |
export default function App() { } |
4. Creating a function named as onFinishCD. We would call this function when Countdown timer finished.
1 2 3 |
const onFinishCD = () => { Alert.alert('Countdown Finished...'); } |
5. Creating a function named as onPressCD. We would call this function when user clicks on the Timer.
1 2 3 |
const onPressCD = () => { Alert.alert('Countdown Component Pressed...'); } |
6. Creating return() block, Now here we would make our main Countdown timer.
- until :- Here we would pass the countdown timer time in seconds. It will be automatically calculated.
- onFinish :- Calls a function when countdown timer will be finished.
- onPress :- Calls a function when countdown timer clicks.
- size :- Size of countdown timer.
1 2 3 4 5 6 |
<CountDown until={600} onFinish={onFinishCD} onPress={onPressCD} size={20} /> |
7. Creating Style.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
const styleSheet = StyleSheet.create({ MainContainer: { flex: 1, padding: 5, alignItems: 'center', }, title: { fontSize: 24, textAlign: 'center', color: 'green', padding: 3, } }); |
8. Complete Source Code for App.js file :-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import React from "react"; import { Alert, SafeAreaView, StyleSheet, Text, View } from 'react-native'; import CountDown from 'react-native-countdown-component'; export default function App() { const onFinishCD = () => { Alert.alert('Countdown Finished...'); } const onPressCD = () => { Alert.alert('Countdown Component Pressed...'); } return ( <SafeAreaView style={{ flex: 1 }}> <View style={styleSheet.MainContainer}> <Text style={styleSheet.title}> Example of React Native Countdown Component </Text> <CountDown until={600} onFinish={onFinishCD} onPress={onPressCD} size={20} /> </View> </SafeAreaView> ); } const styleSheet = StyleSheet.create({ MainContainer: { flex: 1, padding: 5, alignItems: 'center', }, title: { fontSize: 24, textAlign: 'center', color: 'green', padding: 3, } }); |
Screenshots :-