0.0.12 • Published 5 years ago

@wapps/react-animation-frame v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

react-animation-frame

Build Status

React higher-order component for managing recurring animation frames

Installation

npm install --save @wapps/react-animation-frame

How to use

import React, { Component } from 'react';
import withAnimationFrame from '@wapps/react-animation-frame';

class Loop extends Component {
  constructor(props) {
    super(props);

    this.nodeRef = React.createRef();
    this.startTime = performance.now();
  }

  onAnimationFrame(time) {
    const { duration } = this.props;
    const progress = ((time - this.startTime) / duration) * 100;

    if (progress >= 100) {
      this.startTime = performance.now();
      return;
    }

    const node = this.nodeRef.current;
    node.style.width = `${progress}%`;
  }

  render() {
    return (
      <div
        style={{ backgroundColor: 'blue', color: 'white' }}
        ref={this.nodeRef}
      >
        Loop
      </div>
    );
  }
}

export default withAnimationFrame(Loop);

Live Demo

For a demo, check out https://hupe1980.github.io/wapps-components/

License

MIT

0.0.12

5 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago