Skip to content

Commit 7ca6214

Browse files
committed
test a fix
1 parent d868b6b commit 7ca6214

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

core/src/utils/input-shims/hacks/scroll-assist.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ export const enableScrollAssist = (
5959
*/
6060
let platformHeight = win !== undefined ? win.innerHeight : 0;
6161

62+
/**
63+
* The initial platform height is used to determine the platform
64+
* height when the webview is fullscreen/the keyboard is closed.
65+
*/
66+
const initialPlatformHeight = platformHeight;
67+
6268
/**
6369
* Scroll assist is run when a text field
6470
* is focused. However, it may need to
@@ -81,6 +87,13 @@ export const enableScrollAssist = (
8187
const keyboardShow = (ev: CustomEvent<{ keyboardHeight: number }>) => {
8288
const { keyboardHeight } = ev.detail;
8389

90+
/**
91+
* platformHeight is recomputed every time the keyboard shows
92+
* to account for any device rotations (i.e. rotating from portrait
93+
* to landscape). This ensures we are using an accurate platform height.
94+
*/
95+
platformHeight = win !== undefined ? win.innerHeight: 0;
96+
8497
/**
8598
* If the keyboard has not yet been presented
8699
* for this text field then the text field has just
@@ -89,33 +102,28 @@ export const enableScrollAssist = (
89102
*/
90103
if (hasKeyboardBeenPresentedForTextField === false) {
91104
hasKeyboardBeenPresentedForTextField = true;
92-
93-
/**
94-
* The platform height is the innerHeight of the window
95-
* because the webview has not resize yet.
96-
*/
97-
platformHeight = win !== undefined ? win.innerHeight : 0;
98105
return;
99106
}
100107

101-
/**
102-
* platformHeight is recomputed every time the keyboard shows
103-
* to account for any device rotations (i.e. rotating from portrait
104-
* to landscape). This ensures we are using an accurate platform height.
105-
*
106-
* If we are using the Native keyboard resize behavior and
107-
* the keyboard was already shown then the webview has already resized.
108-
* In order to compute the correct platform height (before the keyboard was shown)
109-
* we need to add the keyboard height to window.innerHeight.
108+
109+
/*
110+
* If we are using the Native keyboard resize behavior then
111+
* the webview will resize when the keyboard is shown. However,
112+
* this happens asynchronously so the webview is not guaranteed
113+
* to have resized by the time the keyboard show event is fired.
114+
* If current platform height is NOT equal to the initial platform height
115+
* (i.e. the platform height when the keyboard is guaranteed to be closed/the
116+
* webview is fullsize) then it's possible that the webview has resized.
117+
* In that case we add the keyboard height to get the real platform height (the
118+
* height when the keyboard is closed).
110119
*/
111-
if (keyboardResize !== undefined && keyboardResize.mode === KeyboardResize.Native) {
112-
platformHeight = win !== undefined ? win.innerHeight + keyboardHeight : 0;
113-
/**
114-
* Otherwise the webview does not resize and we can use window.innerHeight
115-
* as we normally would.
116-
*/
117-
} else {
118-
platformHeight = win !== undefined ? win.innerHeight : 0;
120+
if (
121+
keyboardResize !== undefined &&
122+
keyboardResize.mode === KeyboardResize.Native &&
123+
win !== undefined &&
124+
platformHeight !== initialPlatformHeight
125+
) {
126+
platformHeight += keyboardHeight;
119127
}
120128

121129
/**

0 commit comments

Comments
 (0)