Skip to content

Commit 373c0cd

Browse files
committed
fix(scroll): scroll inputs correctly with footer
1 parent e0c7979 commit 373c0cd

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

Diff for: js/utils/keyboard.js

-5
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ function keyboardShow(element, elementTop, elementBottom, viewportHeight, keyboa
144144

145145
console.log('keyboardShow', keyboardHeight, details.contentHeight);
146146

147-
// distance from top of input to the top of the keyboard
148-
details.keyboardTopOffset = details.elementTop - details.contentHeight;
149-
150-
console.log('keyboardTopOffset', details.elementTop, details.contentHeight, details.keyboardTopOffset);
151-
152147
// figure out if the element is under the keyboard
153148
details.isElementUnderKeyboard = (details.elementBottom > details.contentHeight);
154149

Diff for: js/views/scrollView.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -622,15 +622,19 @@ ionic.views.Scroll = ionic.views.View.inherit({
622622
//Broadcasted when keyboard is shown on some platforms.
623623
//See js/utils/keyboard.js
624624
container.addEventListener('scrollChildIntoView', function(e) {
625+
626+
//distance from bottom of scrollview to top of viewport
627+
var scrollBottomOffsetToTop;
628+
625629
if( !self.isScrolledIntoView ) {
626630
// shrink scrollview so we can actually scroll if the input is hidden
627631
// if it isn't shrink so we can scroll to inputs under the keyboard
628632
if (ionic.Platform.isIOS() || ionic.Platform.isFullScreen){
629633
// if there are things below the scroll view account for them and
630634
// 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);
634638
container.style.height = (container.clientHeight - keyboardOffset) + "px";
635639
container.style.overflow = "visible";
636640
//update scroll view
@@ -642,22 +646,33 @@ ionic.views.Scroll = ionic.views.View.inherit({
642646
//If the element is positioned under the keyboard...
643647
if( e.detail.isElementUnderKeyboard ) {
644648
var delay;
645-
// Wait on android for scroll view to resize
649+
// Wait on android for web view to resize
646650
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+
}
648659
}
649660
else {
650661
delay = 80;
651662
}
652663

653664
//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
655666
ionic.scroll.isScrolling = true;
656667
setTimeout(function(){
657668
//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;
661676
ionic.tap.cloneFocusedInput(container, self);
662677
self.scrollBy(0, scrollTop, true);
663678
self.onScroll();

0 commit comments

Comments
 (0)