mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
feat(vue): extend useIonRouter hook for programmatic navigation with animation control (#23499)
resolves #23450
This commit is contained in:
40
packages/vue/src/hooks/keyboard.ts
Normal file
40
packages/vue/src/hooks/keyboard.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { ref, Ref } from 'vue';
|
||||
|
||||
export interface UseKeyboardResult {
|
||||
isOpen: Ref<boolean>;
|
||||
keyboardHeight: Ref<number>;
|
||||
unregister: () => void
|
||||
}
|
||||
|
||||
export const useKeyboard = (): UseKeyboardResult => {
|
||||
let isOpen = ref(false);
|
||||
let keyboardHeight = ref(0);
|
||||
|
||||
const showCallback = (ev: CustomEvent) => {
|
||||
isOpen.value = true;
|
||||
keyboardHeight.value = ev.detail.keyboardHeight;
|
||||
}
|
||||
|
||||
const hideCallback = () => {
|
||||
isOpen.value = false;
|
||||
keyboardHeight.value = 0;
|
||||
}
|
||||
|
||||
const unregister = () => {
|
||||
if (typeof (window as any) !== 'undefined') {
|
||||
window.removeEventListener('ionKeyboardDidShow', showCallback);
|
||||
window.removeEventListener('ionKeyboardDidHide', hideCallback);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof (window as any) !== 'undefined') {
|
||||
window.addEventListener('ionKeyboardDidShow', showCallback);
|
||||
window.addEventListener('ionKeyboardDidHide', hideCallback);
|
||||
}
|
||||
|
||||
return {
|
||||
isOpen,
|
||||
keyboardHeight,
|
||||
unregister
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user