feat(platform-browser): add token marking which the type of animation module nearest in the injector tree (#23075)
PR Close #23075
This commit is contained in:
parent
f958293205
commit
b551f844e4
|
@ -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 {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 {AnimationDriver, ɵAnimationEngine, ɵNoopAnimationDriver as NoopAnimationDriver} from '@angular/animations/browser';
|
||||||
import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing';
|
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 {ɵ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 {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
|
|
||||||
import {TestBed, fakeAsync, flushMicrotasks} from '../../testing';
|
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: '<p>template text</p>'})
|
||||||
|
class SharedAnimationCmp {
|
||||||
|
constructor(@Inject(ANIMATION_MODULE_TYPE) public animationType: 'NoopAnimations'|
|
||||||
|
'BrowserAnimations') {}
|
||||||
|
}
|
||||||
|
|
||||||
describe('fakeAsync testing', () => {
|
describe('fakeAsync testing', () => {
|
||||||
it('should only require one flushMicrotasks call to kick off animation callbacks',
|
it('should only require one flushMicrotasks call to kick off animation callbacks',
|
||||||
fakeAsync(() => {
|
fakeAsync(() => {
|
||||||
|
|
|
@ -13,4 +13,6 @@
|
||||||
*/
|
*/
|
||||||
export {BrowserAnimationsModule, NoopAnimationsModule} from './module';
|
export {BrowserAnimationsModule, NoopAnimationsModule} from './module';
|
||||||
|
|
||||||
|
export {ANIMATION_MODULE_TYPE} from './providers';
|
||||||
|
|
||||||
export * from './private_export';
|
export * from './private_export';
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {AnimationBuilder} from '@angular/animations';
|
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 {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 {ɵDomRendererFactory2 as DomRendererFactory2} from '@angular/platform-browser';
|
||||||
|
|
||||||
import {BrowserAnimationBuilder} from './animation_builder';
|
import {BrowserAnimationBuilder} from './animation_builder';
|
||||||
|
@ -34,6 +34,12 @@ export function instantiateRendererFactory(
|
||||||
return new AnimationRendererFactory(renderer, engine, zone);
|
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[] = [
|
const SHARED_ANIMATION_PROVIDERS: Provider[] = [
|
||||||
{provide: AnimationBuilder, useClass: BrowserAnimationBuilder},
|
{provide: AnimationBuilder, useClass: BrowserAnimationBuilder},
|
||||||
{provide: AnimationStyleNormalizer, useFactory: instantiateDefaultStyleNormalizer},
|
{provide: AnimationStyleNormalizer, useFactory: instantiateDefaultStyleNormalizer},
|
||||||
|
@ -50,12 +56,14 @@ const SHARED_ANIMATION_PROVIDERS: Provider[] = [
|
||||||
*/
|
*/
|
||||||
export const BROWSER_ANIMATIONS_PROVIDERS: Provider[] = [
|
export const BROWSER_ANIMATIONS_PROVIDERS: Provider[] = [
|
||||||
{provide: AnimationDriver, useFactory: instantiateSupportedAnimationDriver},
|
{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
|
* Separate providers from the actual module so that we can do a local modification in Google3 to
|
||||||
* include them in the BrowserTestingModule.
|
* include them in the BrowserTestingModule.
|
||||||
*/
|
*/
|
||||||
export const BROWSER_NOOP_ANIMATIONS_PROVIDERS: Provider[] =
|
export const BROWSER_NOOP_ANIMATIONS_PROVIDERS: Provider[] = [
|
||||||
[{provide: AnimationDriver, useClass: NoopAnimationDriver}, ...SHARED_ANIMATION_PROVIDERS];
|
{provide: AnimationDriver, useClass: NoopAnimationDriver},
|
||||||
|
{provide: ANIMATION_MODULE_TYPE, useValue: 'NoopAnimations'}, ...SHARED_ANIMATION_PROVIDERS
|
||||||
|
];
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
/** @experimental */
|
||||||
|
export declare const ANIMATION_MODULE_TYPE: InjectionToken<"NoopAnimations" | "BrowserAnimations">;
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class BrowserAnimationsModule {
|
export declare class BrowserAnimationsModule {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue