npm.io
0.0.126 • Published 3 years ago

@platform/util.animate

Licence
MIT
Version
0.0.126
Deps
2
Size
5 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

Module License: MIT NPM

util.animate

Physics based animation. Uses dynamics.js under the hood.

Setup

yarn add @platform/util.animate

Usage

Within a React component:

private animate(target: { value1: number; value2: number }) {
  this.stop$.next();  // Stop currently executing animation (if any).
  const current = () => this.state;
  const duration = 200;
  animation
    .start({ target, current, duration, type: 'easeInOut' })
    .pipe(takeUntil(this.stop$))
    .subscribe({
      next: data => this.setState(data as any),
      complete: () => {
         // Done.
      },
    });
}