Hello greensockers,
I got a little problem here.
So the onComplete function recall every time the toggleStartAnim function, and not just once.
So I do not understand why... normally the cycle is finish, any idea...
here some of my code :
import React, { useEffect, useState } from "react";
import GifFusee from "../assets/gif/fuseeQuiGalere.gif";
import { gsap, MotionPathPlugin, TimelineMax } from "gsap/all";
import WayToMars from "./WayToMars";
import "../assets/stylesheets/Intro.css";
const Intro = () => {
let currentTimeScale;
const [animStart, setAnimStart] = useState(false);
// gsap.registerPlugin(MotionPathPlugin);
const takeTime = () => {
// currentTimeScale = gsap.globalTimeline.time();
};
const tl = new TimelineMax({
onUpdate: takeTime,
yoyo: false,
repeatDelay: 1
});
const toggleStartAnim = () => {
setAnimStart(!animStart);
console.log("toggleStartAnim pop");
};
function test2() {
return new Promise(resolve => {
tl.set(".intro-container", { autoAlpha: 1 })
.set("#takeoff", {
autoAlpha: 1
})
.to("#takeoff", 5, {
rotation: 360,
ease: "linear"
})
.set("#fuseehop", { autoAlpha: 1 })
.set("#fuseeKiDecol", { autoAlpha: 1 })
.to("#fuseeKiDecol", {
y: -10,
scaleY: -0.1,
scaleX: -0.1,
duration: 10,
onComplete: () => {
toggleStartAnim();
resolve();
},
onCompleteParams: {}
});
});
}
useEffect(() => {
test2().then(() => {
console.log("test2 done");
});
console.log(animStart);
});
useEffect(() => {
gsap.globalTimeline.pause();
}, []);
return (
<div>
{/* Debut intro */}
<div className="intro-container">
{/* Debut decollage fusee */}
<div id="fuseehop" className="container-fusee">
<img
alt="fuseekidecol"
id="fuseeKiDecol"
className="container-fusee"
src={GifFusee}
/>
</div>
{/* Debut rotation terre */}
<div className="takeoffplanet">
<div id="takeoff" />
</div>
</div>
<WayToMars animStart={animStart} changeState={toggleStartAnim} />
</div>
);
};
export default Intro;
Edit: problem solved in an other way:
set the hooks by false like that i'm sure that even if the function is anormally call every x time,
i'll set it by true in the child component after
really i do not understand why onComplete repeat every time if everybody got an idea why :s
const toggleStartAnim = () => {
setAnimStart(false);
};