Skip to content
Permalink
Browse files

fix(input): keep entire input in view when scrolling with keyboard op…

…en (#18253)

fixes #17457
  • Loading branch information...
pegler authored and brandyscarney committed May 14, 2019
1 parent ba0def3 commit 3cad7787c27d34d5bde0b831b04f01c38808effb
Showing with 6 additions and 2 deletions.
  1. +6 −2 core/src/utils/input-shims/hacks/scroll-data.ts
@@ -40,13 +40,17 @@ function calcScrollData(
const distanceToBottom = safeAreaBottom - inputBottom;
const distanceToTop = safeAreaTop - inputTop;

// The scrollAmount is the negated distance to the safe area.
const scrollAmount = Math.round((distanceToBottom < 0)
// desiredScrollAmount is the negated distance to the safe area according to our calculations.
const desiredScrollAmount = Math.round((distanceToBottom < 0)
? -distanceToBottom
: (distanceToTop > 0)
? -distanceToTop
: 0);

// our calculations make some assumptions that aren't always true, like the keyboard being closed when an input
// gets focus, so make sure we don't scroll the input above the visible area
const scrollAmount = Math.min(desiredScrollAmount, inputTop - visibleAreaTop);

const distance = Math.abs(scrollAmount);
const duration = distance / SCROLL_ASSIST_SPEED;
const scrollDuration = Math.min(400, Math.max(150, duration));

0 comments on commit 3cad778

Please sign in to comment.
You can’t perform that action at this time.