npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

animated-react-native

v1.0.0

Published

A lightweight and flexible animation library for React Native, inspired by react-native-reanimated.

Downloads

64

Readme


animated-react-native

A lightweight and flexible animation library for React Native, inspired by react-native-reanimated.

Features

  • Create smooth and high-performance animations using React Native's native driver.
  • Support for timing, spring, and decay animations.
  • Simple hooks to manage animations declaratively.
  • Fully compatible with functional components.
  • Includes comprehensive unit tests with coverage.

Installation

Step 1: Install the Package

npm install animated-react-native

Step 2: Compile TypeScript Files (For Development)

If you're working on this library or testing locally, make sure to compile TypeScript files into JavaScript:

npx tsc

This will generate JavaScript files in the dist/ directory (or the output directory specified in tsconfig.json).


Getting Started

Here’s a simple example to get you started:

Example Usage

import React from 'react';
import { View, Button, StyleSheet } from 'react-native';
import { useAnimatedValue, useTiming } from 'animated-react-native';

const App = () => {
  const opacity = useAnimatedValue(0);

  const toggleAnimation = () => {
    useTiming(opacity, opacity._value === 0 ? 1 : 0, 1000);
  };

  return (
    <View style={styles.container}>
      <Animated.View style={[styles.box, { opacity }]} />
      <Button title="Toggle Animation" onPress={toggleAnimation} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  box: { width: 100, height: 100, backgroundColor: 'blue' },
});

export default App;

API Reference

AnimatedAPI

AnimatedAPI.Value(initialValue: number)

Creates a new animated value.

const value = AnimatedAPI.Value(0);

AnimatedAPI.timing(value: Animated.Value, config: Animated.TimingAnimationConfig)

Performs a timing animation.

AnimatedAPI.timing(value, {
  toValue: 1,
  duration: 1000,
  useNativeDriver: true,
}).start();

AnimatedAPI.spring(value: Animated.Value, config: Animated.SpringAnimationConfig)

Performs a spring animation.

AnimatedAPI.spring(value, {
  toValue: 1,
  useNativeDriver: true,
}).start();

AnimatedAPI.interpolate(value: Animated.Value, inputRange: number[], outputRange: number[])

Interpolates an animated value.

const interpolated = AnimatedAPI.interpolate(value, [0, 1], [0, 100]);

Hooks

useAnimatedValue(initialValue: number)

A hook for creating animated values.

const value = useAnimatedValue(0);

useTiming(value: Animated.Value, toValue: number, duration: number)

A hook for performing timing animations.

useTiming(value, 1, 1000);

useSpring(value: Animated.Value, toValue: number)

A hook for performing spring animations.

useSpring(value, 1);

Testing

Running Unit Tests

All test files are located in the tests/ directory. To run the tests:

  1. Clone the repository.

  2. Install dependencies:

    npm install
  3. Run the tests:

    npm test

This will execute all test cases and display the results in the console.

Test Coverage Report

To generate a test coverage report, run:

npm test -- --coverage

This will create a coverage summary and detailed files in the coverage/ directory.

Example Output

 PASS  src/Animated.test.ts
  AnimatedAPI
    ✓ should create an animated value with an initial value (3ms)
    ✓ should interpolate values correctly (2ms)
    ✓ should perform a timing animation (3ms)
    ✓ should perform a spring animation (2ms)

 PASS  src/useAnimatedValue.test.ts
  useAnimatedValue
    ✓ should create an animated value (2ms)
    ✓ should allow updates to the animated value (1ms)

-------------------------|---------|----------|---------|---------|-------------------
File                     | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------|---------|----------|---------|---------|-------------------
All files                |   100%  |    100%  |   100%  |   100%  |
 src                     |   100%  |    100%  |   100%  |   100%  |
  Animated.ts            |   100%  |    100%  |   100%  |   100%  |
  useAnimations.ts       |   100%  |    100%  |   100%  |   100%  |
-------------------------|---------|----------|---------|---------|-------------------

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.

  2. Create a new branch for your feature or bug fix.

  3. Add your changes, including unit tests if applicable.

  4. Run tests to ensure everything works:

    npm test
  5. Submit a pull request with a detailed description of your changes.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Acknowledgments

This library is inspired by the amazing react-native-reanimated library. If you need advanced features like worklets or shared values, we recommend using it.