|
340 | 340 | * into view.
|
341 | 341 | */
|
342 | 342 | self.scrollChildIntoView = function(e) {
|
| 343 | + var rect = container.getBoundingClientRect(); |
| 344 | + if(!self.__originalContainerHeight) { |
| 345 | + self.__originalContainerHeight = rect.height; |
| 346 | + } |
| 347 | + |
343 | 348 | // D
|
344 |
| - var scrollBottomOffsetToTop = container.getBoundingClientRect().bottom; |
| 349 | + var scrollBottomOffsetToTop = rect.bottom; |
345 | 350 | // D - A
|
346 |
| - scrollViewOffsetHeight = container.offsetHeight; |
| 351 | + scrollViewOffsetHeight = self.__originalContainerHeight; |
| 352 | + //console.log('Scroll view offset height', scrollViewOffsetHeight); |
| 353 | + //console.dir(container); |
347 | 354 | var alreadyShrunk = self.isShrunkForKeyboard;
|
348 | 355 |
|
349 | 356 | var isModal = container.parentNode.classList.contains('modal');
|
|
378 | 385 | var scrollBottomOffsetToBottom = e.detail.viewportHeight - scrollBottomOffsetToTop;
|
379 | 386 |
|
380 | 387 | // 0 or D - B if D > B E - B E - D
|
381 |
| - var keyboardOffset = e.detail.keyboardHeight - scrollBottomOffsetToBottom; |
| 388 | + //var keyboardOffset = e.detail.keyboardHeight - scrollBottomOffsetToBottom; |
382 | 389 |
|
383 | 390 | ionic.requestAnimationFrame(function(){
|
384 | 391 | // D - A or B - A if D > B D - A max(0, D - B)
|
385 |
| - scrollViewOffsetHeight = keyboardOffset >= 0 ? scrollViewOffsetHeight + keyboardOffset : scrollViewOffsetHeight - keyboardOffset; |
| 392 | + scrollViewOffsetHeight = Math.max(0, Math.min(self.__originalContainerHeight, self.__originalContainerHeight - (e.detail.keyboardHeight - 43)));//keyboardOffset >= 0 ? scrollViewOffsetHeight - keyboardOffset : scrollViewOffsetHeight + keyboardOffset; |
| 393 | + |
| 394 | + //console.log('Old container height', self.__originalContainerHeight, 'New container height', scrollViewOffsetHeight, 'Keyboard height', e.detail.keyboardHeight); |
386 | 395 |
|
387 | 396 | container.style.height = scrollViewOffsetHeight + "px";
|
388 | 397 |
|
| 398 | + /* |
| 399 | + if (ionic.Platform.isIOS()) { |
| 400 | + // Force redraw to avoid disappearing content |
| 401 | + var disp = container.style.display; |
| 402 | + container.style.display = 'none'; |
| 403 | + var trick = container.offsetHeight; |
| 404 | + container.style.display = disp; |
| 405 | + } |
| 406 | + */ |
389 | 407 | container.classList.add('keyboard-up');
|
390 | 408 | //update scroll view
|
391 | 409 | self.resize();
|
|
413 | 431 | if (e.detail.isElementUnderKeyboard) {
|
414 | 432 |
|
415 | 433 | ionic.requestAnimationFrame(function(){
|
| 434 | + var pos = ionic.DomUtil.getOffsetTop(e.detail.target); |
| 435 | + setTimeout(function() { |
| 436 | + if (ionic.Platform.isIOS()) { |
| 437 | + ionic.tap.cloneFocusedInput(container, self); |
| 438 | + } |
| 439 | + // Scroll the input into view, with a 100px buffer |
| 440 | + self.scrollTo(0, pos - (rect.top + 100), true); |
| 441 | + self.onScroll(); |
| 442 | + }, 32); |
| 443 | + |
| 444 | + /* |
416 | 445 | // update D if we shrunk
|
417 | 446 | if (self.isShrunkForKeyboard && !alreadyShrunk) {
|
418 | 447 | scrollBottomOffsetToTop = container.getBoundingClientRect().bottom;
|
| 448 | + console.log('Scroll bottom', scrollBottomOffsetToTop); |
419 | 449 | }
|
420 | 450 |
|
421 | 451 | // middle of the scrollview, this is where we want to scroll to
|
422 | 452 | // (D - A) / 2
|
423 | 453 | var scrollMidpointOffset = scrollViewOffsetHeight * 0.5;
|
| 454 | + console.log('Midpoint', scrollMidpointOffset); |
424 | 455 | //console.log("container.offsetHeight: " + scrollViewOffsetHeight);
|
425 | 456 |
|
426 | 457 | // middle of the input we want to scroll into view
|
427 | 458 | // C
|
428 | 459 | var inputMidpoint = ((e.detail.elementBottom + e.detail.elementTop) / 2);
|
| 460 | + console.log('Input midpoint'); |
429 | 461 |
|
430 | 462 | // distance from middle of input to the bottom of the scroll view
|
431 | 463 | // C - D C D
|
432 | 464 | var inputMidpointOffsetToScrollBottom = inputMidpoint - scrollBottomOffsetToTop;
|
| 465 | + console.log('Input midpoint offset', inputMidpointOffsetToScrollBottom); |
433 | 466 |
|
434 | 467 | //C - D + (D - A)/2 C - D (D - A)/ 2
|
435 | 468 | var scrollTop = inputMidpointOffsetToScrollBottom + scrollMidpointOffset;
|
| 469 | + console.log('Scroll top', scrollTop); |
436 | 470 |
|
437 | 471 | if ( scrollTop > 0) {
|
438 | 472 | if (ionic.Platform.isIOS()) {
|
|
447 | 481 | self.onScroll();
|
448 | 482 | }
|
449 | 483 | }
|
| 484 | + */ |
450 | 485 | });
|
451 | 486 | }
|
452 | 487 |
|
|
461 | 496 | self.isShrunkForKeyboard = false;
|
462 | 497 | container.style.height = "";
|
463 | 498 |
|
464 |
| - // Read after setting this to avoid rendering issues like white boxes. |
465 |
| - ionic.requestAnimationFrame(function() { |
466 |
| - container.classList.remove('keyboard-up'); |
467 |
| - }); |
| 499 | + /* |
| 500 | + if (ionic.Platform.isIOS()) { |
| 501 | + // Force redraw to avoid disappearing content |
| 502 | + var disp = container.style.display; |
| 503 | + container.style.display = 'none'; |
| 504 | + var trick = container.offsetHeight; |
| 505 | + container.style.display = disp; |
| 506 | + } |
| 507 | + */ |
| 508 | + |
| 509 | + self.__originalContainerHeight = container.getBoundingClientRect().height; |
| 510 | + |
| 511 | + if (ionic.Platform.isIOS()) { |
| 512 | + ionic.requestAnimationFrame(function() { |
| 513 | + container.classList.remove('keyboard-up'); |
| 514 | + }); |
| 515 | + } |
468 | 516 |
|
469 | 517 | }
|
470 | 518 | self.resize();
|
|
0 commit comments