Skip to content

Commit 4ad6021

Browse files
committed
fix(keyboard): fix blank spot. Fixes #4849 and #4645
1 parent c1ef9da commit 4ad6021

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

Diff for: js/views/scrollViewNative.js

+25-5
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@
221221
var oldOverflowX = self.el.style.overflowX;
222222
var oldOverflowY = self.el.style.overflowY;
223223

224+
clearTimeout(self.__scrollToCleanupTimeout);
225+
self.__scrollToCleanupTimeout = setTimeout(function() {
226+
self.el.style.overflowX = oldOverflowX;
227+
self.el.style.overflowY = oldOverflowY;
228+
}, 500);
229+
224230
self.el.style.overflowY = 'hidden';
225231
self.el.style.overflowX = 'hidden';
226232

@@ -326,14 +332,14 @@
326332
// save height when scroll view is shrunk so we don't need to reflow
327333
var scrollViewOffsetHeight;
328334

335+
var lastKeyboardHeight;
336+
329337
/**
330338
* Shrink the scroll view when the keyboard is up if necessary and if the
331339
* focused input is below the bottom of the shrunk scroll view, scroll it
332340
* into view.
333341
*/
334342
self.scrollChildIntoView = function(e) {
335-
//console.log("scrollChildIntoView at: " + Date.now());
336-
337343
// D
338344
var scrollBottomOffsetToTop = container.getBoundingClientRect().bottom;
339345
// D - A
@@ -357,7 +363,11 @@
357363
* All commented calculations relative to the top of the viewport (ie E
358364
* is the viewport height, not 0)
359365
*/
360-
if (!alreadyShrunk) {
366+
367+
368+
var changedKeyboardHeight = lastKeyboardHeight && (lastKeyboardHeight !== e.detail.keyboardHeight);
369+
370+
if (!alreadyShrunk || changedKeyboardHeight) {
361371
// shrink scrollview so we can actually scroll if the input is hidden
362372
// if it isn't shrink so we can scroll to inputs under the keyboard
363373
// inset modals won't shrink on Android on their own when the keyboard appears
@@ -368,13 +378,15 @@
368378
var scrollBottomOffsetToBottom = e.detail.viewportHeight - scrollBottomOffsetToTop;
369379

370380
// 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;
372382

373383
ionic.requestAnimationFrame(function(){
374384
// 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+
376387
container.style.height = scrollViewOffsetHeight + "px";
377388

389+
container.classList.add('keyboard-up');
378390
//update scroll view
379391
self.resize();
380392
});
@@ -383,6 +395,8 @@
383395
self.isShrunkForKeyboard = true;
384396
}
385397

398+
lastKeyboardHeight = e.detail.keyboardHeight;
399+
386400
/*
387401
* _______
388402
* |---A---| <- top of scroll view
@@ -446,6 +460,12 @@
446460
if (self.isShrunkForKeyboard) {
447461
self.isShrunkForKeyboard = false;
448462
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+
449469
}
450470
self.resize();
451471
};

Diff for: scss/_scaffolding.scss

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ ion-infinite-scroll {
209209
height: 100%;
210210
-webkit-transform: translate3d(0, 0, 0); // fix iOS bug where relative children of scroller disapear while scrolling. see: http://stackoverflow.com/questions/9807620/ipad-safari-scrolling-causes-html-elements-to-disappear-and-reappear-with-a-dela
211211
}
212+
213+
&.keyboard-up {
214+
overflow: hidden;
215+
}
212216
}
213217

214218

0 commit comments

Comments
 (0)