|
21 | 21 | const OFFSET_ACCURACY = 10;
|
22 | 22 | const SCALE = weex.config.env.platform.toLowerCase() === 'web' ? 2 : 1;
|
23 | 23 |
|
24 |
| - function _toNum(str) { |
| 24 | + function _toNum (str) { |
25 | 25 | return typeof str === 'number' ? str : parseFloat((str || '').replace(/px$/i, ''));
|
26 | 26 | }
|
27 | 27 |
|
28 |
| - function _getHeight(element, callback) { |
29 |
| - if (!element) { return; } |
| 28 | + function _getHeight (element, callback) { |
| 29 | + if (!element) { |
| 30 | + return; |
| 31 | + } |
30 | 32 | if (element.__cacheHeight) {
|
31 | 33 | element.__cacheHeight && callback && callback(element.__cacheHeight);
|
32 | 34 | } else {
|
|
48 | 50 | height: [String, Number]
|
49 | 51 | },
|
50 | 52 |
|
51 |
| - data() { |
| 53 | + data () { |
52 | 54 | return {
|
53 | 55 | visible: true
|
54 | 56 | }
|
55 | 57 | },
|
56 | 58 |
|
57 | 59 | watch: {
|
58 |
| - visible(newVal) { |
| 60 | + visible (newVal) { |
59 | 61 | newVal ? this._slideIn() : this._slideOut();
|
60 | 62 | }
|
61 | 63 | },
|
62 | 64 |
|
63 |
| - created() { |
| 65 | + created () { |
64 | 66 | this._height = _toNum(this.height) || 0;
|
65 | 67 | this._isBottom = this.position === 'bottom';
|
66 | 68 | this._direction = this._isBottom ? 1 : -1;
|
67 | 69 | },
|
68 | 70 |
|
69 | 71 | methods: {
|
70 | 72 |
|
71 |
| - _slideOut() { |
| 73 | + _slideOut () { |
72 | 74 | this.getHeight((height) => {
|
73 | 75 | this.$emit('slideOut');
|
74 | 76 | this.slideY(height * this._direction * SCALE, () => {
|
|
77 | 79 | });
|
78 | 80 | },
|
79 | 81 |
|
80 |
| - _slideIn() { |
| 82 | + _slideIn () { |
81 | 83 | this.getHeight((height) => {
|
82 | 84 | this.$emit('slideIn');
|
83 | 85 | this.slideY(0, () => {
|
|
86 | 88 | });
|
87 | 89 | },
|
88 | 90 |
|
89 |
| - getHeight(callback) { |
| 91 | + getHeight (callback) { |
90 | 92 | return _getHeight(this.$refs.wrapper, callback);
|
91 | 93 | },
|
92 | 94 |
|
93 |
| - slideOut() { |
| 95 | + slideOut () { |
94 | 96 | this.visible = false;
|
95 | 97 | },
|
96 | 98 |
|
97 |
| - slideIn() { |
| 99 | + slideIn () { |
98 | 100 | this.visible = true;
|
99 | 101 | },
|
100 | 102 |
|
101 |
| - slideY(y, callback) { |
| 103 | + slideY (y, callback) { |
102 | 104 | Animation.transition(this.$refs.wrapper, {
|
103 |
| - styles: { transform: 'translateY(' + y + 'px)' }, |
| 105 | + styles: { transform: 'translateY(' + y + 'px)' }, |
104 | 106 | duration: 150, //ms
|
105 | 107 | timingFunction: 'ease',
|
106 | 108 | delay: 0 //ms
|
107 | 109 | }, callback);
|
108 | 110 | }
|
109 | 111 | },
|
110 | 112 |
|
111 |
| - handleTouchStart(e) { |
| 113 | + handleTouchStart (e) { |
112 | 114 | let touch = e.changedTouches[0];
|
113 | 115 | this._touchParams = {
|
114 | 116 | pageY: touch.screenY,
|
|
119 | 121 | };
|
120 | 122 | },
|
121 | 123 |
|
122 |
| - handleTouchMove(e, bottomNav) { |
| 124 | + handleTouchMove (e, bottomNav) { |
123 | 125 | let tp = this._touchParams;
|
124 | 126 | let touch = e.changedTouches[0];
|
125 | 127 | let offsetY;
|
|
157 | 159 | }
|
158 | 160 | },
|
159 | 161 |
|
160 |
| - handleTouchEnd() { |
| 162 | + handleTouchEnd () { |
161 | 163 | let tp = this._touchParams;
|
162 | 164 | tp && (tp.hasEnd = true);
|
163 | 165 | },
|
164 | 166 |
|
165 |
| - handleScroll(e, scroller, topNav, bottomNav, startThreshold, moveThreshold = 5) { |
| 167 | + handleScroll (e, scroller, topNav, bottomNav, startThreshold, moveThreshold = 5) { |
166 | 168 | let scrollY = e.contentOffset.y;
|
167 | 169 | let nav = topNav || bottomNav;
|
168 | 170 | let scrollFn = (maxScrollY) => {
|
169 |
| - if (-scrollY > maxScrollY) { return; } |
| 171 | + if (-scrollY > maxScrollY) { |
| 172 | + return; |
| 173 | + } |
170 | 174 | maxScrollY = Math.abs(maxScrollY);
|
171 | 175 | if (Math.abs(scrollY) < startThreshold) {
|
172 | 176 | if (Math.abs(scrollY) >= maxScrollY - OFFSET_ACCURACY) {
|
173 | 177 | let tp = this._touchParams;
|
174 |
| - if (!tp) { return; } |
| 178 | + if (!tp) { |
| 179 | + return; |
| 180 | + } |
175 | 181 | let offsetY = tp.offsetY;
|
176 |
| - if (offsetY < -OFFSET_ACCURACY) { |
177 |
| - bottomNav && bottomNav.slideOut(); |
178 |
| - } else if (offsetY > OFFSET_ACCURACY) { |
179 |
| - bottomNav && bottomNav.slideIn(); |
| 182 | + if (offsetY < -OFFSET_ACCURACY) { |
| 183 | + bottomNav && bottomNav.slideOut(); |
| 184 | + } else if (offsetY > OFFSET_ACCURACY) { |
| 185 | + bottomNav && bottomNav.slideIn(); |
180 | 186 | }
|
181 | 187 | } else {
|
182 | 188 | topNav && topNav.slideIn();
|
183 | 189 | bottomNav && bottomNav.slideIn();
|
184 | 190 | }
|
185 | 191 | } else {
|
186 | 192 | let tp = this._touchParams;
|
187 |
| - if (!tp) { return; } |
| 193 | + if (!tp) { |
| 194 | + return; |
| 195 | + } |
188 | 196 | let offsetY = tp.offsetY;
|
189 | 197 | if (Math.abs(offsetY) >= moveThreshold) {
|
190 | 198 | if (offsetY > 0) {
|
|
199 | 207 | };
|
200 | 208 |
|
201 | 209 | let maxScrollYCheck = (maxScrollY) => {
|
202 |
| - if (!this.__scrollable) { return; } |
| 210 | + if (!this.__scrollable) { |
| 211 | + return; |
| 212 | + } |
203 | 213 | if (startThreshold) {
|
204 | 214 | scrollFn(maxScrollY);
|
205 | 215 | } else {
|
|
210 | 220 | }
|
211 | 221 | };
|
212 | 222 |
|
213 |
| - if (!nav) { return; } |
| 223 | + if (!nav) { |
| 224 | + return; |
| 225 | + } |
214 | 226 |
|
215 | 227 | _getHeight(scroller, (scrollerHeight) => {
|
216 | 228 | let maxScrollY = e.contentSize.height - scrollerHeight;
|
|
0 commit comments