@@ -297,6 +297,7 @@ function keyboardFocusIn(e) {
297
297
e . target . readOnly ||
298
298
! ionic . tap . isKeyboardElement ( e . target ) ||
299
299
! ( scrollView = inputScrollView ( e . target ) ) ) {
300
+ keyboardActiveElement = null ;
300
301
return ;
301
302
}
302
303
@@ -527,9 +528,11 @@ function keyboardHide() {
527
528
ionic . keyboard . isOpen = false ;
528
529
ionic . keyboard . isClosing = false ;
529
530
530
- ionic . trigger ( 'resetScrollView' , {
531
- target : keyboardActiveElement
532
- } , true ) ;
531
+ if ( keyboardActiveElement ) {
532
+ ionic . trigger ( 'resetScrollView' , {
533
+ target : keyboardActiveElement
534
+ } , true ) ;
535
+ }
533
536
534
537
ionic . requestAnimationFrame ( function ( ) {
535
538
document . body . classList . remove ( KEYBOARD_OPEN_CSS ) ;
@@ -549,6 +552,8 @@ function keyboardHide() {
549
552
if ( keyboardHasPlugin ( ) ) cordova . plugins . Keyboard . close ( ) ;
550
553
keyboardActiveElement && keyboardActiveElement . blur ( ) ;
551
554
}
555
+
556
+ keyboardActiveElement = null ;
552
557
}
553
558
554
559
/**
@@ -557,36 +562,40 @@ function keyboardHide() {
557
562
* the currently focused input into view if necessary.
558
563
*/
559
564
function keyboardShow ( ) {
560
- var elementBounds = keyboardActiveElement . getBoundingClientRect ( ) ;
565
+
566
+ ionic . keyboard . isOpen = true ;
567
+ ionic . keyboard . isOpening = false ;
568
+
561
569
var details = {
562
- target : keyboardActiveElement ,
563
- elementTop : Math . round ( elementBounds . top ) ,
564
- elementBottom : Math . round ( elementBounds . bottom ) ,
565
570
keyboardHeight : keyboardGetHeight ( ) ,
566
571
viewportHeight : keyboardCurrentViewportHeight
567
572
} ;
568
573
569
- details . windowHeight = details . viewportHeight - details . keyboardHeight ;
570
- //console.log("keyboardShow viewportHeight: " + details.viewportHeight +
571
- //", windowHeight: " + details.windowHeight +
572
- //", keyboardHeight: " + details.keyboardHeight);
574
+ if ( keyboardActiveElement ) {
575
+ details . target = keyboardActiveElement ;
573
576
574
- // figure out if the element is under the keyboard
575
- details . isElementUnderKeyboard = ( details . elementBottom > details . windowHeight ) ;
576
- //console.log("isUnderKeyboard: " + details.isElementUnderKeyboard);
577
- //console.log("elementBottom: " + details.elementBottom);
577
+ var elementBounds = keyboardActiveElement . getBoundingClientRect ( ) ;
578
578
579
- ionic . keyboard . isOpen = true ;
580
- ionic . keyboard . isOpening = false ;
579
+ details . elementTop = Math . round ( elementBounds . top ) ;
580
+ details . elementBottom = Math . round ( elementBounds . bottom ) ;
581
+
582
+ details . windowHeight = details . viewportHeight - details . keyboardHeight ;
583
+ //console.log("keyboardShow viewportHeight: " + details.viewportHeight +
584
+ //", windowHeight: " + details.windowHeight +
585
+ //", keyboardHeight: " + details.keyboardHeight);
586
+
587
+ // figure out if the element is under the keyboard
588
+ details . isElementUnderKeyboard = ( details . elementBottom > details . windowHeight ) ;
589
+ //console.log("isUnderKeyboard: " + details.isElementUnderKeyboard);
590
+ //console.log("elementBottom: " + details.elementBottom);
581
591
582
- // send event so the scroll view adjusts
583
- ionic . trigger ( 'scrollChildIntoView' , details , true ) ;
592
+ // send event so the scroll view adjusts
593
+ ionic . trigger ( 'scrollChildIntoView' , details , true ) ;
594
+ }
584
595
585
596
setTimeout ( function ( ) {
586
597
document . body . classList . add ( KEYBOARD_OPEN_CSS ) ;
587
598
} , 400 ) ;
588
-
589
- return details ;
590
599
}
591
600
592
601
/* eslint no-unused-vars:0 */
@@ -654,9 +663,11 @@ function keyboardUpdateViewportHeight() {
654
663
keyboardPortraitViewportHeight = keyboardCurrentViewportHeight ;
655
664
}
656
665
657
- ionic . trigger ( 'resetScrollView' , {
658
- target : keyboardActiveElement
659
- } , true ) ;
666
+ if ( keyboardActiveElement ) {
667
+ ionic . trigger ( 'resetScrollView' , {
668
+ target : keyboardActiveElement
669
+ } , true ) ;
670
+ }
660
671
661
672
if ( ionic . keyboard . isOpen && ionic . tap . isTextInput ( keyboardActiveElement ) ) {
662
673
keyboardShow ( ) ;
0 commit comments