GithubHelp home page GithubHelp logo

bibixx / react-adobe-animate Goto Github PK

View Code? Open in Web Editor NEW
29.0 2.0 11.0 1.57 MB

Component helping to embed animations from Adobe Animate

License: MIT License

JavaScript 5.00% Shell 0.56% TypeScript 94.44%
react animation adobe adobe-animate

react-adobe-animate's Introduction

Adobe Animate React component

npm npm npm Snyk Vulnerabilities for GitHub Repo semantic-release Commitizen friendly

The component for embedding animations from Adobe Animate.

Table of contents
  1. Installation
  2. Examples
  3. Dependencies
  4. How to use
  5. ๐Ÿ™‹โ€โ™‚๏ธ Questions
  6. ๐Ÿค Contributing
  7. Show your support
  8. ๐Ÿ“ License

Installation

npm install react-adobe-animate
# or
yarn add react-adobe-animate

Examples

Dependencies

  • React
  • CreateJS โ€“ add this to your page <script src="https://code.createjs.com/1.0.0/createjs.min.js"></script>
  • Your animation โ€“ add .js file exported from Adobe Animate to page with <script> tag

How to use

index.html

In your index.html file you should import CreateJS and any other animation js file. Note that this should be done before import of your main jsx file to ensure that they are loaded before React script is executed.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>React Adobe Animate example</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="https://code.createjs.com/1.0.0/createjs.min.js" type="text/javascript"></script>
    <script src="./lishtml5-with-background.js" type="text/javascript"></script>
    <script src="./lishtml5.js" type="text/javascript"></script>
    <script src="/src/your-main-react-file.jsx"></script>
  </body>
</html>

App.tsx

react-adobe-animate exposes a AnimateCC component used to render the animation. For more details on the props passed to the component please see Props.

import { useState } from "react";
import { AnimateCC, GetAnimationObjectParameter } from "react-adobe-animate";

const App = () => {
  const [paused, setPaused] = useState(true);
  const [animationObject, getAnimationObject] = useState<GetAnimationObjectParameter|null>(null);
  const onClick = () => setPaused(!paused);

  console.log(animationObject);

  return (
    <div style={{ width: "400px" }}>
      <AnimateCC
        animationName="lishtml5"
        getAnimationObject={getAnimationObject}
        paused={paused}
      />

      <AnimateCC
        animationName="lishtml5"
        composition="C1475B64B160904BB90B34246A5FF54B"
        paused={paused}
      />

      <button onClick={onClick}>{paused ? "Unpause" : "Pause"}</button><br />
    </div>
  );
};

Next.js

To use the component with Next.js you have to include CreateJS and Animate files (you have to put those into public folder first) with the Script component.

For detailed example see examples/next/pages/index.tsx.

Props

Prop name Type Required Description
animationName string true Name of animation (exportRoot = new lib.animationName(); in js file. There the name is (lib.animationName = function. Also usually name of published file)
composition string false If you have two animations with same name you can specify an id of that animation. You can get it from .html file generate by Adobe Animate (var comp=AdobeAn.getComposition("C1475B64B160904BB90B34246A5FF54B");)
getAnimationObject function false It is fired after component was mounted. It takes 1 argument โ€“ animation object that enables you to fire functions created in Adobe Animate
paused boolean false Whether an animation should be paused
onError function false Function called whenever an error is thrown inside the component

All other props will be passed to div surrounding canvas

FAQ

How do I insert animations published from the same file?

Unfortunately it isn't possible to export from Adobe Animate two unique animations. However you can make one! Simply replace all occurrences of composition id inside your .js file of an animation to one created by you. Composition id is this long string in var comp=AdobeAn.getComposition("C1475B64B160904BB90B34246A5FF54B"); found in .html file published by Adobe Animate.

๐Ÿ™‹โ€โ™‚๏ธ Questions

Should you have any questions on how to use/setup the component feel free to ask you questions on the discussions page.

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

For development purposes you can use the examples folder.
You'll find instructions on how to use it in examples/README.md

Show your support

Give a โญ๏ธ if this project helped you!

๐Ÿ“ License

Copyright ยฉ 2019-2022 bibixx [email protected].
This project is MIT licensed.

react-adobe-animate's People

Contributors

anharu2394 avatar bibixx avatar dependabot[bot] avatar gnuletik avatar witcher112 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-adobe-animate's Issues

null is not an object (evaluating 't.setTransform') on iOS Safari

We recently ported a project using this library on mobile web browsers.
This library works as expected on every mobile browsers we tested except on iPhone 6S Safari (iOS 13.5.1).
Other versions of iOS are not tested.

On iOS Safari, at some random times (happens usually after 5-10 minutes of loading and unloading animations), we are experiencing the following error : null is not an object (evaluating 't.setTransform')
This error is thrown in the animations generated by Adobe Animate inside the startAnimation function called from react-adobe-animate.

Does someone already faces similar issues ?

looking for a demo/ guide

Hi Bartosz,

Thanks for working on this component, sounds promising.

I am looking for a demo or guide to help me to use this component. I have tried to clone it but it doesn't work. so can you help me out?

Event Listeners

Hi, I'm trying to use some animate stuff inside react as well.

I'm wondering if you have an easier way to handle which animations are playing and having callbacks on certain frames bubble up to the react components.

I am also using zimjs

How do I control the animation?

So the animation is working as it should, and I can control if it's paused or not, but what if I want to play it again? There are functions called .seek(), .pause(), .stop(), etc. in the export itself, but I couldn't really access them in a straightforward manner, and when I did get a hold of them they weren't working due to them having the wrong scope.

Is there an easy way to control the timeline of the animation? All I want to do really is to reset the animation so that I can play it again.

Animation with images not showing

Hi, I have an exported animation that pulls various images to use in the animation. The canvas gets created and no errors are displayed but also canvas is empty. Have tried this with a sprite as well.

Animation not showing on page

Discussed in #64

๐Ÿค” It seems as though Adobe has changed the output file format yet again. What version of Adobe Animate have you used to generate the JS and html files?

Originally posted by bigbadbrad August 11, 2021
Hi,
I have the example running locally. I added an elephant animation which comes with Animate. I exported it as html canvas and added it to public. I updated index with: <script src="./elephant.js" type="text/javascript"></script>
and I call it in App.js:

 <AnimateCC
    animationName="elephant"
    getAnimationObject={getAnimationObject}
    paused={paused}
  />

animations.zip

But it isn't rendering. I read the documentation but cannot figure out what I'm missing. Attached are the assets. thx!

v2.2.0 removes getAnimationObject call

Hi,

It seems that the version 2.2.0 removes the getAnimationObject call on init : 90c3892

This props is important as it allows to access the createJs instance in order to handle the loop, visible and onComplete callback.
Is it possible to reintroduce it ?

Thanks

weird size issue when viewed on mobile.

It appears when the animation is viewed on mobile, there are two issues

  1. Canvas width and height attribute becomes massive - sometimes over 5000px. It is styled to be 100% width, but there will be performance issue.
  2. The canvas's sibling dev element has default width and height attribute that differs from the canvas, and it is NOT styled to be 100%.

Both issues never happened when viewed with default AnimateCC export.

Screenshot 2023-06-09 at 2 57 29 pm

Regards,
H

How to deal with createjs 1.0.0?

My export from Adobe Animate 20.0 uses StageGL. So I switched from https://code.createjs.com/createjs-2015.11.26.min.js to https://code.createjs.com/1.0.0/createjs.min.js
Now I get the error

TypeError: f is undefined createjs_1_0_0.min.js:12:19290 _parseData createjs_1_0_0.min.js:12 a createjs_1_0_0.min.js:12 handleComplete index.js:1 initAdobeAn index.js:1 _dispatchEvent createjs_1_0_0.min.js:12 _dispatchEvent createjs_1_0_0.min.js:12 dispatchEvent createjs_1_0_0.min.js:12 _sendComplete createjs_1_0_0.min.js:16 _loadNext createjs_1_0_0.min.js:17 _handleError createjs_1_0_0.min.js:17 on createjs_1_0_0.min.js:12 _dispatchEvent createjs_1_0_0.min.js:12 _dispatchEvent createjs_1_0_0.min.js:12 dispatchEvent createjs_1_0_0.min.js:12 _sendError createjs_1_0_0.min.js:16 handleEvent createjs_1_0_0.min.js:16 on createjs_1_0_0.min.js:12 _dispatchEvent createjs_1_0_0.min.js:12 _dispatchEvent createjs_1_0_0.min.js:12 dispatchEvent createjs_1_0_0.min.js:12 _handleError createjs_1_0_0.min.js:16 proxy createjs_1_0_0.min.js:15

Any hint how to fix this?

Also I think that some code is missing, thats included in
the exported file myanimation.html
for example
AdobeAn.makeResponsive(true,'both',false,1,[canvas,anim_container,dom_overlay_container]);

getContext undefined (Canvas is null)

I'm fairly new to react/jsx, so I apologize if this is not a bug. I'm unclear if the order in execution could be the problem. Version 2.3.1. Cheers.

index.js:
image

CanvasHero.js Component:
image

Canvas.tsx
image

Canvas appears to be null
image

Much appreciated!

AnimateCC: AdobeAn dependency not found

Introduction

Hello there! Let's talk about what we had found :) We will be glad if you will have time to take a look on our issue!
We are using Next.js for our landing page, and we DO NOT use any typescript or any types, if it's important.
We have 2 Adobe animation with static .js files for them on our server.
We had go through your examples but we stacked on one unusual workflow.

How to reproduce a bug

Firstly we have a landing page with 2 animations. Now all working is fine. When you look at it and when you go somewhere and return, no error are throned. Instead of one case when you go to some page and you click refresh button and then go back to page with animation you will see the error about AnimateCC: AdobeAn dependency not found.
We had try to solve this problem with next/script optimisation. We had combined: placing the script on different levels of app, different loading strategies, static and dynamic imports and etc.. But nothing working with us.

Step by step reproducing on stage

  1. Go to Staging landing page.
  2. Go to any other page, for example Blog page or one of Case-studies.
  3. Refresh the page(using refresh button or hot keys, no matter).
  4. Click on back button in your browser(should redirect you to '/' landing page).
  5. Tada!!! you have an Error :)
  6. Open console to see the logs of your library.

Ideas

Probably this issue is relative to SSR(server side rendering) of our Next.js app.
Also looks like the scripts haven't enough time for loading, so maybe you need to add some checking methods
Will be very cool of you will provide some onError method to handle runtime errors.

Thanks for reading, wish you the best!

TypeError: Cannot read property 'getLibrary' of undefined

When trying to use the example you provided, I receive the following error:
TypeError: Cannot read property 'getLibrary' of undefined

My index.html is as follows:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>App</title>
</head>

<body>
    <div id="root"></div>
    <script src="https://code.createjs.com/createjs-2015.11.26.min.js" type="text/javascript"></script>
    <script src="./lishtml5.js"></script>
</body>

</html>

getLibrary reference is found within the Adobe Animate output inside of lishtml5.js

when animationName is changed, the referenced animation doesn't load

When animationName is changed, the new animation doesn't load.

function playback({ state }){
  return (
	  <AnimateCC
	    animationName={state.playback.actor}
	    getAnimationObject={getAnimationObject}
	  /> 
  );
}

Perhaps it would be easiest if I just always load different animate into different AnimateCC components?

StrictMode Issue

The package not work with React.StrictMode activated, if I go to other route and come back the image not show, but first time its is showing

Cannot set property 'tickEnabled' of undefined

When loading an animation and updating state within a useEffect you get this error: Cannot set property 'tickEnabled' of undefined

Example:

const test = props => {
	let [state, setState] = useState(false);
	let animation = useRef();

	useEffect(() => {
		setState(true);
	}, []);

	return (
	   <Animation animationRef={animation} fixedLineHeight animationName="megacash" />
	);
};

Movie isn't rendered when doing a click selector

Hello!

Well, this is whats happening

I'm trying to show 2 buttons on screen,

When clicking the idea is if it was button1 to render on screen animation1

If it was button2 to render on screen animation2

I'm using the code shown below and well, all vars used are indeed being updated but it seems animationObject isn't

Any help will be apreciated

Thanks a lot!

import { useState } from "react";
import AnimateCC from "react-adobe-animate";

const App = () => {
  const [paused, setPaused] = useState(false);
  let [animationObject, getAnimationObject] = useState(null);
  const [animationName, setAnimationName] = useState("animacion1");
  const [composition, setComposition] = useState("31CF89A62C0C40B6A9FBB94549BA8682");
  console.log("animationObject ::: " , animationObject);

  const shoot = (animationName,composition) => {
    console.log(animationName);
    console.log(composition);

    setAnimationName(animationName)
    setComposition(composition)
  }
  
  
  return (
    <div style={{ width: "1024px", height: "638px" }}>
      <AnimateCC
        animationName={animationName}   
        composition={composition} 
        paused={paused}        
      />

      <button onClick={() => shoot("animacion1","31CF89A62C0C40B6A9FBB94549BA8682")}>Archivo 1</button>
      <button onClick={() => shoot("animacion2","78AD7AADD9ABE045B68AAC9D6B6B1C41")}>Archivo 2</button>

      <p>{animationName}</p>
           
    </div>
  );
};

export default App;

Mouseover not detected

Currently, we use a mouseover event to reveal certain elements of a game although the mouseover events within the animation aren't being detected. Any ideas on how to fix this?

stage.mc_pipes.mc_chosen_ball_1.addEventListener('mouseover', reveal_chosen_1);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.