MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / startInputShims

Function startInputShims

core/src/utils/input-shims/input-shims.ts:16–142  ·  view source on GitHub ↗
(config: Config, platform: 'ios' | 'android')

Source from the content-addressed store, hash-verified

14const HIDE_CARET = true;
15
16export const startInputShims = async (config: Config, platform: 'ios' | 'android') => {
17 /**
18 * If doc is undefined then we are in an SSR environment
19 * where input shims do not apply.
20 */
21 if (doc === undefined) {
22 return;
23 }
24
25 const isIOS = platform === 'ios';
26 const isAndroid = platform === 'android';
27
28 /**
29 * Hide Caret and Input Blurring are needed on iOS.
30 * Scroll Assist and Scroll Padding are needed on iOS and Android
31 * with Chrome web browser (not Chrome webview).
32 */
33 const keyboardHeight = config.getNumber('keyboardHeight', 290);
34 const scrollAssist = config.getBoolean('scrollAssist', true);
35 const hideCaret = config.getBoolean('hideCaretOnScroll', isIOS);
36
37 /**
38 * The team is evaluating if inputBlurring is still needed. As a result
39 * this feature is disabled by default as of Ionic 8.0. Developers are
40 * able to re-enable it temporarily. The team may remove this utility
41 * if it is determined that doing so would not bring any adverse side effects.
42 * TODO FW-6014 remove input blurring utility (including implementation)
43 */
44 const inputBlurring = config.getBoolean('inputBlurring', false);
45 const scrollPadding = config.getBoolean('scrollPadding', true);
46 const inputs = Array.from(doc.querySelectorAll('ion-input, ion-textarea')) as HTMLElement[];
47
48 const hideCaretMap = new WeakMap<HTMLElement, () => void>();
49 const scrollAssistMap = new WeakMap<HTMLElement, () => void>();
50
51 /**
52 * Grab the native keyboard resize configuration
53 * and pass it to scroll assist. Scroll assist requires
54 * that we adjust the input right before the input
55 * is about to be focused. If we called `Keyboard.getResizeMode`
56 * on focusin in scroll assist, we could potentially adjust the
57 * input too late since this call is async.
58 */
59 const keyboardResizeMode = await Keyboard.getResizeMode();
60
61 const registerInput = async (componentEl: HTMLElement) => {
62 await new Promise((resolve) => componentOnReady(componentEl, resolve));
63
64 const inputRoot = componentEl.shadowRoot || componentEl;
65 const inputEl = inputRoot.querySelector('input') || inputRoot.querySelector('textarea');
66 const scrollEl = findClosestIonContent(componentEl);
67 const footerEl = !scrollEl ? (componentEl.closest('ion-footer') as HTMLIonFooterElement | null) : null;
68
69 if (!inputEl) {
70 return;
71 }
72
73 if (HIDE_CARET && !!scrollEl && hideCaret && !hideCaretMap.has(componentEl)) {

Callers

nothing calls this directly

Calls 7

enableInputBlurringFunction · 0.90
registerInputFunction · 0.85
unregisterInputFunction · 0.85
fromMethod · 0.80
addEventListenerMethod · 0.65
getNumberMethod · 0.45
getBooleanMethod · 0.45

Tested by

no test coverage detected