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

feat(animations): refactor ngbTransition #3793

Merged
merged 1 commit into from
Jun 29, 2020

Conversation

fbasso
Copy link
Member

@fbasso fbasso commented Jun 29, 2020

This is a refactor of ngbTransition to fix an issue around the transition detection.

The main problem comes from the order startFn is run and the transition computed style.

It's easier to explain the issue with the collapse widget:

What Bootstrap do :

  • The transition is set on the collapsing class,
  • When reduce motion is activated, Bootstrap set this transition to none.

Before this PR :

  • We get the transition value for mthe element computed style,
  • if this transition is none, we consider that there is no animation and we run the startFn an endFn synchronously.

This is wrong, as it's the startFn purpose is to change collapse to collapsing, we can't compute the transition property of collapsing before running it.

What this PR do:

  • Always run startFn
  • If no animation (via the options or transition none), run endFn synchronously

At the same time, for the collpase widget:

  • The shown and hidden were missing to well managed the transitions: there are emitted at the transition end, unlike the collapseChange.
  • The tests have been refactor to well reflect the asynchronous/synchronous stuff depending on the reduce motion activation

The other transitions tests need to be refactor as well (not done yet).

Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @fbasso!

LGTM, just left two comments (see below in code):

  • could we use the binding for the initial 'collapse' class
  • add a comment why we need reflow()
  • (+ a bonus one) the build is failing

Cheers,
Max

constructor(private _element: ElementRef, config: NgbCollapseConfig) { this.animation = config.animation; }

ngOnInit() {
const {classList} = this._element.nativeElement;
classList.add('collapse');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one we should add via the 'class': 'collapse' binding as before, what's the point doing it imperatively, if we could do this declaratively with Angular...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not merged what is done by binding and what is done by the transition engine.

As far as remember, the collapse class was added back just after starting the transition (direction: show), because collapsed is true. The result is there is collapsingand collapseat the same time in the dom.

I will check, but I thing the tests in this PR prevent this, so it should fail.

(startFn(element, context) || noopFn)();
return of(undefined);
}
reflow(element);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain why in a comment? because we'll never remember this later.

Copy link
Member

@benouat benouat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maxokorokov maxokorokov merged commit 99e7e8c into ng-bootstrap:animations Jun 29, 2020
@fbasso
Copy link
Member Author

fbasso commented Jun 30, 2020

Thanks !

@fbasso fbasso mentioned this pull request Jul 1, 2020
@fbasso fbasso deleted the animation-engine branch August 4, 2020 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants