Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari animations problems in an angular app #914

Closed
dkaimoti opened this issue Mar 15, 2018 · 7 comments
Closed

Safari animations problems in an angular app #914

dkaimoti opened this issue Mar 15, 2018 · 7 comments

Comments

@dkaimoti
Copy link

Hi,

I'm facing problems with lottie, angular and Safari.
I have an angular (angular 5) app with many components (routes). On each component there is a Lottie animation.
The initial route with animations works, slowly, but works. When i go to another route, the animation works but without the svgs, i can see the masks transitions of the animations, but it is like the SVGs can't be loaded.

It happens only on Safari. Chrome, firefox and even on the Internet Explorer works well.

Someone faced something like this?
Thanks in advance!

@bodymovin
Copy link
Collaborator

It might be related to the "base" tag that angular uses.
If you have it defined you should set the base path from where svg fragments will target each other.
when the library is loaded, call lottie.setLocationHref(path)
passing the base path.
Take a look at the discussion here.
#382

@dkaimoti
Copy link
Author

Thanks! I understand the problem and solved using angular's HashLocationStrategy.

@simeyla
Copy link

simeyla commented Jun 13, 2018

Wow I spent ALL day on this.

Can you expand the explanation in the docs and samples. This is very important, and extremely hard to debug.

Also what's written above is confusing and implies you pass in your base path - which in my Angular app is actually "/" so initially people may think this doesn't even apply to them if they are using a subdirectory. Also not all developers may be familiar with what an animation mask/matte is - especially if they're just trying to incorporate a file someone else gave them - so including details about that would be valuable.

Anyway this fixed it for me for Angular 6 app:

ngOnInit() {
       const settings = {
           container: this.lavContainer.nativeElement
       };

       lottie.setLocationHref(document.location.href);
       this.anim = lottie.loadAnimation({...this.options, ...settings});
 }

Hate to see someone else waste as much time as I did - it's very puzzling what is happening until you know - and many opportunities to make a wrong assumption.

@dkaimoti
Copy link
Author

dkaimoti commented Jun 14, 2018

@simeyla,

When we use HashLocationStrategy, a "#" will be added after your domain.
Ex: http://localhost:4200 will be http://localhost:4200/#/

The server will consider only http://localhost:4200, everthing after "#" will be ignored, so the lottie animation will always look for the SVGs considering the base url.

For use this, in your app.module.ts import and add to providers:

import { LocationStrategy, HashLocationStrategy } from '@angular/common'
...
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}]
...

More explanation:
https://angular.io/api/common/HashLocationStrategy

Hope it helps.

@Jokero
Copy link

Jokero commented Jul 1, 2018

This is very unexpected... SVG animation, angular, <base> tag, safari. It's crazy 😄
Using location.href helped.

@emmanuel-cbqa
Copy link

emmanuel-cbqa commented Jan 4, 2019

I have this in my component.html

<lottie-animation-view [options]="_options" ></lottie-animation-view>

this in my component.ts

public _options: Object;


  constructor() { 
    this._options = {
      path: '../../../../assets/images/xoat-animation.json',
      renderer: 'svg',
      autoplay: true,
      loop: true
  };
  }

Works fine in Chrome and Firefox but does not work for Safari.

@SobolevskyDmitry
Copy link

   lottie.setLocationHref(document.location.href);

@bodymovin Could add this hack to Lottie Web FAQ? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants