mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
update types
This commit is contained in:
@@ -20,6 +20,26 @@
|
||||
* Note: Code inside of this if-block will
|
||||
* not run in an SSR environment.
|
||||
*/
|
||||
export const win: Window | undefined = typeof window !== 'undefined' ? window : undefined;
|
||||
|
||||
/**
|
||||
* Even listeners on the window typically expect
|
||||
* Event types for the listener parameter. If you want to listen
|
||||
* on the window for certain CustomEvent types you can add that definition
|
||||
* here as long as you are using the "win" utility below.
|
||||
*/
|
||||
type IonicWindow = Window & {
|
||||
addEventListener(
|
||||
type: 'ionKeyboardDidShow',
|
||||
listener: (ev: CustomEvent<{ keyboardHeight: number }>) => void,
|
||||
options?: boolean | AddEventListenerOptions
|
||||
): void;
|
||||
removeEventListener(
|
||||
type: 'ionKeyboardDidShow',
|
||||
listener: (ev: CustomEvent<{ keyboardHeight: number }>) => void,
|
||||
options?: boolean | AddEventListenerOptions
|
||||
): void;
|
||||
};
|
||||
|
||||
export const win: IonicWindow | undefined = typeof window !== 'undefined' ? window : undefined;
|
||||
|
||||
export const doc: Document | undefined = typeof document !== 'undefined' ? document : undefined;
|
||||
|
||||
@@ -13,18 +13,6 @@ let currentPadding = 0;
|
||||
|
||||
const SKIP_SCROLL_ASSIST = 'data-ionic-skip-scroll-assist';
|
||||
|
||||
/**
|
||||
* addEventListener typically expects an Event
|
||||
* type in the event listener callbacks. In this case
|
||||
* we have a CustomEvent, so we update the window event map
|
||||
* to register our specific event as well as the type of that event.
|
||||
*/
|
||||
declare global {
|
||||
interface WindowEventMap {
|
||||
ionKeyboardDidShow: CustomEvent<{ keyboardHeight: number }>;
|
||||
}
|
||||
}
|
||||
|
||||
export const enableScrollAssist = (
|
||||
componentEl: HTMLElement,
|
||||
inputEl: HTMLInputElement | HTMLTextAreaElement,
|
||||
@@ -135,7 +123,7 @@ export const enableScrollAssist = (
|
||||
*/
|
||||
const focusOut = () => {
|
||||
hasKeyboardBeenPresentedForTextField = false;
|
||||
window.removeEventListener('ionKeyboardDidShow', keyboardShow);
|
||||
win?.removeEventListener('ionKeyboardDidShow', keyboardShow);
|
||||
componentEl.removeEventListener('focusout', focusOut, true);
|
||||
};
|
||||
|
||||
@@ -166,7 +154,7 @@ export const enableScrollAssist = (
|
||||
platformHeight
|
||||
);
|
||||
|
||||
window.addEventListener('ionKeyboardDidShow', keyboardShow);
|
||||
win?.addEventListener('ionKeyboardDidShow', keyboardShow);
|
||||
componentEl.addEventListener('focusout', focusOut, true);
|
||||
};
|
||||
|
||||
@@ -174,7 +162,7 @@ export const enableScrollAssist = (
|
||||
|
||||
return () => {
|
||||
componentEl.removeEventListener('focusin', focusIn, true);
|
||||
window.removeEventListener('ionKeyboardDidShow', keyboardShow);
|
||||
win?.removeEventListener('ionKeyboardDidShow', keyboardShow);
|
||||
componentEl.removeEventListener('focusout', focusOut, true);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user