@wwzzyying/react-apng
v1.0.3
Published
A React component make apng to canvas for controling apng with apng-js's events callback
Downloads
16
Maintainers
Readme
react-apng
APNG implementation on canvas as a React.js component, provides functions for control it (base on apng-js).
Notice
Based on react-apng
- added support for callback events in apng-js, such as play, frame, end, and other events.
- added Typescript declaration of
ApngComponent - fix apng-js occasional frame skipping after calling
pause
Demo & Examples
Live demo: https://wwzzyying.github.io/react-apng/
To run the examples locally:
npm install or yarn
npm start or yarn startThen open localhost:8080/docs/ in a browser.
Installation
react-apng is available through npm or yarn:
npm install @wwzzyying/react-apng --saveyarn add @wwzzyying/react-apng --saveUsage
Require the react-apng component and render it with JSX:
import React from 'react';
import ApngComponent from '@wwzzyying/react-apng';
//const ApngComponent = require('react-apng'); or this way
import apic1 from './apic1.png';
class ApngComponent extends React.Component {
render() {
return <ApngComponent src={apic1} />;
}
}
React.render(<App />, document.getElementById('app'));Methods && State
methods
playplay the apngpausepause the apngstopstop the apngoneplay the apng once
state
isPlayapng play status
class ApngComponent extends React.Component {
playAndPause =()=>{
const apngcom = this.refs.apngcom;
const isPlay = apngcom.isPlay;
if(isPlay){
apngcom.pause();
}else {
apngcom.play();
}
}
render() {
return (
<ApngComponent
ref="apngcom"
onClick={this.playAndPause}
src={apic1}
/>;
)
}
}You can interact with the component instance using a ref after the componentDidMount lifecycle event has fired (including inside the componentDidMount event in a parent Component).
Properties
classNamestringcanvas classNamestylestringcanvas stylesrcstringlocal image pathautoPlayboolauto play apng (default false)rateflootapng play rate (default 1.0)onPlayplayback startedonFrameframe played (frame number passed as event parameter)onPauseplayback pausedonStopplayback stoppedonEndplayback ended (for APNG with finite count of plays)onClick,onMouseOver...functionbind events like a real dom
Copyright (c) 2018 wangzy MIT Licensed.
