-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathanimations.module.ts
63 lines (53 loc) · 2.32 KB
/
animations.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { NgModule, Injectable, NgZone, Provider, RendererFactory2, Optional, SkipSelf } from "@angular/core";
import { AnimationBuilder } from "@angular/animations";
import {
AnimationDriver,
ɵAnimationStyleNormalizer as AnimationStyleNormalizer,
ɵWebAnimationsStyleNormalizer as WebAnimationsStyleNormalizer,
ɵAnimationEngine as AnimationEngine,
} from "@angular/animations/browser";
import {
ɵAnimationRendererFactory as AnimationRendererFactory,
ɵBrowserAnimationBuilder as BrowserAnimationBuilder,
} from "@angular/platform-browser/animations";
import { NativeScriptModule } from "../nativescript.module";
import { NativeScriptRendererFactory } from "../renderer";
import { NativeScriptAnimationDriver } from "./animation-driver";
import { throwIfAlreadyLoaded } from "../common/utils";
@Injectable()
export class InjectableAnimationEngine extends AnimationEngine {
constructor(driver: AnimationDriver, normalizer: AnimationStyleNormalizer) {
super(driver, normalizer);
}
}
export function instantiateSupportedAnimationDriver() {
return new NativeScriptAnimationDriver();
}
export function instantiateRendererFactory(
renderer: NativeScriptRendererFactory, engine: AnimationEngine, zone: NgZone) {
return new AnimationRendererFactory(renderer, engine, zone);
}
export function instantiateDefaultStyleNormalizer() {
return new WebAnimationsStyleNormalizer();
}
export const NATIVESCRIPT_ANIMATIONS_PROVIDERS: Provider[] = [
{provide: AnimationDriver, useFactory: instantiateSupportedAnimationDriver},
{provide: AnimationBuilder, useClass: BrowserAnimationBuilder},
{provide: AnimationStyleNormalizer, useFactory: instantiateDefaultStyleNormalizer},
{provide: AnimationEngine, useClass: InjectableAnimationEngine},
{
provide: RendererFactory2,
useFactory: instantiateRendererFactory,
deps: [NativeScriptRendererFactory, AnimationEngine, NgZone]
}
];
@NgModule({
imports: [NativeScriptModule],
providers: NATIVESCRIPT_ANIMATIONS_PROVIDERS,
})
export class NativeScriptAnimationsModule {
constructor(@Optional() @SkipSelf() parentModule: NativeScriptAnimationsModule) {
// Prevents NativeScriptAnimationsModule from getting imported multiple times
throwIfAlreadyLoaded(parentModule, "NativeScriptAnimationsModule");
}
}