Skip to content

satya164/react-native-animated-observer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

react-native-animated-observer

npm MIT License

Helpers that let you observe Animated and Reanimated values and convert between them.

Use case

This library is useful when you have a component that uses Animated and accepts animated values or styles, but you use Reanimated for your app's animations, or vice versa. You can use this library to convert your values to work with the component.

Installation

npm install react-native-animated-observer

API

The library exports the following components:

AnimatedConverter

A component that converts between an Animated.Node and a SharedValue<number> natively.

Usage:

import { AnimatedConverter } from 'react-native-animated-observer';

// ...
const animatedValue = useRef(new Animated.Value(0)).current;
const reanimatedSharedValue = useSharedValue(0);

// ...

<AnimatedConverter from={animatedValue} to={reanimatedSharedValue} />;

It accepts the following props:

from

Value to read and observe changes from. It can be one of the following:

to

Value to update when the from value changes. It can be one of the following:

AnimatedObserver

A component that observes changes in a given value and emits an event when the value changes. This is the building block for AnimatedConverter.

Usage:

import { AnimatedObserver } from 'react-native-animated-observer';

// ...

const animatedValue = useRef(new Animated.Value(0)).current;

// ...

<AnimatedObserver
  value={animatedValue}
  onValueChange={(e) => console.log(e.nativeEvent.value)}
/>;

It accepts the following props:

value

The value to observe.

It can be a number, Animated.Node for Animated, SharedValue<number> or DerivedValue<number> for Reanimated.

onValueChange

A callback function that is called when the observed value changes.

How it works

The library renders a native component that receives an Animated.Node or SharedValue<number> value. When the value changes, the library dispatches an event with this value.

This event is then used with Animated.event (with native driver) or useEvent to update Animated.Value or SharedValue<number> respectively, depending on the usage.

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

About

Helper to convert an Animated value to Reanimated and vice-versa

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published