Skip to content

Dynamically setting animation on ionNavView : possible ionic logic error #1148

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

Closed
peey opened this issue Apr 16, 2014 · 4 comments
Closed

Dynamically setting animation on ionNavView : possible ionic logic error #1148

peey opened this issue Apr 16, 2014 · 4 comments

Comments

@peey
Copy link

peey commented Apr 16, 2014

I'm using ionic beta 1. I was looking for methods to dynamically set the animation class on ionNavView directive (animation attribute is quite static), so I dived into ionic-angular.js and found that ionic tries to read navViewScope.$nextAnimation first, and if it isn't there, then it tries to read the animation attribute. So, I decided to try it, only to find that it was automatically being set to undefined soon after the page loads. I traced the error to this code in ionic-angular.js , which starts on line 1870 :

    getRenderer: function(navViewElement, navViewAttrs, navViewScope) {
      var service = this;
      var registerData;
      var doAnimation;

      // climb up the DOM and see which animation classname to use, if any
      var animationClass = angular.isDefined(navViewScope.$nextAnimation) ?
        navViewScope.$nextAnimation :
        getParentAnimationClass(navViewElement[0]);

      navViewScope.$nextAnimation = undefined;

      function getParentAnimationClass(el) {
        var className = '';
        while(!className && el) {
          className = el.getAttribute('animation');
          el = el.parentElement;
        }
        return className;
      }

      function setAnimationClass() {
        // add the animation CSS class we're gonna use to transition between views
        if (animationClass) {
          navViewElement[0].classList.add(animationClass);
        }

        if(registerData.navDirection === 'back') {
          // animate like we're moving backward
          navViewElement[0].classList.add('reverse');
        } else {
          // defaults to animate forward
          // make sure the reverse class isn't already added
          navViewElement[0].classList.remove('reverse');
        }
      }

It's the line 1880 (navViewScope.$nextAnimation = undefined;) that bothers me. It sets the $nextAnimation variable in the scope to undefined, which affects the future calls to getRenderer function.

I don't see what purpose that line serves, and I think it should be removed. I tried to run my application with that line commented out and it worked as expected.

@ajoslin
Copy link
Contributor

ajoslin commented Apr 29, 2014

This isn't the way to do it, $nextAnimation is unused and deprecated.

You can do <ion-nav-view animation="{{myVariable}}">.

@martingg88
Copy link

The following doesn't work at all
"".

@peey
Copy link
Author

peey commented Aug 4, 2014

This issue is open at #1288 . follow it there @martingg88

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 6, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants