Skip to content

Commit e21c4d5

Browse files
committed
fix(keyboard): remove content padding after input blur
Closes #5800
1 parent 3cf4e52 commit e21c4d5

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

ionic/components/content/content.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Component, ElementRef, Optional, NgZone, ChangeDetectionStrategy, ViewEn
33
import {Ion} from '../ion';
44
import {IonicApp} from '../app/app';
55
import {Config} from '../../config/config';
6+
import {Keyboard} from '../../util/keyboard';
67
import {raf, transitionEnd, pointerCoord} from '../../util/dom';
78
import {ViewController} from '../nav/view-controller';
89
import {Animation} from '../../animations/animation';
@@ -38,6 +39,7 @@ import {ScrollView} from '../../util/scroll-view';
3839
})
3940
export class Content extends Ion {
4041
private _padding: number = 0;
42+
private _inputPolling: boolean = false;
4143
private _scroll: ScrollView;
4244
private _scLsn: Function;
4345
private _scrollEle: HTMLElement;
@@ -46,6 +48,7 @@ export class Content extends Ion {
4648
private _elementRef: ElementRef,
4749
private _config: Config,
4850
private _app: IonicApp,
51+
private _keyboard: Keyboard,
4952
private _zone: NgZone,
5053
@Optional() viewCtrl: ViewController
5154
) {
@@ -356,7 +359,7 @@ export class Content extends Ion {
356359
* Adds padding to the bottom of the scroll element when the keyboard is open
357360
* so content below the keyboard can be scrolled into view.
358361
*/
359-
addScrollPadding(newPadding) {
362+
addScrollPadding(newPadding: number) {
360363
if (newPadding > this._padding) {
361364
console.debug('content addScrollPadding', newPadding);
362365

@@ -365,4 +368,17 @@ export class Content extends Ion {
365368
}
366369
}
367370

371+
clearScrollPaddingFocusOut() {
372+
if (!this._inputPolling) {
373+
this._inputPolling = true;
374+
375+
this._keyboard.onClose(() => {
376+
this._padding = 0;
377+
this._scrollEle.style.paddingBottom = '';
378+
this._inputPolling = false;
379+
this.addScrollPadding(0);
380+
}, 200, Infinity);
381+
}
382+
}
383+
368384
}

ionic/components/input/input-base.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export class InputBase {
2121
protected _keyboardHeight;
2222
protected _scrollMove: EventListener;
2323
protected _type: string = 'text';
24-
protected _useAssist: boolean = true;
24+
protected _useAssist: boolean;
25+
protected _usePadding: boolean;
2526
protected _value = '';
2627
protected _isTouch: boolean;
2728
protected _autoFocusAssist: string;
@@ -47,8 +48,9 @@ export class InputBase {
4748
protected _nav: NavController,
4849
ngControl: NgControl
4950
) {
50-
this._useAssist = config.get('scrollAssist');
51-
this._keyboardHeight = config.get('keyboardHeight');
51+
this._useAssist = config.getBoolean('scrollAssist', false);
52+
this._usePadding = config.getBoolean('scrollPadding', this._useAssist);
53+
this._keyboardHeight = config.getNumber('keyboardHeight');
5254

5355
this._autoFocusAssist = config.get('autoFocusAssist', 'delay');
5456
this._autoComplete = config.get('autocomplete', 'off');
@@ -359,8 +361,10 @@ export class InputBase {
359361
return;
360362
}
361363

362-
// add padding to the bottom of the scroll view (if needed)
363-
scrollView.addScrollPadding(scrollData.scrollPadding);
364+
if (this._usePadding) {
365+
// add padding to the bottom of the scroll view (if needed)
366+
scrollView.addScrollPadding(scrollData.scrollPadding);
367+
}
364368

365369
// manually scroll the text input to the top
366370
// do not allow any clicks while it's scrolling
@@ -385,6 +389,10 @@ export class InputBase {
385389
this._app.setEnabled(true);
386390
this._nav && this._nav.setTransitioning(false);
387391
this.regScrollMove();
392+
393+
if (this._usePadding) {
394+
this._scrollView.clearScrollPaddingFocusOut();
395+
}
388396
});
389397

390398
} else {

ionic/util/keyboard.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class Keyboard {
7070
* @param {function} callback method you want to call when the keyboard has been closed
7171
* @return {function} returns a callback that gets fired when the keyboard is closed
7272
*/
73-
onClose(callback, pollingInternval = KEYBOARD_CLOSE_POLLING) {
73+
onClose(callback, pollingInternval = KEYBOARD_CLOSE_POLLING, pollingChecksMax = KEYBOARD_POLLING_CHECKS_MAX) {
7474
console.debug('keyboard onClose');
7575
const self = this;
7676
let checks = 0;
@@ -84,7 +84,7 @@ export class Keyboard {
8484

8585
function checkKeyboard() {
8686
console.debug('keyboard isOpen', self.isOpen(), checks);
87-
if (!self.isOpen() || checks > 100) {
87+
if (!self.isOpen() || checks > pollingChecksMax) {
8888
rafFrames(30, () => {
8989
self._zone.run(() => {
9090
console.debug('keyboard closed');
@@ -183,3 +183,4 @@ export class Keyboard {
183183
}
184184

185185
const KEYBOARD_CLOSE_POLLING = 150;
186+
const KEYBOARD_POLLING_CHECKS_MAX = 100;

0 commit comments

Comments
 (0)