Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-animated-stopwatch-timer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-animated-stopwatch-timer

React Native Stopwatch component that smoothly animates the digits change

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
157
increased by55.45%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-animated-stopwatch-timer

npm npm bundle size platforms: ios, android, web license MIT

A React Native Stopwatch/Timer component that empowers reanimated worklets to smoothly animate the digits change. Cross-platform, performant, with all layout animations executed on the UI thread at 60FPS. Compatible with Expo.

It works in two modes:

  • Stopwatch: The timer starts counting up from 0 (default).
  • Timer: The timer starts counting down from a given time. Use the initialTimeInMs prop to activate this mode.

Installation

npm install react-native-animated-stopwatch-timer

You also need to install react-native-reanimated 2.5.x or higher.

npm install react-native-reanimated

If you are installing reanimated on a bare React Native app, you should also follow this additional installation instructions.

Usage

import { useRef } from 'react';
import StopwatchTimer, {
  StopwatchTimerMethods,
} from 'react-native-animated-stopwatch-timer';

const stopwatchTimerRef = useRef<StopwatchTimerMethods>(null);

// Methods to control the stopwatch

function play() {
  stopwatchTimerRef.current?.play();
}

function pause() {
  const elapsedTimeInMs = stopwatchTimerRef.current?.pause();
  // Do something with the elapsed time
  console.log(elapsedTimeInMs);
}

function reset() {
  stopwatchTimerRef.current?.reset();
}

return <StopwatchTimer ref={stopwatchTimerRef} />;

Props

NameRequiredTypeDescription
animationDurationnonumberThe enter/exit animation duration in milliseconds of a digit. Defaults to 80
animationDelaynonumberThe enter/exit animation delay in milliseconds of a digit. Defaults to 0
animationDistancenonumberThe enter/exit animation vertical distance in dp of a digit. Defaults to 120
containerStylenoStyleProp<ViewStyle>The style of the stopwatch/timer View container
digitStylenoStyleProp<TextStyle>Extra style applied to each digit, excluding separators (: and ,). This is useful if the fontFamily has different widths per digit, to avoid an unpleasant fluctuation of the total component width as it runs. Check the example app where this is used on iOS's default San Francisco font, that presents this issue.
initialTimeInMsnonumberIf you want to use it as a timer, set this value
leadingZerosno1 or 2The number of zeros for the minutes. Defaults to 1
enterAnimationTypeno'slide-in-up' or 'slide-in-down'Whether the new digit should enter from the top or the bottom
separatorStylenoStyleProp<TextStyle>Extra style applied only to separators. In this case, the colon (:) and the comma (,)
onFinishno() => voidCallback executed when the timer reaches 0 (only when working in timer mode and initialTimeInMs prop is provided)
textCharStylenoStyleProp<TextStyle>The style applied to each individual character of the stopwatch/timer
trailingZerosno0, 1 or 2If 0, the component will only display seconds and minutes. If 1, the component will display seconds, minutes and hundredth of ms. If 2, the component will display seconds, minutes and tens of ms. Defaults to 1

Methods

play: () => void

Starts the stopwatch/timer or resumes it if paused. It has no effect if it's already running.

stopwatchTimerRef.current?.play();
pause: () => number

Pauses the stopwatch/timer. It has no effect if it is either paused or reset. The method returns a snapshot of the time elapsed in ms.

stopwatchTimerRef.current?.pause();
reset: () => void

Resets the stopwatch/timer.

stopwatchTimerRef.current?.reset();
getSnapshot: () => number

Returns the current time elapsed in ms.

stopwatchTimerRef.current?.getSnapshot();

stopwatchTimerRef refers to the ref passed to the StopwatchTimer component.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

Keywords

FAQs

Package last updated on 12 Jan 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc