1
1
import { AnimationPlayer } from "@angular/core" ;
2
2
import { AnimationKeyframe } from "./private_import_core" ;
3
- import { KeyframeAnimation , KeyframeAnimationInfo , KeyframeInfo , KeyframeDeclaration } from 'ui/animation/keyframe-animation' ;
3
+ import {
4
+ KeyframeAnimation ,
5
+ KeyframeAnimationInfo ,
6
+ KeyframeInfo ,
7
+ KeyframeDeclaration
8
+ } from "ui/animation/keyframe-animation" ;
4
9
import { View } from "ui/core/view" ;
5
10
import { AnimationCurve } from "ui/enums" ;
6
- import { ValueSource } from ' ui/core/dependency-observable' ;
11
+ import { ValueSource } from " ui/core/dependency-observable" ;
7
12
import { isString } from "utils/types" ;
8
- import * as styleProperty from ' ui/styling/style-property' ;
13
+ import * as styleProperty from " ui/styling/style-property" ;
9
14
10
15
export class NativeScriptAnimationPlayer implements AnimationPlayer {
11
16
@@ -18,7 +23,13 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
18
23
private animation : KeyframeAnimation ;
19
24
private target : View ;
20
25
21
- constructor ( element : Node , keyframes : AnimationKeyframe [ ] , duration : number , delay : number , easing : string ) {
26
+ constructor (
27
+ element : Node ,
28
+ keyframes : AnimationKeyframe [ ] ,
29
+ duration : number ,
30
+ delay : number ,
31
+ easing : string
32
+ ) {
22
33
23
34
this . parentPlayer = null ;
24
35
@@ -36,7 +47,9 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
36
47
keyframeAnimationInfo . duration = duration ;
37
48
keyframeAnimationInfo . delay = delay ;
38
49
keyframeAnimationInfo . iterations = 1 ;
39
- keyframeAnimationInfo . curve = easing ? NativeScriptAnimationPlayer . animationTimingFunctionConverter ( easing ) : AnimationCurve . ease ;
50
+ keyframeAnimationInfo . curve = easing ?
51
+ NativeScriptAnimationPlayer . animationTimingFunctionConverter ( easing ) :
52
+ AnimationCurve . ease ;
40
53
keyframeAnimationInfo . keyframes = new Array < KeyframeInfo > ( ) ;
41
54
keyframeAnimationInfo . isForwards = true ;
42
55
@@ -53,16 +66,16 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
53
66
value = property . valueConverter ( < string > value ) ;
54
67
}
55
68
keyframeInfo . declarations . push ( { property : property . name , value : value } ) ;
56
- }
57
- else if ( typeof value === "string" && substyle === "transform" ) {
69
+ } else if ( typeof value === "string" && substyle === "transform" ) {
58
70
NativeScriptAnimationPlayer . parseTransform ( < string > value , keyframeInfo ) ;
59
71
}
60
72
}
61
73
}
62
74
keyframeAnimationInfo . keyframes . push ( keyframeInfo ) ;
63
75
}
64
76
65
- this . animation = KeyframeAnimation . keyframeAnimationFromInfo ( keyframeAnimationInfo , ValueSource . VisualState ) ;
77
+ this . animation = KeyframeAnimation . keyframeAnimationFromInfo (
78
+ keyframeAnimationInfo , ValueSource . VisualState ) ;
66
79
}
67
80
68
81
init ( ) : void {
@@ -98,7 +111,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
98
111
this . _onStart ( ) ;
99
112
this . animation . play ( this . target )
100
113
. then ( ( ) => { this . _onFinish ( ) ; } )
101
- . catch ( ( e ) => { } ) ;
114
+ . catch ( ( _e ) => { } ) ;
102
115
}
103
116
}
104
117
@@ -126,7 +139,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
126
139
this . _onFinish ( ) ;
127
140
}
128
141
129
- setPosition ( p : any ) : void {
142
+ setPosition ( _p : any ) : void {
130
143
throw new Error ( "AnimationPlayer.setPosition method is not supported!" ) ;
131
144
}
132
145
@@ -159,8 +172,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
159
172
NativeScriptAnimationPlayer . bezieArgumentConverter ( bezierArr [ 1 ] ) ,
160
173
NativeScriptAnimationPlayer . bezieArgumentConverter ( bezierArr [ 2 ] ) ,
161
174
NativeScriptAnimationPlayer . bezieArgumentConverter ( bezierArr [ 3 ] ) ) ;
162
- }
163
- else {
175
+ } else {
164
176
throw new Error ( "Invalid value for animation: " + value ) ;
165
177
}
166
178
}
@@ -178,16 +190,14 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
178
190
let operations = { } ;
179
191
operations [ value ] = value ;
180
192
return operations ;
181
- }
182
- else if ( isString ( value ) ) {
193
+ } else if ( isString ( value ) ) {
183
194
let operations = { } ;
184
195
let operator = "" ;
185
196
let pos = 0 ;
186
197
while ( pos < value . length ) {
187
198
if ( value [ pos ] === " " || value [ pos ] === "," ) {
188
199
pos ++ ;
189
- }
190
- else if ( value [ pos ] === "(" ) {
200
+ } else if ( value [ pos ] === "(" ) {
191
201
let start = pos + 1 ;
192
202
while ( pos < value . length && value [ pos ] !== ")" ) {
193
203
pos ++ ;
@@ -196,14 +206,12 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
196
206
operations [ operator ] = operand . trim ( ) ;
197
207
operator = "" ;
198
208
pos ++ ;
199
- }
200
- else {
209
+ } else {
201
210
operator += value [ pos ++ ] ;
202
211
}
203
212
}
204
213
return operations ;
205
- }
206
- else {
214
+ } else {
207
215
return undefined ;
208
216
}
209
217
}
@@ -215,29 +223,50 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
215
223
for ( let transform in newTransform ) {
216
224
switch ( transform ) {
217
225
case "scaleX" :
218
- animationInfo . declarations . push ( { property : "scale" , value : { x : parseFloat ( newTransform [ transform ] ) , y : 1 } } ) ;
226
+ animationInfo . declarations . push ( {
227
+ property : "scale" ,
228
+ value : { x : parseFloat ( newTransform [ transform ] ) , y : 1 }
229
+ } ) ;
219
230
break ;
220
231
case "scaleY" :
221
- animationInfo . declarations . push ( { property : "scale" , value : { x : 1 , y : parseFloat ( newTransform [ transform ] ) } } ) ;
232
+ animationInfo . declarations . push ( {
233
+ property : "scale" ,
234
+ value : { x : 1 , y : parseFloat ( newTransform [ transform ] ) }
235
+ } ) ;
222
236
break ;
223
237
case "scale" :
224
238
case "scale3d" :
225
239
values = newTransform [ transform ] . split ( "," ) ;
226
240
if ( values . length === 2 || values . length === 3 ) {
227
- animationInfo . declarations . push ( { property : "scale" , value : { x : parseFloat ( values [ 0 ] ) , y : parseFloat ( values [ 1 ] ) } } ) ;
241
+ animationInfo . declarations . push ( {
242
+ property : "scale" ,
243
+ value : { x : parseFloat ( values [ 0 ] ) , y : parseFloat ( values [ 1 ] ) }
244
+ } ) ;
228
245
}
229
246
break ;
230
247
case "translateX" :
231
- animationInfo . declarations . push ( { property : "translate" , value : { x : parseFloat ( newTransform [ transform ] ) , y : 0 } } ) ;
248
+ animationInfo . declarations . push ( {
249
+ property : "translate" ,
250
+ value : { x : parseFloat ( newTransform [ transform ] ) , y : 0 }
251
+ } ) ;
232
252
break ;
233
253
case "translateY" :
234
- animationInfo . declarations . push ( { property : "translate" , value : { x : 0 , y : parseFloat ( newTransform [ transform ] ) } } ) ;
254
+ animationInfo . declarations . push ( {
255
+ property : "translate" ,
256
+ value : { x : 0 , y : parseFloat ( newTransform [ transform ] ) }
257
+ } ) ;
235
258
break ;
236
259
case "translate" :
237
260
case "translate3d" :
238
261
values = newTransform [ transform ] . split ( "," ) ;
239
262
if ( values . length === 2 || values . length === 3 ) {
240
- animationInfo . declarations . push ( { property : "translate" , value : { x : parseFloat ( values [ 0 ] ) , y : parseFloat ( values [ 1 ] ) } } ) ;
263
+ animationInfo . declarations . push ( {
264
+ property : "translate" ,
265
+ value : {
266
+ x : parseFloat ( values [ 0 ] ) ,
267
+ y : parseFloat ( values [ 1 ] )
268
+ }
269
+ } ) ;
241
270
}
242
271
break ;
243
272
case "rotate" :
@@ -250,9 +279,12 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
250
279
break ;
251
280
case "none" :
252
281
animationInfo . declarations . push ( { property : "scale" , value : { x : 1 , y : 1 } } ) ;
253
- animationInfo . declarations . push ( { property : "translate" , value : { x : 0 , y : 0 } } ) ;
282
+ animationInfo . declarations . push (
283
+ { property : "translate" , value : { x : 0 , y : 0 } } ) ;
254
284
animationInfo . declarations . push ( { property : "rotate" , value : 0 } ) ;
255
285
break ;
286
+ default :
287
+ throw new Error ( "Unsupported transform: " + transform ) ;
256
288
}
257
289
}
258
290
return array ;
0 commit comments