UNPKG

4.43 kBJavaScriptView Raw
1/*
2Copyright 2013-2015 ASIAL CORPORATION
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15
16*/
17
18import animit from '../../ons/animit.js';
19import BaseAnimator from '../../ons/base-animator.js';
20import iPhoneXPatch from '../../ons/iphonex-patch.js';
21
22export class ActionSheetAnimator extends BaseAnimator {
23
24 constructor({timing = 'linear', delay = 0, duration = 0.2} = {}) {
25 super({ timing, delay, duration });
26 }
27
28 /**
29 * @param {HTMLElement} dialog
30 * @param {Function} done
31 */
32 show(dialog, done) {
33 done();
34 }
35
36 /**
37 * @param {HTMLElement} dialog
38 * @param {Function} done
39 */
40 hide(dialog, done) {
41 done();
42 }
43}
44
45/**
46 * Android style animator for Action Sheet.
47 */
48export class MDActionSheetAnimator extends ActionSheetAnimator {
49
50 constructor({ timing = 'ease', delay = 0, duration = 0.4 } = {}) {
51 super({timing, delay, duration});
52
53 this.maskTiming = 'linear';
54 this.maskDuration = 0.2;
55 }
56
57 /**
58 * @param {Object} dialog
59 * @param {Function} callback
60 */
61 show(dialog, callback) {
62
63 animit.runAll(
64 animit(dialog._mask)
65 .queue({ opacity: 0 })
66 .wait(this.delay)
67 .queue({ opacity: 1.0 }, {
68 duration: this.maskDuration,
69 timing: this.maskTiming
70 }),
71
72 animit(dialog._sheet, this.def)
73 .default(
74 { transform: `translate3d(0, 80%, 0)`, opacity: 0 },
75 { transform: 'translate3d(0, 0, 0)', opacity: 1 }
76 )
77 .queue(done => {
78 callback && callback();
79 done();
80 })
81 );
82 }
83
84 /**
85 * @param {Object} dialog
86 * @param {Function} callback
87 */
88 hide(dialog, callback) {
89 animit.runAll(
90
91 animit(dialog._mask)
92 .queue({ opacity: 1 })
93 .wait(this.delay)
94 .queue({ opacity: 0 }, {
95 duration: this.maskDuration,
96 timing: this.maskTiming
97 }),
98
99 animit(dialog._sheet, this.def)
100 .default(
101 { transform: 'translate3d(0, 0, 0)', opacity: 1 },
102 { transform: `translate3d(0, 80%, 0)`, opacity: 0 }
103 )
104 .queue(done => {
105 callback && callback();
106 done();
107 })
108 );
109 }
110}
111
112/**
113 * iOS style animator for dialog.
114 */
115export class IOSActionSheetAnimator extends ActionSheetAnimator {
116
117 constructor({ timing = 'ease', delay = 0, duration = 0.3 } = {}) {
118 super({timing, delay, duration});
119
120 this.maskTiming = 'linear';
121 this.maskDuration = 0.2;
122 if (iPhoneXPatch.isIPhoneXPortraitPatchActive()) {
123 this.liftAmount = 'calc(100% + 48px)';
124 } else if (iPhoneXPatch.isIPhoneXLandscapePatchActive()) {
125 this.liftAmount = 'calc(100% + 33px)';
126 } else {
127 this.liftAmount = document.body.clientHeight / 2.0 - 1 + 'px'; // avoid Forced Synchronous Layout
128 }
129 }
130
131 /**
132 * @param {Object} dialog
133 * @param {Function} callback
134 */
135 show(dialog, callback) {
136 animit.runAll(
137
138 animit(dialog._mask)
139 .queue({ opacity: 0 })
140 .wait(this.delay)
141 .queue({ opacity: 1 }, {
142 duration: this.maskDuration,
143 timing: this.maskTiming
144 }),
145
146 animit(dialog._sheet, this.def)
147 .default(
148 { transform: `translate3d(0, ${this.liftAmount}, 0)` },
149 { transform: 'translate3d(0, 0, 0)' }
150 )
151 .queue(done => {
152 callback && callback();
153 done();
154 })
155 );
156 }
157
158 /**
159 * @param {Object} dialog
160 * @param {Function} callback
161 */
162 hide(dialog, callback) {
163 animit.runAll(
164
165 animit(dialog._mask)
166 .queue({ opacity: 1 })
167 .wait(this.delay)
168 .queue({ opacity: 0 }, {
169 duration: this.maskDuration,
170 timing: this.maskTiming
171 }),
172
173 animit(dialog._sheet, this.def)
174 .default(
175 { transform: 'translate3d(0, 0, 0)' },
176 { transform: `translate3d(0, ${this.liftAmount}, 0)` }
177 )
178 .queue(done => {
179 callback && callback();
180 done();
181 })
182 );
183 }
184}