@@ -622,15 +622,19 @@ ionic.views.Scroll = ionic.views.View.inherit({
622
622
//Broadcasted when keyboard is shown on some platforms.
623
623
//See js/utils/keyboard.js
624
624
container . addEventListener ( 'scrollChildIntoView' , function ( e ) {
625
+
626
+ //distance from bottom of scrollview to top of viewport
627
+ var scrollBottomOffsetToTop ;
628
+
625
629
if ( ! self . isScrolledIntoView ) {
626
630
// shrink scrollview so we can actually scroll if the input is hidden
627
631
// if it isn't shrink so we can scroll to inputs under the keyboard
628
632
if ( ionic . Platform . isIOS ( ) || ionic . Platform . isFullScreen ) {
629
633
// if there are things below the scroll view account for them and
630
634
// subtract them from the keyboard height when resizing
631
- var offsetToTop = container . getBoundingClientRect ( ) . bottom ;
632
- var offsetToBottom = e . detail . viewportHeight - offsetToTop ;
633
- var keyboardOffset = Math . max ( 0 , e . detail . keyboardHeight - offsetToBottom ) ;
635
+ scrollBottomOffsetToTop = container . getBoundingClientRect ( ) . bottom ;
636
+ var scrollBottomOffsetToBottom = e . detail . viewportHeight - scrollBottomOffsetToTop ;
637
+ var keyboardOffset = Math . max ( 0 , e . detail . keyboardHeight - scrollBottomOffsetToBottom ) ;
634
638
container . style . height = ( container . clientHeight - keyboardOffset ) + "px" ;
635
639
container . style . overflow = "visible" ;
636
640
//update scroll view
@@ -642,22 +646,33 @@ ionic.views.Scroll = ionic.views.View.inherit({
642
646
//If the element is positioned under the keyboard...
643
647
if ( e . detail . isElementUnderKeyboard ) {
644
648
var delay ;
645
- // Wait on android for scroll view to resize
649
+ // Wait on android for web view to resize
646
650
if ( ionic . Platform . isAndroid ( ) && ! ionic . Platform . isFullScreen ) {
647
- delay = 350 ;
651
+ // android y u resize so slow
652
+ if ( ionic . Platform . version ( ) < 4.4 ) {
653
+ delay = 500 ;
654
+ }
655
+ else {
656
+ // probably overkill for chrome
657
+ delay = 350 ;
658
+ }
648
659
}
649
660
else {
650
661
delay = 80 ;
651
662
}
652
663
653
664
//Put element in middle of visible screen
654
- //Wait for resize() to reset scroll position
665
+ //Wait for android to update view height and resize() to reset scroll position
655
666
ionic . scroll . isScrolling = true ;
656
667
setTimeout ( function ( ) {
657
668
//middle of the scrollview, where we want to scroll to
658
- var scrollViewMidpointOffset = container . clientHeight * 0.5 ;
659
- var scrollTop = e . detail . keyboardTopOffset + scrollViewMidpointOffset ;
660
- console . log ( 'scrollChildIntoView' , scrollTop ) ;
669
+ var scrollMidpointOffset = container . clientHeight * 0.5 ;
670
+
671
+ scrollBottomOffsetToTop = container . getBoundingClientRect ( ) . bottom ;
672
+ //distance from top of focused element to the bottom of the scroll view
673
+ var elementTopOffsetToScrollBottom = e . detail . elementTop - scrollBottomOffsetToTop ;
674
+
675
+ var scrollTop = elementTopOffsetToScrollBottom + scrollMidpointOffset ;
661
676
ionic . tap . cloneFocusedInput ( container , self ) ;
662
677
self . scrollBy ( 0 , scrollTop , true ) ;
663
678
self . onScroll ( ) ;
0 commit comments