1 | import { Transition } from '.';
|
2 | import { Screen } from '../../platform';
|
3 | import lazy from '../../utils/lazy';
|
4 | const screenWidth = lazy(() => Screen.mainScreen.widthPixels);
|
5 | const screenHeight = lazy(() => Screen.mainScreen.heightPixels);
|
6 | export class SlideTransition extends Transition {
|
7 | constructor(direction, duration = 350, curve) {
|
8 | super(duration, curve);
|
9 | this._direction = direction;
|
10 | }
|
11 | createAndroidAnimator(transitionType) {
|
12 | const translationValues = Array.create('float', 2);
|
13 | switch (this._direction) {
|
14 | case 'left':
|
15 | switch (transitionType) {
|
16 | case Transition.AndroidTransitionType.enter:
|
17 | translationValues[0] = screenWidth();
|
18 | translationValues[1] = 0;
|
19 | break;
|
20 | case Transition.AndroidTransitionType.exit:
|
21 | translationValues[0] = 0;
|
22 | translationValues[1] = -screenWidth();
|
23 | break;
|
24 | case Transition.AndroidTransitionType.popEnter:
|
25 | translationValues[0] = -screenWidth();
|
26 | translationValues[1] = 0;
|
27 | break;
|
28 | case Transition.AndroidTransitionType.popExit:
|
29 | translationValues[0] = 0;
|
30 | translationValues[1] = screenWidth();
|
31 | break;
|
32 | }
|
33 | break;
|
34 | case 'right':
|
35 | switch (transitionType) {
|
36 | case Transition.AndroidTransitionType.enter:
|
37 | translationValues[0] = -screenWidth();
|
38 | translationValues[1] = 0;
|
39 | break;
|
40 | case Transition.AndroidTransitionType.exit:
|
41 | translationValues[0] = 0;
|
42 | translationValues[1] = screenWidth();
|
43 | break;
|
44 | case Transition.AndroidTransitionType.popEnter:
|
45 | translationValues[0] = screenWidth();
|
46 | translationValues[1] = 0;
|
47 | break;
|
48 | case Transition.AndroidTransitionType.popExit:
|
49 | translationValues[0] = 0;
|
50 | translationValues[1] = -screenWidth();
|
51 | break;
|
52 | }
|
53 | break;
|
54 | case 'top':
|
55 | switch (transitionType) {
|
56 | case Transition.AndroidTransitionType.enter:
|
57 | translationValues[0] = screenHeight();
|
58 | translationValues[1] = 0;
|
59 | break;
|
60 | case Transition.AndroidTransitionType.exit:
|
61 | translationValues[0] = 0;
|
62 | translationValues[1] = -screenHeight();
|
63 | break;
|
64 | case Transition.AndroidTransitionType.popEnter:
|
65 | translationValues[0] = -screenHeight();
|
66 | translationValues[1] = 0;
|
67 | break;
|
68 | case Transition.AndroidTransitionType.popExit:
|
69 | translationValues[0] = 0;
|
70 | translationValues[1] = screenHeight();
|
71 | break;
|
72 | }
|
73 | break;
|
74 | case 'bottom':
|
75 | switch (transitionType) {
|
76 | case Transition.AndroidTransitionType.enter:
|
77 | translationValues[0] = -screenHeight();
|
78 | translationValues[1] = 0;
|
79 | break;
|
80 | case Transition.AndroidTransitionType.exit:
|
81 | translationValues[0] = 0;
|
82 | translationValues[1] = screenHeight();
|
83 | break;
|
84 | case Transition.AndroidTransitionType.popEnter:
|
85 | translationValues[0] = screenHeight();
|
86 | translationValues[1] = 0;
|
87 | break;
|
88 | case Transition.AndroidTransitionType.popExit:
|
89 | translationValues[0] = 0;
|
90 | translationValues[1] = -screenHeight();
|
91 | break;
|
92 | }
|
93 | break;
|
94 | }
|
95 | let prop;
|
96 | if (this._direction === 'left' || this._direction === 'right') {
|
97 | prop = 'translationX';
|
98 | }
|
99 | else {
|
100 | prop = 'translationY';
|
101 | }
|
102 | const animator = android.animation.ObjectAnimator.ofFloat(null, prop, translationValues);
|
103 | const duration = this.getDuration();
|
104 | if (duration !== undefined) {
|
105 | animator.setDuration(duration);
|
106 | }
|
107 | animator.setInterpolator(this.getCurve());
|
108 | const animatorSet = new android.animation.AnimatorSet();
|
109 | animatorSet.play(animator);
|
110 | return animatorSet;
|
111 | }
|
112 | toString() {
|
113 | return `${super.toString()} ${this._direction}`;
|
114 | }
|
115 | }
|
116 |
|
\ | No newline at end of file |