airbnb / lottie-web

Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/
MIT License
30.28k stars 2.87k forks source link

Dynamic text tracking problem in nextjs #2892

Closed gfxargentina closed 1 year ago

gfxargentina commented 1 year ago

Tell us about your environment i use nextjs with @lottiefiles/react-lottie-player

i have problem with text tracking when i render the json in nextjs

this is how text look in AE, the text tracking is ok This is an image

and this is how is look when i render the json with netxjs This is an image

.my-font { font-family: ‘Roboto’, sans-serif; letter-spacing: -1px; }

letter-spacing not fix the problem, I would appreciate it if anyone could tell me where the problem could be, bodymovin is awesome, thank you very much

gfxargentina commented 1 year ago

the problem is the google font, i disable the google font styles, and the text default font is ok, i think is somenthing when the font is loaded, it doesn't load well then it shows wrong text tracking, can someone tell me a possible solution for this?

bodymovin commented 1 year ago

I'm guessing that the font is not loaded when the animation starts. Have you tried, as a test, making sure to load the animation once the font is fully loaded?

oguz3 commented 1 year ago

I'm guessing that the font is not loaded when the animation starts. Have you tried, as a test, making sure to load the animation once the font is fully loaded?

I have the same problem. This did not solve my problem

gfxargentina commented 1 year ago

hi @bodymovin thanks for your response, i try self-host fonts in NextJS, i follow this tutorial , i also try preload the font with

<link
          rel="preload"
          href="/fonts/FrederickatheGreat-Regular.ttf'"
          as="font"
          type="font/ttf"
          crossorigin
        />

but don´t work, i have the same problem, can you put me in the right direction on where i can find information on how to make the font load before the animation?

bodymovin commented 1 year ago

@gfxargentina can you share a link to check it out?

gfxargentina commented 1 year ago

hi @bodymovin sorry forthe late response, here is the link to the After Effects Project File: https://drive.google.com/file/d/1h8zmNTWTJDNSxPtQ7f0ttH5sQL-kgGeU/view?usp=share_link , also i invited you to my repo, in the repo the file [name].js, is where the json is show, the file controller is where the json is created, please let me know if you need anything else.

bodymovin commented 1 year ago

@gfxargentina do you have a url where this is deployed?

gfxargentina commented 1 year ago

@bodymovin yes, here https://tarjetas-animadas.vercel.app/

bodymovin commented 1 year ago

@gfxargentina can you share a link directly to the animation or details of how to get to it?

gfxargentina commented 1 year ago

@bodymovin, yes here: https://tarjetas-animadas.vercel.app/video/url?preview=https://aws-tarjetas.s3.amazonaws.com/djluischilo.json

bodymovin commented 1 year ago

@gfxargentina it looks like the url has a tilde that is preventing the font to be preloaded correctly. If you check the network on the chrome dev tools you'll notice it is not getting loaded

gfxargentina commented 1 year ago

@bodymovin yes you are right, i don´t see that tilde, i delete the tilde, check network, but still don´t work

bodymovin commented 1 year ago

@gfxargentina this is probably related to the font not being loaded when the animation starts. Lottie tries to detect that and wait for the font to be loaded. I think that if you remove the "cursive" option from the css selector, it might fix it.

If that doesn't work, another option is to load an html element with the css class applied to it so the font loads before the animation. As a test, can you try adding an html element with the classapplied and delay the loading of the animation for 1 second?

gfxargentina commented 1 year ago

@bodymovin problem solved, i load the lottie player in a div with the classname of the font, and now work, you can now close this issue, thank you very much for your help

Nobunaji commented 1 year ago

@bodymovin @gfxargentina Hi, sorry for the ping but you guys haven't been here for a while, I have the same problem and i followed what you guys wrote. Applying the font to the div using font-family does work but only after I reload the page.

Any idea on how to fix this ?

animation_text.zip

bodymovin commented 1 year ago

@Nobunaji I just tested the html you shared in Chrome and I see the font correctly. Is it working for you when you run it locally?