Skip to content

Commit

Permalink
test a fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdebeasi committed Sep 14, 2023
1 parent d868b6b commit 7ca6214
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions core/src/utils/input-shims/hacks/scroll-assist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export const enableScrollAssist = (
*/
let platformHeight = win !== undefined ? win.innerHeight : 0;

/**
* The initial platform height is used to determine the platform
* height when the webview is fullscreen/the keyboard is closed.
*/
const initialPlatformHeight = platformHeight;

/**
* Scroll assist is run when a text field
* is focused. However, it may need to
Expand All @@ -81,6 +87,13 @@ export const enableScrollAssist = (
const keyboardShow = (ev: CustomEvent<{ keyboardHeight: number }>) => {
const { keyboardHeight } = ev.detail;

/**
* platformHeight is recomputed every time the keyboard shows
* to account for any device rotations (i.e. rotating from portrait
* to landscape). This ensures we are using an accurate platform height.
*/
platformHeight = win !== undefined ? win.innerHeight: 0;

/**
* If the keyboard has not yet been presented
* for this text field then the text field has just
Expand All @@ -89,33 +102,28 @@ export const enableScrollAssist = (
*/
if (hasKeyboardBeenPresentedForTextField === false) {
hasKeyboardBeenPresentedForTextField = true;

/**
* The platform height is the innerHeight of the window
* because the webview has not resize yet.
*/
platformHeight = win !== undefined ? win.innerHeight : 0;
return;
}

/**
* platformHeight is recomputed every time the keyboard shows
* to account for any device rotations (i.e. rotating from portrait
* to landscape). This ensures we are using an accurate platform height.
*
* If we are using the Native keyboard resize behavior and
* the keyboard was already shown then the webview has already resized.
* In order to compute the correct platform height (before the keyboard was shown)
* we need to add the keyboard height to window.innerHeight.

/*
* If we are using the Native keyboard resize behavior then
* the webview will resize when the keyboard is shown. However,
* this happens asynchronously so the webview is not guaranteed
* to have resized by the time the keyboard show event is fired.
* If current platform height is NOT equal to the initial platform height
* (i.e. the platform height when the keyboard is guaranteed to be closed/the
* webview is fullsize) then it's possible that the webview has resized.
* In that case we add the keyboard height to get the real platform height (the
* height when the keyboard is closed).
*/
if (keyboardResize !== undefined && keyboardResize.mode === KeyboardResize.Native) {
platformHeight = win !== undefined ? win.innerHeight + keyboardHeight : 0;
/**
* Otherwise the webview does not resize and we can use window.innerHeight
* as we normally would.
*/
} else {
platformHeight = win !== undefined ? win.innerHeight : 0;
if (
keyboardResize !== undefined &&
keyboardResize.mode === KeyboardResize.Native &&
win !== undefined &&
platformHeight !== initialPlatformHeight
) {
platformHeight += keyboardHeight;
}

/**
Expand Down

0 comments on commit 7ca6214

Please sign in to comment.