1 | import { Color } from '../../../color';
|
2 | import { RootLayoutBase, defaultShadeCoverOptions } from './root-layout-common';
|
3 | import { parseLinearGradient } from '../../../css/parser';
|
4 | import { LinearGradient } from '../../styling/linear-gradient';
|
5 | export * from './root-layout-common';
|
6 | export class RootLayout extends RootLayoutBase {
|
7 | constructor() {
|
8 | super();
|
9 | }
|
10 | insertChild(view, atIndex) {
|
11 | super.insertChild(view, atIndex);
|
12 | if (!view.hasGestureObservers()) {
|
13 |
|
14 | if (view.nativeViewProtected) {
|
15 | view.nativeViewProtected.setOnTouchListener(new android.view.View.OnTouchListener({
|
16 | onTouch: function (view, event) {
|
17 | return true;
|
18 | },
|
19 | }));
|
20 | }
|
21 | }
|
22 | }
|
23 | removeChild(view) {
|
24 | if (view.hasGestureObservers() && view.nativeViewProtected) {
|
25 | view.nativeViewProtected.setOnTouchListener(null);
|
26 | }
|
27 | super.removeChild(view);
|
28 | }
|
29 | _bringToFront(view) {
|
30 | view.nativeViewProtected.bringToFront();
|
31 | }
|
32 | _initShadeCover(view, shadeOptions) {
|
33 | const initialState = {
|
34 | ...defaultShadeCoverOptions.animation.enterFrom,
|
35 | ...shadeOptions?.animation?.enterFrom,
|
36 | };
|
37 | this._playAnimation(this._getAnimationSet(view, initialState));
|
38 | }
|
39 | _updateShadeCover(view, shadeOptions) {
|
40 | const options = {
|
41 | ...defaultShadeCoverOptions,
|
42 | ...shadeOptions,
|
43 | };
|
44 | const duration = options.animation?.enterFrom?.duration || defaultShadeCoverOptions.animation.enterFrom.duration;
|
45 | return this._playAnimation(this._getAnimationSet(view, {
|
46 | translateX: 0,
|
47 | translateY: 0,
|
48 | scaleX: 1,
|
49 | scaleY: 1,
|
50 | rotate: 0,
|
51 | opacity: options.opacity,
|
52 | }, options.color), duration);
|
53 | }
|
54 | _closeShadeCover(view, shadeOptions) {
|
55 | const exitState = {
|
56 | ...defaultShadeCoverOptions.animation.exitTo,
|
57 | ...shadeOptions?.animation?.exitTo,
|
58 | };
|
59 | return this._playAnimation(this._getAnimationSet(view, exitState), exitState?.duration);
|
60 | }
|
61 | _getAnimationSet(view, shadeCoverAnimation, backgroundColor = defaultShadeCoverOptions.color) {
|
62 | const backgroundIsGradient = backgroundColor.startsWith('linear-gradient');
|
63 | const animationSet = Array.create(android.animation.Animator, backgroundIsGradient ? 6 : 7);
|
64 | animationSet[0] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'translationX', [shadeCoverAnimation.translateX]);
|
65 | animationSet[1] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'translationY', [shadeCoverAnimation.translateY]);
|
66 | animationSet[2] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'scaleX', [shadeCoverAnimation.scaleX]);
|
67 | animationSet[3] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'scaleY', [shadeCoverAnimation.scaleY]);
|
68 | animationSet[4] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'rotation', [shadeCoverAnimation.rotate]);
|
69 | animationSet[5] = android.animation.ObjectAnimator.ofFloat(view.nativeViewProtected, 'alpha', [shadeCoverAnimation.opacity]);
|
70 | if (backgroundIsGradient) {
|
71 | if (view.backgroundColor) {
|
72 | view.backgroundColor = undefined;
|
73 | }
|
74 | const parsedGradient = parseLinearGradient(backgroundColor);
|
75 | view.backgroundImage = LinearGradient.parse(parsedGradient.value);
|
76 | }
|
77 | else {
|
78 | if (view.backgroundImage) {
|
79 | view.backgroundImage = undefined;
|
80 | }
|
81 | animationSet[6] = this._getBackgroundColorAnimator(view, backgroundColor);
|
82 | }
|
83 | return animationSet;
|
84 | }
|
85 | _getBackgroundColorAnimator(view, backgroundColor) {
|
86 | const nativeArray = Array.create(java.lang.Object, 2);
|
87 | nativeArray[0] = view.backgroundColor ? java.lang.Integer.valueOf(view.backgroundColor.argb) : java.lang.Integer.valueOf(-1);
|
88 | nativeArray[1] = java.lang.Integer.valueOf(new Color(backgroundColor).argb);
|
89 | const backgroundColorAnimator = android.animation.ValueAnimator.ofObject(new android.animation.ArgbEvaluator(), nativeArray);
|
90 | backgroundColorAnimator.addUpdateListener(new android.animation.ValueAnimator.AnimatorUpdateListener({
|
91 | onAnimationUpdate(animator) {
|
92 | const argb = animator.getAnimatedValue().intValue();
|
93 | view.backgroundColor = new Color(argb);
|
94 | },
|
95 | }));
|
96 | return backgroundColorAnimator;
|
97 | }
|
98 | _playAnimation(animationSet, duration = 0) {
|
99 | return new Promise((resolve) => {
|
100 | const animatorSet = new android.animation.AnimatorSet();
|
101 | animatorSet.playTogether(animationSet);
|
102 | animatorSet.setDuration(duration);
|
103 | animatorSet.addListener(new android.animation.Animator.AnimatorListener({
|
104 | onAnimationStart: function (animator) { },
|
105 | onAnimationEnd: function (animator) {
|
106 | resolve();
|
107 | },
|
108 | onAnimationRepeat: function (animator) { },
|
109 | onAnimationCancel: function (animator) { },
|
110 | }));
|
111 | animatorSet.start();
|
112 | });
|
113 | }
|
114 | }
|
115 |
|
\ | No newline at end of file |