2.1.2 • Published 1 year ago

react-native-element-timer v2.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-element-timer

A component that displays a timer and countdown for React Native. Implemented using react-native-background-timer

Getting started

    npm install react-native-element-timer --save

or

    yarn add react-native-element-timer

Demo

npm.io npm.io

Timer Props

PropsTypeisRequireDescription
initialSecondsNumberNoInitial seconds, defalut is 0
autoStartBooleanNoAuto start timer
startref.start()YesStart timer
pauseref.pause()YesPause timer
resumeref.resume()YesResume timer
stopref.stop()YesStop timer
styleViewStyleNoStyling container view
fontFamilyStringNoCustomize font style
textStyleTextStyleNoStyling text
formatTimehh:mm:ss or ssNoFormat time
onTimes(seconds) => voidNocallback when running time
onPause(seconds) => voidNoCallback when the pause event is called
onEnd(seconds) => voidNoCallback when the stop event is called

Countdown Props

PropsTypeisRequiredefault
initialSecondsNumberYesInitial seconds
autoStartBooleanNoAuto start timer
startref.start()YesStart timer
pauseref.pause()YesPause timer
resumeref.resume()YesResume timer
stopref.stop()YesStop timer
styleViewStyleNoStyling container view
fontFamilyStringNoCustomize font style
textStyleTextStyleNoStyling text
formatTimehh:mm:ss or ssNoFormat time
onTimes(seconds) => voidNocallback when running time
onPause(seconds) => voidNoCallback when the pause event is called
onEnd(seconds) => voidNoCallback when the stop event is called

Usage

    import React, {useRef} from 'react';
    import {StyleSheet, Button, Text, SafeAreaView} from 'react-native';
    import {Timer, Countdown} from 'react-native-element-timer';

    const TimerScreen = _props => {
        const timerRef = useRef(null);
        const countdownRef = useRef(null);

        return (
            <SafeAreaView style={styles.container}>
                <Text style={styles.text}>Timer:</Text>
                <Timer
                    ref={timerRef}
                    style={styles.timer}
                    textStyle={styles.timerText}
                    onTimes={e => {}}
                    onPause={e => {}}
                    onEnd={e => {}}
                />
                <Button
                    style={styles.button}
                    title={'Start'}
                    onPress={() => {
                        timerRef.current.start();
                    }}
                />
                <Button
                    style={styles.button}
                    title={'Pause'}
                    onPress={() => {
                        timerRef.current.pause();
                    }}
                />
                <Button
                    style={styles.button}
                    title={'Resume'}
                    onPress={() => {
                        timerRef.current.resume();
                    }}
                />
                <Button
                    style={styles.button}
                    title={'Stop'}
                    onPress={() => {
                        timerRef.current.stop();
                    }}
                />

                <Text style={styles.text}>Countdown:</Text>
                <Countdown
                    ref={countdownRef}
                    style={styles.timer}
                    textStyle={styles.timerText}
                    initialSeconds={5}
                    onTimes={e => {}}
                    onPause={e => {}}
                    onEnd={(e) => {}}
                />
                <Button
                    style={styles.button}
                    title={'Start'}
                    onPress={() => {
                        countdownRef.current.start();
                    }}
                />
                <Button
                    style={styles.button}
                    title={'Pause'}
                    onPress={() => {
                        countdownRef.current.pause();
                    }}
                />
                <Button
                    style={styles.button}
                    title={'Resume'}
                    onPress={() => {
                        countdownRef.current.resume();
                    }}
                />
                <Button
                    style={styles.button}
                    title={'Stop'}
                    onPress={() => {
                        countdownRef.current.stop();
                    }}
                />
            </SafeAreaView>
        );
    };

    export default TimerScreen;

    const styles = StyleSheet.create({
        container: {
            flex: 1,
            alignItems: 'center',
            padding: 20,
        },
        text: {
            fontWeight: 'bold',
            fontSize: 16,
            marginTop: 40,
        },
        timer: {
            marginVertical: 10,
        },
        timerText: {
            fontSize: 20,
        },
        button: {
            marginVertical: 5,
            backgroundColor: 'white',
            borderRadius: 24,
            width: 100,
        },
    });

Donate

Support maintainers with a donation and help them continue with activities.

2.1.2

1 year ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago