@@ -4,6 +4,7 @@ import { RootLayoutBase, defaultShadeCoverOptions } from './root-layout-common';
4
4
import { TransitionAnimation , ShadeCoverOptions } from '.' ;
5
5
import { parseLinearGradient } from '../../../css/parser' ;
6
6
import { LinearGradient } from '../../styling/linear-gradient' ;
7
+ import { layout } from '../../../utils' ;
7
8
8
9
export * from './root-layout-common' ;
9
10
@@ -38,11 +39,20 @@ export class RootLayout extends RootLayoutBase {
38
39
}
39
40
40
41
protected _initShadeCover ( view : View , shadeOptions : ShadeCoverOptions ) : void {
41
- const initialState = < TransitionAnimation > {
42
+ const options = < TransitionAnimation > {
42
43
...defaultShadeCoverOptions . animation . enterFrom ,
43
44
...shadeOptions ?. animation ?. enterFrom ,
44
45
} ;
45
- this . _playAnimation ( this . _getAnimationSet ( view , initialState ) ) ;
46
+ const nativeView : android . view . View = view ?. nativeViewProtected ;
47
+
48
+ if ( nativeView ) {
49
+ nativeView . setAlpha ( options . opacity ) ;
50
+ nativeView . setScaleX ( float ( options . scaleX ) ) ;
51
+ nativeView . setScaleY ( float ( options . scaleY ) ) ;
52
+ nativeView . setTranslationX ( layout . toDevicePixels ( options . translateX ) ) ;
53
+ nativeView . setTranslationY ( layout . toDevicePixels ( options . translateY ) ) ;
54
+ nativeView . setRotation ( float ( options . rotate ) ) ;
55
+ }
46
56
}
47
57
48
58
protected _updateShadeCover ( view : View , shadeOptions : ShadeCoverOptions ) : Promise < void > {
@@ -51,6 +61,20 @@ export class RootLayout extends RootLayoutBase {
51
61
...shadeOptions ,
52
62
} ;
53
63
const duration = options . animation ?. enterFrom ?. duration || defaultShadeCoverOptions . animation . enterFrom . duration ;
64
+ const isBackgroundGradient = options . color && options . color . startsWith ( 'linear-gradient' ) ;
65
+
66
+ if ( isBackgroundGradient ) {
67
+ if ( view . backgroundColor ) {
68
+ view . backgroundColor = undefined ;
69
+ }
70
+ const parsedGradient = parseLinearGradient ( options . color ) ;
71
+ view . backgroundImage = LinearGradient . parse ( parsedGradient . value ) ;
72
+ } else {
73
+ if ( view . backgroundImage ) {
74
+ view . backgroundImage = undefined ;
75
+ }
76
+ }
77
+
54
78
return this . _playAnimation (
55
79
this . _getAnimationSet (
56
80
view ,
@@ -62,7 +86,7 @@ export class RootLayout extends RootLayoutBase {
62
86
rotate : 0 ,
63
87
opacity : options . opacity ,
64
88
} ,
65
- options . color ,
89
+ isBackgroundGradient ? null : options . color ,
66
90
) ,
67
91
duration ,
68
92
) ;
@@ -77,30 +101,16 @@ export class RootLayout extends RootLayoutBase {
77
101
}
78
102
79
103
private _getAnimationSet ( view : View , shadeCoverAnimation : TransitionAnimation , backgroundColor ?: string ) : Array < android . animation . Animator > {
80
- const isBackgroundGradient = backgroundColor && backgroundColor . startsWith ( 'linear-gradient' ) ;
81
-
82
- const animationSet = Array . create ( android . animation . Animator , ! backgroundColor || isBackgroundGradient ? 6 : 7 ) ;
83
- animationSet [ 0 ] = android . animation . ObjectAnimator . ofFloat ( view . nativeViewProtected , 'translationX' , [ shadeCoverAnimation . translateX ] ) ;
84
- animationSet [ 1 ] = android . animation . ObjectAnimator . ofFloat ( view . nativeViewProtected , 'translationY' , [ shadeCoverAnimation . translateY ] ) ;
104
+ const animationSet = Array . create ( android . animation . Animator , backgroundColor ? 7 : 6 ) ;
105
+ animationSet [ 0 ] = android . animation . ObjectAnimator . ofFloat ( view . nativeViewProtected , 'translationX' , [ layout . toDevicePixels ( shadeCoverAnimation . translateX ) ] ) ;
106
+ animationSet [ 1 ] = android . animation . ObjectAnimator . ofFloat ( view . nativeViewProtected , 'translationY' , [ layout . toDevicePixels ( shadeCoverAnimation . translateY ) ] ) ;
85
107
animationSet [ 2 ] = android . animation . ObjectAnimator . ofFloat ( view . nativeViewProtected , 'scaleX' , [ shadeCoverAnimation . scaleX ] ) ;
86
108
animationSet [ 3 ] = android . animation . ObjectAnimator . ofFloat ( view . nativeViewProtected , 'scaleY' , [ shadeCoverAnimation . scaleY ] ) ;
87
109
animationSet [ 4 ] = android . animation . ObjectAnimator . ofFloat ( view . nativeViewProtected , 'rotation' , [ shadeCoverAnimation . rotate ] ) ;
88
110
animationSet [ 5 ] = android . animation . ObjectAnimator . ofFloat ( view . nativeViewProtected , 'alpha' , [ shadeCoverAnimation . opacity ] ) ;
89
111
90
- if ( isBackgroundGradient ) {
91
- if ( view . backgroundColor ) {
92
- view . backgroundColor = undefined ;
93
- }
94
- const parsedGradient = parseLinearGradient ( backgroundColor ) ;
95
- view . backgroundImage = LinearGradient . parse ( parsedGradient . value ) ;
96
- } else {
97
- if ( view . backgroundImage ) {
98
- view . backgroundImage = undefined ;
99
- }
100
-
101
- if ( backgroundColor ) {
102
- animationSet [ 6 ] = this . _getBackgroundColorAnimator ( view , backgroundColor ) ;
103
- }
112
+ if ( backgroundColor ) {
113
+ animationSet [ 6 ] = this . _getBackgroundColorAnimator ( view , backgroundColor ) ;
104
114
}
105
115
return animationSet ;
106
116
}
0 commit comments