1
1
import type { KeyboardResizeOptions } from '@capacitor/keyboard' ;
2
+ import { win } from '@utils/browser' ;
2
3
3
4
import { getScrollElement , scrollByPoint } from '../../content' ;
4
5
import { raf } from '../../helpers' ;
@@ -34,6 +35,21 @@ export const enableScrollAssist = (
34
35
const addScrollPadding =
35
36
enableScrollPadding && ( keyboardResize === undefined || keyboardResize . mode === KeyboardResize . None ) ;
36
37
38
+ /**
39
+ * When adding scroll padding we need to know
40
+ * how much of the viewport the keyboard obscures.
41
+ * We do this by subtracting the keyboard height
42
+ * from the platform height.
43
+ *
44
+ * If we compute this value when switching between
45
+ * inputs then the webview may already be resized.
46
+ * At this point, `win.innerHeight` has already accounted
47
+ * for the keyboard meaning we would then subtract
48
+ * the keyboard height again. This will result in the input
49
+ * being scrolled more than it needs to.
50
+ */
51
+ const platformHeight = win !== undefined ? win . innerHeight : 0 ;
52
+
37
53
/**
38
54
* When the input is about to receive
39
55
* focus, we need to move it to prevent
@@ -50,7 +66,16 @@ export const enableScrollAssist = (
50
66
inputEl . removeAttribute ( SKIP_SCROLL_ASSIST ) ;
51
67
return ;
52
68
}
53
- jsSetFocus ( componentEl , inputEl , contentEl , footerEl , keyboardHeight , addScrollPadding , disableClonedInput ) ;
69
+ jsSetFocus (
70
+ componentEl ,
71
+ inputEl ,
72
+ contentEl ,
73
+ footerEl ,
74
+ keyboardHeight ,
75
+ addScrollPadding ,
76
+ disableClonedInput ,
77
+ platformHeight
78
+ ) ;
54
79
} ;
55
80
componentEl . addEventListener ( 'focusin' , focusIn , true ) ;
56
81
@@ -84,12 +109,13 @@ const jsSetFocus = async (
84
109
footerEl : HTMLIonFooterElement | null ,
85
110
keyboardHeight : number ,
86
111
enableScrollPadding : boolean ,
87
- disableClonedInput = false
112
+ disableClonedInput = false ,
113
+ platformHeight = 0
88
114
) => {
89
115
if ( ! contentEl && ! footerEl ) {
90
116
return ;
91
117
}
92
- const scrollData = getScrollData ( componentEl , ( contentEl || footerEl ) ! , keyboardHeight ) ;
118
+ const scrollData = getScrollData ( componentEl , ( contentEl || footerEl ) ! , keyboardHeight , platformHeight ) ;
93
119
94
120
if ( contentEl && Math . abs ( scrollData . scrollAmount ) < 4 ) {
95
121
// the text input is in a safe position that doesn't
0 commit comments