From 770f8e505e75cb2f812d428d2af82cd09da01f1c Mon Sep 17 00:00:00 2001 From: jfedgar Date: Mon, 8 Jul 2019 02:58:39 -0500 Subject: [PATCH 1/3] Add ability to customize stopwatch tick interval in props --- lib/stopwatch.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/stopwatch.js b/lib/stopwatch.js index c59be85..65d9ef7 100644 --- a/lib/stopwatch.js +++ b/lib/stopwatch.js @@ -14,6 +14,7 @@ class StopWatch extends Component { getTime: PropTypes.func, startTime: PropTypes.number, getMsecs: PropTypes.func, + tickInterval: PropTypes.number } constructor(props) { @@ -68,6 +69,9 @@ class StopWatch extends Component { } start() { + // default to 1 millisecond + const tickInterval = this.props.tickInterval || 1 + if (this.props.laps && this.state.elapsed) { let lap = new Date() - this.state.stopTime; this.setState({ @@ -81,7 +85,7 @@ class StopWatch extends Component { this.interval = this.interval ? this.interval : setInterval(() => { this.setState({elapsed: new Date() - this.state.startTime }); - }, 1); + }, tickInterval); } stop() { From bec689712f9af00f80fc1275aa52fbf935dec913 Mon Sep 17 00:00:00 2001 From: jfedgar Date: Mon, 8 Jul 2019 02:58:59 -0500 Subject: [PATCH 2/3] Add ability to customize timer tick interval in props --- lib/timer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/timer.js b/lib/timer.js index c65a34c..4a8e819 100644 --- a/lib/timer.js +++ b/lib/timer.js @@ -13,6 +13,7 @@ class Timer extends Component { totalDuration: PropTypes.number, getTime: PropTypes.func, getMsecs: PropTypes.func, + tickInterval: PropTypes.number } constructor(props) { @@ -62,6 +63,8 @@ class Timer extends Component { start() { const handleFinish = this.props.handleFinish ? this.props.handleFinish : () => alert("Timer Finished"); const endTime = new Date().getTime() + this.state.remainingTime; + // default to 1 millisecond + const tickInterval = this.props.tickInterval || 1 this.interval = setInterval(() => { const remaining = endTime - new Date(); if(remaining <= 1000) { @@ -71,7 +74,7 @@ class Timer extends Component { return; } this.setState({remainingTime: remaining}); - }, 1); + }, tickInterval); } stop() { From 2ff65aa812a04c335ca23d305657f5b9ec46d9c9 Mon Sep 17 00:00:00 2001 From: jfedgar Date: Mon, 8 Jul 2019 02:59:16 -0500 Subject: [PATCH 3/3] Update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b056a24..a5ab85b 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ import { Stopwatch, Timer } from 'react-native-stopwatch-timer' |options|object|describes style of rendered timer/stopwatch|see example| |getTime|function|get the formatted value on each tick|(time) => console.log(time)| |getMsecs|function|get the number of msecs on each tick|(time) => console.log(time)| +|tickInterval|number|set the interval for the getTime and getMsecs functions to be executed|1ms #### Stopwatch Options