Skip to content

Commit

Permalink
fix(input): stop ios from hiding keyboard on focus change
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartington committed Dec 6, 2016
1 parent 6c0593c commit 5bcd7f2
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/util/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core';

import { Config } from '../config/config';
import { DomController } from './dom-controller';
import { focusOutActiveElement, hasFocusedTextInput, nativeTimeout } from './dom';
import { focusOutActiveElement, hasFocusedTextInput, nativeTimeout, clearNativeTimeout } from './dom';
import { Key } from './key';


Expand All @@ -23,19 +23,28 @@ import { Key } from './key';
*/
@Injectable()
export class Keyboard {
private _tmr: any;

constructor(config: Config, private _zone: NgZone, private _dom: DomController) {
_zone.runOutsideAngular(() => {
this.focusOutline(config.get('focusOutline'), document);

window.addEventListener('native.keyboardhide', () => {
// this custom cordova plugin event fires when the keyboard will hide
// useful when the virtual keyboard is closed natively
// https://github.com/driftyco/ionic-plugin-keyboard
if (hasFocusedTextInput()) {
focusOutActiveElement();
}
clearNativeTimeout(this._tmr);
this._tmr = nativeTimeout(() => {
// this custom cordova plugin event fires when the keyboard will hide
// useful when the virtual keyboard is closed natively
// https://github.com/driftyco/ionic-plugin-keyboard
if (hasFocusedTextInput()) {
focusOutActiveElement();
}
}, 80);
});

window.addEventListener('native.keyboardshow', () => {
clearNativeTimeout(this._tmr);
});

});
}

Expand Down

1 comment on commit 5bcd7f2

@biesbjerg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 👍

Please sign in to comment.