Shikhar15606 / react-native-accurate-step-counter

A react native library to accurately count the number of steps
https://www.npmjs.com/package/react-native-accurate-step-counter
MIT License
17 stars 13 forks source link
android hacktoberfest hactoberfest2021 ios react-native

react-native-accurate-step-counter

Getting started

Installation

$ npm install react-native-accurate-step-counter react-native-shake

or

$ yarn add react-native-accurate-step-counter react-native-shake

Usage

import React, { useEffect, useState } from 'react';
import { startCounter, stopCounter } from 'react-native-accurate-step-counter';
import { SafeAreaView, StyleSheet, Text, View } from 'react-native';

const App = () => {
  const [steps, setSteps] = useState(0);

  useEffect(() => {
    const config = {
      default_threshold: 15.0,
      default_delay: 150000000,
      cheatInterval: 3000,
      onStepCountChange: (stepCount) => { setSteps(stepCount) },
      onCheat: () => { console.log("User is Cheating") }
    }
    startCounter(config);
    return () => { stopCounter() }
  }, []);

  return (
    <SafeAreaView>
      <View style={styles.screen}>
        <Text style={styles.step}>{steps}</Text>
      </View>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  screen: {
    width: '100%',
    height: '100%',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center'
  },
  step: {
    fontSize: 36
  }
});

export default App;