8000 feat(root-layout): gradient for android handling (#9702) · NativeScript/NativeScript@6ab7fe1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ab7fe1

Browse files
feat(root-layout): gradient for android handling (#9702)
1 parent ef9f03e commit 6ab7fe1

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

apps/toolbox/src/pages/root-layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class RootLayoutModel extends Observable {
1111
view: this.getPopup('#EA5936', 110, -30),
1212
options: {
1313
shadeCover: {
14-
color: '#FFF',
14+
color: 'linear-gradient(to bottom, red, blue)',
1515
opacity: 0.7,
1616
tapToClose: true,
1717
},

packages/core/ui/layouts/root-layout/index.android.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Color } from '../../../color';
22
import { View } from '../../core/view';
33
import { RootLayoutBase, defaultShadeCoverOptions } from './root-layout-common';
44
import { TransitionAnimation, ShadeCoverOptions } from '.';
5+
import { parseLinearGradient } from '../../../css/parser';
6+
import { LinearGradient } from '../../styling/linear-gradient';
57

68
export * from './root-layout-common';
79

@@ -74,14 +76,28 @@ export class RootLayout extends RootLayoutBase {
7476
}
7577

7678
private _getAnimationSet(view: View, shadeCoverAnimation: TransitionAnimation, backgroundColor: string = defaultShadeCoverOptions.color): Array<android.animation.Animator> {
77-
const animationSet = Array.create(android.animation.Animator, 7);
79+
const backgroundIsGradient = backgroundColor.startsWith('linear-gradient');
80+
81+
const animationSet = Array.create(android.animation.Animator, backgroundIsGradient ? 6 : 7);
7882
animationSet[0] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'translationX', [shadeCoverAnimation.translateX]);
7983
animationSet[1] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'translationY', [shadeCoverAnimation.translateY]);
8084
animationSet[2] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'scaleX', [shadeCoverAnimation.scaleX]);
8185
animationSet[3] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'scaleY', [shadeCoverAnimation.scaleY]);
8286
animationSet[4] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'rotation', [shadeCoverAnimation.rotate]);
8387
animationSet[5] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'alpha', [shadeCoverAnimation.opacity]);
84-
animationSet[6] = this._getBackgroundColorAnimator(view, backgroundColor);
88+
89+
if (backgroundIsGradient) {
90+
if (view.backgroundColor) {
91+
view.backgroundColor = undefined;
92+
}
93+
const parsedGradient = parseLinearGradient(backgroundColor);
94+
view.backgroundImage = LinearGradient.parse(parsedGradient.value);
95+
} else {
96+
if (view.backgroundImage) {
97+
view.backgroundImage = undefined;
98+
}
99+
animationSet[6] = this._getBackgroundColorAnimator(view, backgroundColor);
100+
}
85101
return animationSet;
86102
}
87103

0 commit comments

Comments
 (0)
0