diff --git a/packages/core/test/animation/animation_integration_spec.ts b/packages/core/test/animation/animation_integration_spec.ts index a02fdd5202..cc8b9556f1 100644 --- a/packages/core/test/animation/animation_integration_spec.ts +++ b/packages/core/test/animation/animation_integration_spec.ts @@ -8,9 +8,9 @@ import {AUTO_STYLE, AnimationEvent, AnimationOptions, AnimationPlayer, NoopAnimationPlayer, animate, animateChild, group, keyframes, query, state, style, transition, trigger, ɵPRE_STYLE as PRE_STYLE} from '@angular/animations'; import {AnimationDriver, ɵAnimationEngine, ɵNoopAnimationDriver as NoopAnimationDriver} from '@angular/animations/browser'; import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing'; -import {ChangeDetectorRef, Component, HostBinding, HostListener, RendererFactory2, ViewChild} from '@angular/core'; +import {ChangeDetectorRef, Component, HostBinding, HostListener, Inject, RendererFactory2, ViewChild} from '@angular/core'; import {ɵDomRendererFactory2} from '@angular/platform-browser'; -import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; +import {ANIMATION_MODULE_TYPE, BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {TestBed, fakeAsync, flushMicrotasks} from '../../testing'; @@ -37,6 +37,34 @@ const DEFAULT_COMPONENT_ID = '1'; }); }); + describe('animation modules', function() { + it('should hint at BrowserAnimationsModule being used', () => { + TestBed.resetTestingModule(); + TestBed.configureTestingModule( + {declarations: [SharedAnimationCmp], imports: [BrowserAnimationsModule]}); + + const fixture = TestBed.createComponent(SharedAnimationCmp); + const cmp = fixture.componentInstance; + expect(cmp.animationType).toEqual('BrowserAnimations'); + }); + + it('should hint at NoopAnimationsModule being used', () => { + TestBed.resetTestingModule(); + TestBed.configureTestingModule( + {declarations: [SharedAnimationCmp], imports: [NoopAnimationsModule]}); + + const fixture = TestBed.createComponent(SharedAnimationCmp); + const cmp = fixture.componentInstance; + expect(cmp.animationType).toEqual('NoopAnimations'); + }); + }); + + @Component({template: '
template text
'}) + class SharedAnimationCmp { + constructor(@Inject(ANIMATION_MODULE_TYPE) public animationType: 'NoopAnimations'| + 'BrowserAnimations') {} + } + describe('fakeAsync testing', () => { it('should only require one flushMicrotasks call to kick off animation callbacks', fakeAsync(() => { diff --git a/packages/platform-browser/animations/src/animations.ts b/packages/platform-browser/animations/src/animations.ts index 182f7bca81..0d5692ad7b 100644 --- a/packages/platform-browser/animations/src/animations.ts +++ b/packages/platform-browser/animations/src/animations.ts @@ -13,4 +13,6 @@ */ export {BrowserAnimationsModule, NoopAnimationsModule} from './module'; +export {ANIMATION_MODULE_TYPE} from './providers'; + export * from './private_export'; diff --git a/packages/platform-browser/animations/src/providers.ts b/packages/platform-browser/animations/src/providers.ts index b23f57c7a7..fb3f995e33 100644 --- a/packages/platform-browser/animations/src/providers.ts +++ b/packages/platform-browser/animations/src/providers.ts @@ -8,7 +8,7 @@ import {AnimationBuilder} from '@angular/animations'; 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'; -import {Injectable, NgZone, Provider, RendererFactory2} from '@angular/core'; +import {Injectable, InjectionToken, NgZone, Provider, RendererFactory2} from '@angular/core'; import {ɵDomRendererFactory2 as DomRendererFactory2} from '@angular/platform-browser'; import {BrowserAnimationBuilder} from './animation_builder'; @@ -34,6 +34,12 @@ export function instantiateRendererFactory( return new AnimationRendererFactory(renderer, engine, zone); } +/** + * @experimental Animation support is experimental. + */ +export const ANIMATION_MODULE_TYPE = + new InjectionToken<'NoopAnimations'|'BrowserAnimations'>('AnimationModuleType'); + const SHARED_ANIMATION_PROVIDERS: Provider[] = [ {provide: AnimationBuilder, useClass: BrowserAnimationBuilder}, {provide: AnimationStyleNormalizer, useFactory: instantiateDefaultStyleNormalizer}, @@ -50,12 +56,14 @@ const SHARED_ANIMATION_PROVIDERS: Provider[] = [ */ export const BROWSER_ANIMATIONS_PROVIDERS: Provider[] = [ {provide: AnimationDriver, useFactory: instantiateSupportedAnimationDriver}, - ...SHARED_ANIMATION_PROVIDERS + {provide: ANIMATION_MODULE_TYPE, useValue: 'BrowserAnimations'}, ...SHARED_ANIMATION_PROVIDERS ]; /** * Separate providers from the actual module so that we can do a local modification in Google3 to * include them in the BrowserTestingModule. */ -export const BROWSER_NOOP_ANIMATIONS_PROVIDERS: Provider[] = - [{provide: AnimationDriver, useClass: NoopAnimationDriver}, ...SHARED_ANIMATION_PROVIDERS]; +export const BROWSER_NOOP_ANIMATIONS_PROVIDERS: Provider[] = [ + {provide: AnimationDriver, useClass: NoopAnimationDriver}, + {provide: ANIMATION_MODULE_TYPE, useValue: 'NoopAnimations'}, ...SHARED_ANIMATION_PROVIDERS +]; diff --git a/tools/public_api_guard/platform-browser/animations.d.ts b/tools/public_api_guard/platform-browser/animations.d.ts index f9a80e456c..bd3ae195d5 100644 --- a/tools/public_api_guard/platform-browser/animations.d.ts +++ b/tools/public_api_guard/platform-browser/animations.d.ts @@ -1,3 +1,6 @@ +/** @experimental */ +export declare const ANIMATION_MODULE_TYPE: InjectionToken<"NoopAnimations" | "BrowserAnimations">; + /** @experimental */ export declare class BrowserAnimationsModule { }