@@ -79,8 +79,8 @@ class AnimationDelegateImpl extends NSObject implements CAAnimationDelegate {
79
79
targetStyle [ setLocal ? widthProperty . name : widthProperty . keyframe ] = value ;
80
80
break ;
81
81
case Properties . scale :
82
- targetStyle [ setLocal ? scaleXProperty . name : scaleXProperty . keyframe ] = value . x === 0 ? 0.001 : value . x ;
83
- targetStyle [ setLocal ? scaleYProperty . name : scaleYProperty . keyframe ] = value . y === 0 ? 0.001 : value . y ;
82
+ targetStyle [ setLocal ? scaleXProperty . name : scaleXProperty . keyframe ] = value . x === 0 ? 1e-6 : value . x ;
83
+ targetStyle [ setLocal ? scaleYProperty . name : scaleYProperty . keyframe ] = value . y === 0 ? 1e-6 : value . y ;
84
84
break ;
85
85
case _transform :
86
86
if ( value [ Properties . translate ] !== undefined ) {
@@ -95,8 +95,8 @@ class AnimationDelegateImpl extends NSObject implements CAAnimationDelegate {
95
95
if ( value [ Properties . scale ] !== undefined ) {
96
96
const x = value [ Properties . scale ] . x ;
97
97
const y = value [ Properties . scale ] . y ;
98
- targetStyle [ setLocal ? scaleXProperty . name : scaleXProperty . keyframe ] = x === 0 ? 0.001 : x ;
99
- targetStyle [ setLocal ? scaleYProperty . name : scaleYProperty . keyframe ] = y === 0 ? 0.001 : y ;
98
+ targetStyle [ setLocal ? scaleXProperty . name : scaleXProperty . keyframe ] = x === 0 ? 1e-6 : x ;
99
+ targetStyle [ setLocal ? scaleYProperty . name : scaleYProperty . keyframe ] = y === 0 ? 1e-6 : y ;
100
100
}
101
101
break ;
102
102
}
@@ -309,7 +309,6 @@ export class Animation extends AnimationBase {
309
309
const parent = view . parent as View ;
310
310
311
311
let propertyNameToAnimate = animation . property ;
312
- let subPropertyNameToAnimate ;
313
312
let toValue = animation . value ;
314
313
let fromValue ;
315
314
if ( nativeView ) {
@@ -347,30 +346,9 @@ export class Animation extends AnimationBase {
347
346
style [ setLocal ? rotateYProperty . name : rotateYProperty . keyframe ] = value . y ;
348
347
} ;
349
348
350
- propertyNameToAnimate = 'transform.rotation' ;
351
- subPropertyNameToAnimate = [ 'x' , 'y' , 'z' ] ;
352
- fromValue = {
353
- x : nativeView . layer . valueForKeyPath ( 'transform.rotation.x' ) ,
354
- y : nativeView . layer . valueForKeyPath ( 'transform.rotation.y' ) ,
355
- z : nativeView . layer . valueForKeyPath ( 'transform.rotation.z' ) ,
356
- } ;
357
-
358
- if ( animation . target . rotateX !== undefined && animation . target . rotateX !== 0 && Math . floor ( toValue / 360 ) - toValue / 360 === 0 ) {
359
- fromValue . x = ( animation . target . rotateX * Math . PI ) / 180 ;
360
- }
361
- if ( animation . target . rotateY !== undefined && animation . target . rotateY !== 0 && Math . floor ( toValue / 360 ) - toValue / 360 === 0 ) {
362
- fromValue . y = ( animation . target . rotateY * Math . PI ) / 180 ;
363
- }
364
- if ( animation . target . rotate !== undefined && animation . target . rotate !== 0 && Math . floor ( toValue / 360 ) - toValue / 360 === 0 ) {
365
- fromValue . z = ( animation . target . rotate * Math . PI ) / 180 ;
366
- }
367
-
368
- // Respect only value.z for back-compat until 3D rotations are implemented
369
- toValue = {
370
- x : ( toValue . x * Math . PI ) / 180 ,
371
- y : ( toValue . y * Math . PI ) / 180 ,
372
- z : ( toValue . z * Math . PI ) / 180 ,
373
- } ;
349
+ propertyNameToAnimate = 'transform' ;
350
+ fromValue = NSValue . valueWithCATransform3D ( nativeView . layer . transform ) ;
351
+ toValue = NSValue . valueWithCATransform3D ( iosHelper . applyRotateTransform ( nativeView . layer . transform , toValue . x , toValue . y , toValue . z ) ) ;
374
352
break ;
375
353
case Properties . translate :
376
354
animation . _originalValue = {
@@ -387,10 +365,10 @@ export class Animation extends AnimationBase {
387
365
break ;
388
366
case Properties . scale :
389
367
if ( toValue . x === 0 ) {
390
- toValue . x = 0.001 ;
368
+ toValue . x = 1e-6 ;
391
369
}
392
370
if ( toValue . y === 0 ) {
393
- toValue . y = 0.001 ;
371
+ toValue . y = 1e-6 ;
394
372
}
395
373
animation . _originalValue = { x : view . scaleX , y : view . scaleY } ;
396
374
animation . _propertyResetCallback = ( value , valueSource ) => {
@@ -473,7 +451,6 @@ export class Animation extends AnimationBase {
473
451
return {
474
452
propertyNameToAnimate : propertyNameToAnimate ,
475
453
fromValue : fromValue ,
476
- subPropertiesToAnimate : subPropertyNameToAnimate ,
477
454
toValue : toValue ,
478
455
duration : duration ,
479
456
repeatCount : repeatCount ,
@@ -517,8 +494,10 @@ export class Animation extends AnimationBase {
517
494
}
518
495
519
496
private static _createGroupAnimation ( args : AnimationInfo , animation : PropertyAnimation ) {
497
+ const animations = NSMutableArray . alloc < CAAnimation > ( ) . initWithCapacity ( args . subPropertiesToAnimate . length ) ;
520
498
const groupAnimation = CAAnimationGroup . new ( ) ;
521
499
groupAnimation . duration = args . duration ;
500
+
522
501
if ( args . repeatCount !== undefined ) {
523
502
groupAnimation . repeatCount = args . repeatCount ;
524
503
}
@@ -528,7 +507,6 @@ export class Animation extends AnimationBase {
528
507
if ( animation . curve !== undefined ) {
529
508
groupAnimation . timingFunction = animation . curve ;
530
509
}
531
- const animations = NSMutableArray . alloc < CAAnimation > ( ) . initWithCapacity ( 3 ) ;
532
510
533
511
args . subPropertiesToAnimate . forEach ( ( property ) => {
534
512
const basicAnimationArgs = { ...args , duration : undefined , repeatCount : undefined , delay : undefined , curve : undefined } ;
@@ -671,16 +649,30 @@ export class Animation extends AnimationBase {
671
649
}
672
650
673
651
if ( value [ Properties . scale ] !== undefined ) {
674
- const x = value [ Properties . scale ] . x ;
675
- const y = value [ Properties . scale ] . y ;
676
- result = CATransform3DScale ( result , x === 0 ? 0.001 : x , y === 0 ? 0.001 : y , 1 ) ;
652
+ const x = value [ Properties . scale ] . x || 1e-6 ;
653
+ const y = value [ Properties . scale ] . y || 1e-6 ;
654
+ result = CATransform3DScale ( result , x , y , 1 ) ;
655
+ }
656
+
657
+ if ( value [ Properties . rotate ] !== undefined ) {
658
+ const x = value [ Properties . rotate ] . x ;
659
+ const y = value [ Properties . rotate ] . y ;
660
+ const z = value [ Properties . rotate ] . z ;
661
+ const perspective = animation . target . perspective || 300 ;
662
+
663
+ // Set perspective in case of rotation since we use z
664
+ if ( x || y ) {
665
+ result . m34 = - 1 / perspective ;
666
+ }
667
+
668
+ result = iosHelper . applyRotateTransform ( result , x , y , z ) ;
677
669
}
678
670
679
671
return result ;
680
672
}
681
673
682
674
private static _isAffineTransform ( property : string ) : boolean {
683
- return property === _transform || property === Properties . translate || property === Properties . scale ;
675
+ return property === _transform || property === Properties . translate || property === Properties . scale || property === Properties . rotate ;
684
676
}
685
677
686
678
private static _canBeMerged ( animation1 : PropertyAnimation , animation2 : PropertyAnimation ) {
@@ -947,7 +939,8 @@ function calculateTransform(view: View): CATransform3D {
947
939
// Order is important: translate, rotate, scale
948
940
let expectedTransform = new CATransform3D ( CATransform3DIdentity ) ;
949
941
950
- // Only set perspective if there is 3D rotation
942
+ // TODO: Add perspective property to transform animations (not just rotation)
943
+ // Set perspective in case of rotation since we use z
951
944
if ( view . rotateX || view . rotateY ) {
952
945
expectedTransform . m34 = - 1 / perspective ;
953
946
}
0 commit comments