ashura Posted June 2, 2023 Share Posted June 2, 2023 I wanna uninterrupt the flip animation that's it just a simple problem but I cannot find to not interrupt but can't do it anyone care to explain? https://codesandbox.io/s/lively-snowflake-uno0rn?file=/src/styles.scss Link to comment Share on other sites More sharing options...
Rodrigo Posted June 2, 2023 Share Posted June 2, 2023 Hi, I don't see any Flip animation happening in your setup, because right now you're not targeting all the properties that are being updated. Also I spotted a few things that you should consider. Always use GSAP Context when working with React environments.https://greensock.com/docs/v3/GSAP/gsap.context() Always use React's events instead of adding event listeners. It's safer and React will clean those event handlers when/if the component is unmounted. Don't store variables in the global scope of your components, because a re-render will reset those. For a boolean either use state or a ref. Flip.from returns a GSAP Timeline instance so you can store it in a ref. This seems to work the way you expect: export default function App() { const boxRef = useRef(); const flipAnimation = useRef(); const ctx = useRef(gsap.context(() => {})); const clickHandler = () => { ctx.current.add(() => { const state = Flip.getState(boxRef.current, { props: "width,height, background", }); boxRef.current.classList.toggle("enlarge"); flipAnimation.current = Flip.from(state); }); }; useEffect(() => { return () => ctx.current.revert(); }, []); return ( <div className="App"> <div className="composition-component"> <div className="box" ref={boxRef} onClick={clickHandler}> Sky Balls Lopserum Madya </div> <div className="parentBox"> <div className="parentBox1"></div> <div className="parentBox2"></div> </div> </div> </div> ); } Then you can use flipAnimation.current to kill, pause, revert, etc. the timeline returned by the from() method: https://greensock.com/docs/v3/GSAP/Timeline Hopefully this helps. Happy Tweening! 2 Link to comment Share on other sites More sharing options...
ashura Posted June 8, 2023 Author Share Posted June 8, 2023 Thanks I didn't saw your solution. Rodrigo does the ctx.current.revert() always only get called one time or it depends on what are you working different timelines? Link to comment Share on other sites More sharing options...
Rodrigo Posted June 8, 2023 Share Posted June 8, 2023 Hi, That will depend on how your useEffect/useLayoutEffect is setup as described in the React docs: https://react.dev/reference/react/useEffect#my-cleanup-logic-runs-even-though-my-component-didnt-unmount Hopefully this helps. Happy Tweening! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now