1.1.4 • Published 4 years ago

react-native-circular-timer v1.1.4

Weekly downloads
31
License
MIT
Repository
github
Last release
4 years ago

react-native-circular-timer

Circular Timer component for React Native

NPM

  • stable release version: version
  • package downloads: downloads
  • MIT license

Show Case

npm.io

Getting Started

Installation

npm i react-native-circular-timer --save

Basic Usage

  • Initialization of a react-native project
$ npx react-native init AwesomeProject

Note: GUIDE

  • Then, edit AwesomeProject/App.js, like this:
import { View } from 'react-native';
import CircularTimer from 'react-native-circular-timer';

export default class App extends Component<Props> {
  _restartTimer = () => {
    if (this._timerRef) this._timerRef.restart();
  };

  render() {
    return (
      <View
        style={{
          flex: 1,
          justifyContent: 'center',
          alignItems: 'center',
          backgroundColor: 'white'
        }}
      >
        <CircularTimer
          ref={refs => (this._timerRef = refs)}
          onTimeElapsed={() => {
            console.log('Timer Finished!');
          }}
          showSecond={true}
        />
        <TouchableOpacity
          onPress={this._restartTimer}
          style={{
            marginTop: 20,
            borderRadius: 6,
            backgroundColor: '#000000'
          }}
        >
          <Text
            style={{
              padding: 16,
              fontSize: 18,
              color: 'white',
              fontWeight: 'bold'
            }}
          >
            Restart Timer
          </Text>
        </TouchableOpacity>
      </View>
    );
  }
}

Props

parametertyperequireddescriptiondefault
secondsnumberyesTime in seconds
radiusnumberyesRadius of the circle
showSecondbooleannoTo show the sec keyword with timerfalse
borderWidthnumbernoThe border width of the circle10
borderColorstringnoThe color of the border"#0E3657"
borderBackgroundColorstringnoThe background color of the border"#A8C3BC"
circleColorstringnoThe color of the circle"#FFF"
styleobjectnoTo apply style to the timer
textStyleobjectnoTo override the text styledefault
secondStyleobjectnoTo override the second styledefault
onTimeElapsedfunctionnoCallback for the timer end() => {}

Methods

methoddescription
restartTo restart the timer again

Note:

Firstly, you need to create reference of the component and then call the restart method using that reference GUIDE.

To run example

cd example
npm install
npx react-native run-android (For android)
npx react-native run-ios (For ios)

In case of any issue follow the GUIDE.

Supported React Native Versions

This project aims to support any version of React Native.

If you require new features or bug fixes for older versions you can fork this project.

Credits

The idea for this modules came from MrToph react-native-countdown-circle package.

Licenses

CircularTimer - MIT © MeharBhutta