Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
react-native-animated-stopwatch
Advanced tools
React Native Stopwatch component that smoothly animates the digits change
React Native Stopwatch component that smoothly animates the digits change. Cross-platform, performant, with all animations executed on the UI thread at 60FPS. Compatible with Expo.
npm install react-native-animated-stopwatch
import { useRef } from 'react';
import AnimatedStopwatch, {
StopWatchMethods,
} from 'react-native-animated-stopwatch';
const stopwatchRef = useRef<StopWatchMethods>(null);
function play() {
stopwatchRef.current?.play();
}
function pause() {
const elapsedTimeInMs = stopwatchRef.current?.pause();
// Do something with the elapsed time
console.log(elapsedTimeInMs);
}
function reset() {
stopwatchRef.current?.reset();
}
return <AnimatedStopwatch ref={stopwatchRef} />;
Name | Required | Type | Description |
---|---|---|---|
animationDuration | no | number | The enter/exit animation duration in milliseconds of a stopwatch digit. Defaults to 80 |
animationDelay | no | number | The enter/exit animation delay in milliseconds of a stopwatch digit. Defaults to 0 |
animationDistance | no | number | The enter/exit animation vertical distance in dp of a stopwatch digit. Defaults to 120 |
containerStyle | no | StyleProp<ViewStyle> | The style of the stopwatch View container |
digitStyle | no | StyleProp<TextStyle> | Extra style applied to each digit, excluding separators (: and , ) |
leadingZeros | no | 1 or 2 | The number of zeros for the minutes. Defaults to 1 |
enterAnimationType | no | 'slide-in-up' or 'slide-in-down' | Whether the new digit should enter from the top or the bottom |
separatorStyle | no | StyleProp<TextStyle> | Extra style applied only to separators. In this case, the colon (:) and the comma (,) |
textCharStyle | no | StyleProp<TextStyle> | The style applied to each individual character of the stopwatch |
trailingZeros | no | 0 , 1 or 2 | If 0 , the stopwatch will only display seconds and minutes. If 1 , the stopwatch will display seconds, minutes and hundredth of ms. If 2 , the stopwatch will display seconds, minutes and tens of ms. Defaults to 1 |
play: () => void
Starts the stopwatch or resumes it if paused. It has no effect if the stopwatch is already running.
stopwatchRef.current?.play();
pause: () => number
Pauses the stopwatch. It has no effect if the stopwatch is either paused or reset. The method returns a snapshot of the time elapsed in ms.
stopwatchRef.current?.pause();
reset: () => void
Resets the stopwatch to 0.
stopwatchRef.current?.reset();
getSnapshot: () => number
Returns the current time elapsed in ms.
stopwatchRef.current?.getSnapshot();
stopwatchRef
refers to the ref
passed to the AnimatedStopwatch
component.
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
FAQs
React Native Stopwatch component that smoothly animates the digits change
We found that react-native-animated-stopwatch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.