Skip to content

refactor: export component animations for reuse #8971

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

Merged
merged 1 commit into from
Jan 4, 2018

Conversation

crisbeto
Copy link
Member

Exports all of the component animations so they can be reused by consumers.

Fixes #8904.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 13, 2017
@josephperrott
Copy link
Member

If we are exporting them all publically perhaps we should "namespace" them? We could put all of the definitions inside of respective objects for animations. I worry about polluting the exported namespace.

For example:

export const ExpansionPanelAnimations = {
  indicatorRotate: AnimationTriggerMetadata = trigger('indicatorRotate', [
    state('collapsed', style({transform: 'rotate(0deg)'})),
    state('expanded', style({transform: 'rotate(180deg)'})),
    transition('expanded <=> collapsed',
               animate(EXPANSION_PANEL_ANIMATION_TIMING)),
  ]),
  expansionHeaderHeight: AnimationTriggerMetadata = trigger('expansionHeight', [
    state('collapsed', style({
      height: '{{collapsedHeight}}',
    }), {
      params: {collapsedHeight: '48px'},
    }),
    state('expanded', style({
      height: '{{expandedHeight}}'
    }), {
      params: {expandedHeight: '64px'}
    }),
    transition('expanded <=> collapsed', 
               animate(EXPANSION_PANEL_ANIMATION_TIMING)),
  ]),
  bodyExpansion: AnimationTriggerMetadata = trigger('bodyExpansion', [
    state('collapsed', style({height: '0px', visibility: 'hidden'})),
    state('expanded', style({height: '*', visibility: 'visible'})),
    transition('expanded <=> collapsed', 
               animate(EXPANSION_PANEL_ANIMATION_TIMING)),
  ])
}

@crisbeto
Copy link
Member Author

crisbeto commented Dec 13, 2017

Good point @josephperrott, I was hoping that this would come up during the review since I'm not a fan of just exporting them as plain variables either. Switching them over to namespaces.

@crisbeto crisbeto force-pushed the 8904/animation-exports branch from 50258cf to c7d715b Compare December 13, 2017 20:53
@crisbeto crisbeto requested a review from kara as a code owner December 13, 2017 20:53
/**
* Animations used by MatDialog.
*/
export namespace MatDialogAnimations {
Copy link
Member

Choose a reason for hiding this comment

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

We can't use typescript namespaces; they're forbidden inside google (has to do with interop with Closure-style javascript)

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case what would be the proper way to namespace them? Should we have a MatDialogAnimations class with static properties or just an object with some properties on it? The static class has the advantage of allowing us to make the properties readonly.

Copy link
Member

Choose a reason for hiding this comment

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

I would just do an object that we can use typescript to make immutable

@crisbeto crisbeto force-pushed the 8904/animation-exports branch from c7d715b to 0752958 Compare December 16, 2017 11:30
@crisbeto
Copy link
Member Author

Refactored it based on our discussion @jelbourn. Note that I'm not a fan of having to add the typings to all of the constants, but it seems like the simplest way of ensuring that the properties are immutable. Initially I was going for something like {readonly [key: string]: AnimationTriggerMetadata}, but that really only prevents people from adding new keys, it doesn't break if they try to override the existing ones.

crisbeto added a commit to crisbeto/material2 that referenced this pull request Dec 16, 2017
* Enables a tslint rule that will prevent us from using namespaces. Based on the discussion in angular#8971.
* Bumps to the latest stylelint version.
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

} = {
/**
* Animation that slides the dialog in and out of view and fades the opacity.
*/
Copy link
Member

Choose a reason for hiding this comment

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

nit: can condense these comments to a single line

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Dec 18, 2017
Exports all of the component animations so they can be reused by consumers.

Fixes angular#8904.
@crisbeto crisbeto force-pushed the 8904/animation-exports branch from 0752958 to 66ee1cf Compare December 18, 2017 18:41
@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Dec 18, 2017
crisbeto added a commit to crisbeto/material2 that referenced this pull request Dec 20, 2017
* Enables a tslint rule that will prevent us from using namespaces. Based on the discussion in angular#8971.
* Bumps to the latest stylelint version.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Dec 21, 2017
* Enables a tslint rule that will prevent us from using namespaces. Based on the discussion in angular#8971.
* Bumps to the latest stylelint version.
@jelbourn jelbourn merged commit f826805 into angular:master Jan 4, 2018
@jelbourn jelbourn added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Jan 8, 2018
@jelbourn
Copy link
Member

jelbourn commented Jan 8, 2018

Changing this to minor release since it adds new APIs

tinayuangao pushed a commit that referenced this pull request Jan 10, 2018
Exports all of the component animations so they can be reused by consumers.

Fixes #8904.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Animations should be exported for re-use
4 participants