react-native-animated-manager
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-native-animated-mananger

Simple class wrapping native Animated Value that helps to perform various operations on them

yarn add react-native-animated-mananger

Create value

import { AnimatedManager } from 'react-native-animated-mananger';
 
new AnimatedManager(0);
new AnimatedManager(true); // will convert true > 1, false > 0
new AnimatedManager(new Animated.Value(1));

Get raw animated value (to pass it to styles)

const value = new AnimatedManager(0);
const rawAnimatedValue = value.getValue();

Compose values

const valueA = new AnimatedManager(1);
const valueB = new AnimatedManager(2);
const valueC = new AnimatedManager(4);
const valueD = valueA
  .add(valueB, valueC)
  .multiply(2)
  .divide(valueB);
 
<SomeAnimatedView style={{ height: valueD.getValue() }} />;

Call animations as promises

const value = new AnimatedManager(1);
 
async function increase() {
  await value.spring({ toValue: 2 }); // no need to call .start()
  console.log('animation finished');
}

API

// allowed input for AnimatedManager class and methods
type AnimatedValueInput = number | boolean | Animated.Value | AnimatedManager;
 
 
// return raw react natvie Animated.Value
value.getValue()RawAnimatedValue;
// inverts value that is in 0-1 range.
// example: const animatedOpacity = isHidden.invert()
// it's shortcut of .interpolate({ inputRange: [0, 1], outputRange: [1, 0})
value.invert()AnimatedManager;
 
// basic mathematical operators - under the hood it just use raw Animated.add etc but in chainable way
// also every valid AnimatedManager input can be used eg. someValue.add(new Animated.Value(2), 50, true)
value.multiply(...inputsAnimatedValueInput[])AnimatedManager;
value.subtract(...inputsAnimatedValueInput[])AnimatedManager;
value.add(...inputsAnimatedValueInput[])AnimatedManager;
value.divide(...inputsAnimatedValueInput[])AnimatedManager;
 
// Works the same as raw Animated.spring etc, but doesnt need .start() to be called and returns promise that is resolved when animation is finished
value.spring(configRawAnimated.SpringAnimationConfig)Promise<this>;
value.timing(configRawAnimated.TimingAnimationConfig)Promise<this>;
 
// works exactly as native interpolation function
value.interpolate(interpolationRawAnimated.InterpolationConfigType)AnimatedManager;

Tips and Gotchas

Always remember to call .getValue() before passing it to animated view. Animated view will only accept raw Animated.Value instance that is returned by .getValue()

Helpers

Connecting it to events. Pass .getValue() result to Animated.Event

Also there is helper method for scroll based events:

<ScrollView onScroll={animatedManagerInstance.getScrollListener('y')} />

Readme

Keywords

none

Package Sidebar

Install

npm i react-native-animated-manager

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

17.7 kB

Total Files

8

Last publish

Collaborators

  • pie6k