Code Monkey home page Code Monkey logo

react-timer-machine's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-timer-machine's Issues

Timer doesn't start

Hi,

Many thanks for your component, this is exactly what I need. But, unfortunately, I'm unable to run it in a very simple way. The time is well displayed (10), but the timer doesn't start. Could you help me with this issue please?

Here is the code :

import React from 'react';
import { StyleSheet,SafeAreaView, View, Text,Image } from 'react-native';
import TimerMachine from 'react-timer-machine';
import moment from "moment";
import momentDurationFormatSetup from "moment-duration-format";

momentDurationFormatSetup(moment);

class CounterScreen extends React.Component {
  state = {
    isTimerStarted: true,
  };

  constructor(props) {
    super(props);
  }

  render() {
    return (
      <Text>
        <TimerMachine
          timeStart={10 * 1000} // start at 10 seconds
          timeEnd={20 * 1000} // end at 20 seconds
          started={this.state.isTimerStarted}
          paused={false}
          countdown={false} // use as stopwatch
          interval={1000} // tick every 1 second
          formatTimer={(time, ms) =>
            moment.duration(ms, 'milliseconds').format('h:mm:ss')
          }
          onStart={time =>
            console.info(`Timer started: ${JSON.stringify(time)}`)
          }
          onStop={time =>
            console.info(`Timer stopped: ${JSON.stringify(time)}`)
          }
          onTick={time => console.info(`Timer ticked: ${JSON.stringify(time)}`)}
          onPause={time =>
            console.info(`Timer paused: ${JSON.stringify(time)}`)
          }
          onResume={time =>
            console.info(`Timer resumed: ${JSON.stringify(time)}`)
          }
          onComplete={time =>
            console.info(`Timer completed: ${JSON.stringify(time)}`)
          }
        />
      </Text>
    );
  }
}

Best Regards.

Timer pauses in background

Looks like my timer is pausing in background in a react-native app, which seems to be normal since Expo doesn't support background tasks.

You can work around it by keeping start and end time, maybe the timer itself can support this kind of behavior and by doing the diff rather than counting seconds?

Can't get timer to start

Trying to install it on top of fresh create-react-app project.
Copy pasted the example code and it just shows 10 which is timeStart.
It never changes, callbacks onStart etc are never called.

timer parameter is offset by 1 second on callback functions

Describe the bug
onComplete function timer value is offset by 1 second

To Reproduce
Steps to reproduce the behavior:

  1. Set TimerMachine component
  2. Set countdown to true or set timeEnd
  3. Set any callback function to log the timer value
  4. Open console
  5. See error

Expected behavior
Timer should return a value equal to timeEnd (by default 0).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.