|
221 | 221 | var oldOverflowX = self.el.style.overflowX;
|
222 | 222 | var oldOverflowY = self.el.style.overflowY;
|
223 | 223 |
|
| 224 | + clearTimeout(self.__scrollToCleanupTimeout); |
| 225 | + self.__scrollToCleanupTimeout = setTimeout(function() { |
| 226 | + self.el.style.overflowX = oldOverflowX; |
| 227 | + self.el.style.overflowY = oldOverflowY; |
| 228 | + }, 500); |
| 229 | + |
224 | 230 | self.el.style.overflowY = 'hidden';
|
225 | 231 | self.el.style.overflowX = 'hidden';
|
226 | 232 |
|
|
326 | 332 | // save height when scroll view is shrunk so we don't need to reflow
|
327 | 333 | var scrollViewOffsetHeight;
|
328 | 334 |
|
| 335 | + var lastKeyboardHeight; |
| 336 | + |
329 | 337 | /**
|
330 | 338 | * Shrink the scroll view when the keyboard is up if necessary and if the
|
331 | 339 | * focused input is below the bottom of the shrunk scroll view, scroll it
|
332 | 340 | * into view.
|
333 | 341 | */
|
334 | 342 | self.scrollChildIntoView = function(e) {
|
335 |
| - //console.log("scrollChildIntoView at: " + Date.now()); |
336 |
| - |
337 | 343 | // D
|
338 | 344 | var scrollBottomOffsetToTop = container.getBoundingClientRect().bottom;
|
339 | 345 | // D - A
|
|
357 | 363 | * All commented calculations relative to the top of the viewport (ie E
|
358 | 364 | * is the viewport height, not 0)
|
359 | 365 | */
|
360 |
| - if (!alreadyShrunk) { |
| 366 | + |
| 367 | + |
| 368 | + var changedKeyboardHeight = lastKeyboardHeight && (lastKeyboardHeight !== e.detail.keyboardHeight); |
| 369 | + |
| 370 | + if (!alreadyShrunk || changedKeyboardHeight) { |
361 | 371 | // shrink scrollview so we can actually scroll if the input is hidden
|
362 | 372 | // if it isn't shrink so we can scroll to inputs under the keyboard
|
363 | 373 | // inset modals won't shrink on Android on their own when the keyboard appears
|
|
368 | 378 | var scrollBottomOffsetToBottom = e.detail.viewportHeight - scrollBottomOffsetToTop;
|
369 | 379 |
|
370 | 380 | // 0 or D - B if D > B E - B E - D
|
371 |
| - var keyboardOffset = Math.max(0, e.detail.keyboardHeight - scrollBottomOffsetToBottom); |
| 381 | + var keyboardOffset = e.detail.keyboardHeight - scrollBottomOffsetToBottom; |
372 | 382 |
|
373 | 383 | ionic.requestAnimationFrame(function(){
|
374 | 384 | // D - A or B - A if D > B D - A max(0, D - B)
|
375 |
| - scrollViewOffsetHeight = scrollViewOffsetHeight - keyboardOffset; |
| 385 | + scrollViewOffsetHeight = keyboardOffset >= 0 ? scrollViewOffsetHeight + keyboardOffset : scrollViewOffsetHeight - keyboardOffset; |
| 386 | + |
376 | 387 | container.style.height = scrollViewOffsetHeight + "px";
|
377 | 388 |
|
| 389 | + container.classList.add('keyboard-up'); |
378 | 390 | //update scroll view
|
379 | 391 | self.resize();
|
380 | 392 | });
|
|
383 | 395 | self.isShrunkForKeyboard = true;
|
384 | 396 | }
|
385 | 397 |
|
| 398 | + lastKeyboardHeight = e.detail.keyboardHeight; |
| 399 | + |
386 | 400 | /*
|
387 | 401 | * _______
|
388 | 402 | * |---A---| <- top of scroll view
|
|
446 | 460 | if (self.isShrunkForKeyboard) {
|
447 | 461 | self.isShrunkForKeyboard = false;
|
448 | 462 | container.style.height = "";
|
| 463 | + |
| 464 | + // Read after setting this to avoid rendering issues like white boxes. |
| 465 | + ionic.requestAnimationFrame(function() { |
| 466 | + container.classList.remove('keyboard-up'); |
| 467 | + }); |
| 468 | + |
449 | 469 | }
|
450 | 470 | self.resize();
|
451 | 471 | };
|
|
0 commit comments