feat(vue): extend useIonRouter hook for programmatic navigation with animation control (#23499)

resolves #23450
This commit is contained in:
Liam DeBeasi
2021-06-28 10:33:32 -04:00
committed by GitHub
parent 79e3a26499
commit fc9e1b4b36
10 changed files with 456 additions and 132 deletions

View 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
}
}