8000 fix: Avoid unsetting shade cover background during close · NativeScript/NativeScript@ccad490 · GitHub
[go: up one dir, main page]

Skip to content

Commit ccad490

Browse files
committed
fix: Avoid unsetting shade cover background during close
1 parent 1fc6dc7 commit ccad490

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

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

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ export class RootLayout extends RootLayoutBase {
4747

4848
if (nativeView) {
4949
nativeView.setAlpha(options.opacity);
50-
org.nativescript.widgets.ViewHelper.setScaleX(nativeView, float(options.scaleX));
51-
org.nativescript.widgets.ViewHelper.setScaleY(nativeView, float(options.scaleY));
52-
org.nativescript.widgets.ViewHelper.setTranslateX(nativeView, layout.toDevicePixels(options.translateX));
53-
org.nativescript.widgets.ViewHelper.setTranslateY(nativeView, layout.toDevicePixels(options.translateY));
54-
org.nativescript.widgets.ViewHelper.setRotate(nativeView, float(options.rotate));
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));
5555
}
5656
}
5757

@@ -61,6 +61,19 @@ export class RootLayout extends RootLayoutBase {
6161
...shadeOptions,
6262
};
6363
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+
}
6477

6578
return this._playAnimation(
6679
this._getAnimationSet(
@@ -73,7 +86,7 @@ export class RootLayout extends RootLayoutBase {
7386
rotate: 0,
7487
opacity: options.opacity,
7588
},
76-
options.color,
89+
isBackgroundGradient ? null : options.color,
7790
),
7891
duration,
7992
);
@@ -88,30 +101,16 @@ export class RootLayout extends RootLayoutBase {
88101
}
89102

90103
private _getAnimationSet(view: View, shadeCoverAnimation: TransitionAnimation, backgroundColor?: string): Array<android.animation.Animator> {
91-
const isBackgroundGradient = backgroundColor && backgroundColor.startsWith('linear-gradient');
92-
93-
const animationSet = Array.create(android.animation.Animator, !backgroundColor || isBackgroundGradient ? 6 : 7);
94-
animationSet[0] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'translationX', [shadeCoverAnimation.translateX]);
95-
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)]);
96107
animationSet[2] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'scaleX', [shadeCoverAnimation.scaleX]);
97108
animationSet[3] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'scaleY', [shadeCoverAnimation.scaleY]);
98109
animationSet[4] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'rotation', [shadeCoverAnimation.rotate]);
99110
animationSet[5] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'alpha', [shadeCoverAnimation.opacity]);
100111

101-
if (isBackgroundGradient) {
102-
if (view.backgroundColor) {
103-
view.backgroundColor = undefined;
104-
}
105-
const parsedGradient = parseLinearGradient(backgroundColor);
106-
view.backgroundImage = LinearGradient.parse(parsedGradient.value);
107-
} else {
108-
if (view.backgroundImage) {
109-
view.backgroundImage = undefined;
110-
}
111-
112-
if (backgroundColor) {
113-
animationSet[6] = this._getBackgroundColorAnimator(view, backgroundColor);
114-
}
112+
if (backgroundColor) {
113+
animationSet[6] = this._getBackgroundColorAnimator(view, backgroundColor);
115114
}
116115
return animationSet;
117116
}

0 commit comments

Comments
 (0)
0