@@ -59,6 +59,12 @@ export const enableScrollAssist = (
59
59
*/
60
60
let platformHeight = win !== undefined ? win . innerHeight : 0 ;
61
61
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
+
62
68
/**
63
69
* Scroll assist is run when a text field
64
70
* is focused. However, it may need to
@@ -81,6 +87,13 @@ export const enableScrollAssist = (
81
87
const keyboardShow = ( ev : CustomEvent < { keyboardHeight : number } > ) => {
82
88
const { keyboardHeight } = ev . detail ;
83
89
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
+
84
97
/**
85
98
* If the keyboard has not yet been presented
86
99
* for this text field then the text field has just
@@ -89,33 +102,28 @@ export const enableScrollAssist = (
89
102
*/
90
103
if ( hasKeyboardBeenPresentedForTextField === false ) {
91
104
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 ;
98
105
return ;
99
106
}
100
107
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).
110
119
*/
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 ;
119
127
}
120
128
121
129
/**
0 commit comments