Skip to content

Commit b551f84

Browse files
josephperrottIgorMinar
authored andcommitted
feat(platform-browser): add token marking which the type of animation module nearest in the injector tree (#23075)
PR Close #23075
1 parent f958293 commit b551f84

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

packages/core/test/animation/animation_integration_spec.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import {AUTO_STYLE, AnimationEvent, AnimationOptions, AnimationPlayer, NoopAnimationPlayer, animate, animateChild, group, keyframes, query, state, style, transition, trigger, ɵPRE_STYLE as PRE_STYLE} from '@angular/animations';
99
import {AnimationDriver, ɵAnimationEngine, ɵNoopAnimationDriver as NoopAnimationDriver} from '@angular/animations/browser';
1010
import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing';
11-
import {ChangeDetectorRef, Component, HostBinding, HostListener, RendererFactory2, ViewChild} from '@angular/core';
11+
import {ChangeDetectorRef, Component, HostBinding, HostListener, Inject, RendererFactory2, ViewChild} from '@angular/core';
1212
import {ɵDomRendererFactory2} from '@angular/platform-browser';
13-
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
13+
import {ANIMATION_MODULE_TYPE, BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
1414
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
1515

1616
import {TestBed, fakeAsync, flushMicrotasks} from '../../testing';
@@ -37,6 +37,34 @@ const DEFAULT_COMPONENT_ID = '1';
3737
});
3838
});
3939

40+
describe('animation modules', function() {
41+
it('should hint at BrowserAnimationsModule being used', () => {
42+
TestBed.resetTestingModule();
43+
TestBed.configureTestingModule(
44+
{declarations: [SharedAnimationCmp], imports: [BrowserAnimationsModule]});
45+
46+
const fixture = TestBed.createComponent(SharedAnimationCmp);
47+
const cmp = fixture.componentInstance;
48+
expect(cmp.animationType).toEqual('BrowserAnimations');
49+
});
50+
51+
it('should hint at NoopAnimationsModule being used', () => {
52+
TestBed.resetTestingModule();
53+
TestBed.configureTestingModule(
54+
{declarations: [SharedAnimationCmp], imports: [NoopAnimationsModule]});
55+
56+
const fixture = TestBed.createComponent(SharedAnimationCmp);
57+
const cmp = fixture.componentInstance;
58+
expect(cmp.animationType).toEqual('NoopAnimations');
59+
});
60+
});
61+
62+
@Component({template: '<p>template text</p>'})
63+
class SharedAnimationCmp {
64+
constructor(@Inject(ANIMATION_MODULE_TYPE) public animationType: 'NoopAnimations'|
65+
'BrowserAnimations') {}
66+
}
67+
4068
describe('fakeAsync testing', () => {
4169
it('should only require one flushMicrotasks call to kick off animation callbacks',
4270
fakeAsync(() => {

packages/platform-browser/animations/src/animations.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
*/
1414
export {BrowserAnimationsModule, NoopAnimationsModule} from './module';
1515

16+
export {ANIMATION_MODULE_TYPE} from './providers';
17+
1618
export * from './private_export';

packages/platform-browser/animations/src/providers.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {AnimationBuilder} from '@angular/animations';
1010
import {AnimationDriver, ɵAnimationEngine as AnimationEngine, ɵAnimationStyleNormalizer as AnimationStyleNormalizer, ɵCssKeyframesDriver as CssKeyframesDriver, ɵNoopAnimationDriver as NoopAnimationDriver, ɵWebAnimationsDriver as WebAnimationsDriver, ɵWebAnimationsStyleNormalizer as WebAnimationsStyleNormalizer, ɵsupportsWebAnimations as supportsWebAnimations} from '@angular/animations/browser';
11-
import {Injectable, NgZone, Provider, RendererFactory2} from '@angular/core';
11+
import {Injectable, InjectionToken, NgZone, Provider, RendererFactory2} from '@angular/core';
1212
import {ɵDomRendererFactory2 as DomRendererFactory2} from '@angular/platform-browser';
1313

1414
import {BrowserAnimationBuilder} from './animation_builder';
@@ -34,6 +34,12 @@ export function instantiateRendererFactory(
3434
return new AnimationRendererFactory(renderer, engine, zone);
3535
}
3636

37+
/**
38+
* @experimental Animation support is experimental.
39+
*/
40+
export const ANIMATION_MODULE_TYPE =
41+
new InjectionToken<'NoopAnimations'|'BrowserAnimations'>('AnimationModuleType');
42+
3743
const SHARED_ANIMATION_PROVIDERS: Provider[] = [
3844
{provide: AnimationBuilder, useClass: BrowserAnimationBuilder},
3945
{provide: AnimationStyleNormalizer, useFactory: instantiateDefaultStyleNormalizer},
@@ -50,12 +56,14 @@ const SHARED_ANIMATION_PROVIDERS: Provider[] = [
5056
*/
5157
export const BROWSER_ANIMATIONS_PROVIDERS: Provider[] = [
5258
{provide: AnimationDriver, useFactory: instantiateSupportedAnimationDriver},
53-
...SHARED_ANIMATION_PROVIDERS
59+
{provide: ANIMATION_MODULE_TYPE, useValue: 'BrowserAnimations'}, ...SHARED_ANIMATION_PROVIDERS
5460
];
5561

5662
/**
5763
* Separate providers from the actual module so that we can do a local modification in Google3 to
5864
* include them in the BrowserTestingModule.
5965
*/
60-
export const BROWSER_NOOP_ANIMATIONS_PROVIDERS: Provider[] =
61-
[{provide: AnimationDriver, useClass: NoopAnimationDriver}, ...SHARED_ANIMATION_PROVIDERS];
66+
export const BROWSER_NOOP_ANIMATIONS_PROVIDERS: Provider[] = [
67+
{provide: AnimationDriver, useClass: NoopAnimationDriver},
68+
{provide: ANIMATION_MODULE_TYPE, useValue: 'NoopAnimations'}, ...SHARED_ANIMATION_PROVIDERS
69+
];

tools/public_api_guard/platform-browser/animations.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/** @experimental */
2+
export declare const ANIMATION_MODULE_TYPE: InjectionToken<"NoopAnimations" | "BrowserAnimations">;
3+
14
/** @experimental */
25
export declare class BrowserAnimationsModule {
36
}

0 commit comments

Comments
 (0)