@@ -10,6 +10,8 @@ import {
10
10
11
11
import { View , Color } from "../core/view" ;
12
12
13
+ import { AnimationCurve } from "../enums" ;
14
+
13
15
// Types.
14
16
import { unsetValue } from "../core/properties" ;
15
17
import { Animation } from "./animation" ;
@@ -37,19 +39,19 @@ export class KeyframeDeclaration implements KeyframeDeclarationDefinition {
37
39
38
40
export class KeyframeInfo implements KeyframeInfoDefinition {
39
41
public duration : number ;
40
- public curve : any ;
41
42
public declarations : Array < KeyframeDeclaration > ;
43
+ public curve ?: any = AnimationCurve . ease ;
42
44
}
43
45
44
46
export class KeyframeAnimationInfo implements KeyframeAnimationInfoDefinition {
45
- public name : string = "" ;
46
- public duration : number = 0.3 ;
47
- public delay : number = 0 ;
48
- public iterations : number = 1 ;
49
- public curve : any = "ease" ;
50
- public isForwards : boolean = false ;
51
- public isReverse : boolean = false ;
52
47
public keyframes : Array < KeyframeInfo > ;
48
+ public name ?: string = "" ;
49
+ public duration ?: number = 0.3 ;
50
+ public delay ?: number = 0 ;
51
+ public iterations ?: number = 1 ;
52
+ public curve ?: any = "ease" ;
53
+ public isForwards ?: boolean = false ;
54
+ public isReverse ?: boolean = false ;
53
55
}
54
56
55
57
interface Keyframe {
@@ -76,17 +78,19 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
76
78
private _nativeAnimations : Array < Animation > ;
77
79
private _target : View ;
78
80
79
- public static keyframeAnimationFromInfo ( info : KeyframeAnimationInfo ) {
81
+ public static keyframeAnimationFromInfo ( info : KeyframeAnimationInfo )
82
+ : KeyframeAnimation {
83
+
84
+ const length = info . keyframes . length ;
80
85
let animations = new Array < Keyframe > ( ) ;
81
- let length = info . keyframes . length ;
82
86
let startDuration = 0 ;
87
+
83
88
if ( info . isReverse ) {
84
89
for ( let index = length - 1 ; index >= 0 ; index -- ) {
85
90
let keyframe = info . keyframes [ index ] ;
86
91
startDuration = KeyframeAnimation . parseKeyframe ( info , keyframe , animations , startDuration ) ;
87
92
}
88
- }
89
- else {
93
+ } else {
90
94
for ( let index = 0 ; index < length ; index ++ ) {
91
95
let keyframe = info . keyframes [ index ] ;
92
96
startDuration = KeyframeAnimation . parseKeyframe ( info , keyframe , animations , startDuration ) ;
@@ -100,17 +104,15 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
100
104
}
101
105
}
102
106
}
103
- for ( let index = 1 ; index < length ; index ++ ) {
104
- let a = animations [ index ] ;
105
- if ( a [ "curve" ] === undefined ) {
106
- a [ "curve" ] = info . curve ;
107
- }
108
- }
109
- let animation : KeyframeAnimation = new KeyframeAnimation ( ) ;
107
+
108
+ animations . map ( a => a [ "curve" ] ? a : Object . assign ( a , { curve : info . curve } ) ) ;
109
+
110
+ const animation : KeyframeAnimation = new KeyframeAnimation ( ) ;
110
111
animation . delay = info . delay ;
111
112
animation . iterations = info . iterations ;
112
113
animation . animations = animations ;
113
114
animation . _isForwards = info . isForwards ;
115
+
114
116
return animation ;
115
117
}
116
118
@@ -119,11 +121,11 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
119
121
for ( let declaration of keyframe . declarations ) {
120
122
animation [ declaration . property ] = declaration . value ;
121
123
}
124
+
122
125
let duration = keyframe . duration ;
123
126
if ( duration === 0 ) {
124
127
duration = 0.01 ;
125
- }
126
- else {
128
+ } else {
127
129
duration = ( info . duration * duration ) - startDuration ;
128
130
startDuration += duration ;
129
131
}
@@ -132,6 +134,7 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
132
134
animation . forceLayer = true ;
133
135
animation . valueSource = "keyframe" ;
134
136
animations . push ( animation ) ;
137
+
135
138
return startDuration ;
136
139
}
137
140
0 commit comments