mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-15 17:42:15 +08:00
chore(): fix bad merge, update tests
This commit is contained in:
@ -1,112 +0,0 @@
|
|||||||
import { BackButtonEvent } from '@ionic/core';
|
|
||||||
import {
|
|
||||||
inject,
|
|
||||||
ref,
|
|
||||||
Ref,
|
|
||||||
ComponentInternalInstance,
|
|
||||||
getCurrentInstance
|
|
||||||
} from 'vue';
|
|
||||||
import { LifecycleHooks } from './utils';
|
|
||||||
|
|
||||||
type Handler = (processNextHandler: () => void) => Promise<any> | void | null;
|
|
||||||
|
|
||||||
export interface IonRouter {
|
|
||||||
canGoBack: (deep?: number) => boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IonKeyboardRef {
|
|
||||||
isOpen: Ref<boolean>;
|
|
||||||
keyboardHeight: Ref<number>;
|
|
||||||
unregister: () => void
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useBackButton = (priority: number, handler: Handler) => {
|
|
||||||
const callback = (ev: BackButtonEvent) => ev.detail.register(priority, handler);
|
|
||||||
const unregister = () => document.removeEventListener('ionBackButton', callback);
|
|
||||||
|
|
||||||
document.addEventListener('ionBackButton', callback);
|
|
||||||
|
|
||||||
return { unregister };
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useIonRouter = (): IonRouter => {
|
|
||||||
const { canGoBack } = inject('navManager') as any;
|
|
||||||
|
|
||||||
return {
|
|
||||||
canGoBack
|
|
||||||
} as IonRouter
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useKeyboard = (): IonKeyboardRef => {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an returns a function that
|
|
||||||
* can be used to provide a lifecycle hook.
|
|
||||||
*/
|
|
||||||
const injectHook = (lifecycleType: LifecycleHooks, hook: Function, component: ComponentInternalInstance | null): Function | undefined => {
|
|
||||||
if (component) {
|
|
||||||
|
|
||||||
// Add to public instance so it is accessible to IonRouterOutlet
|
|
||||||
const target = component as any;
|
|
||||||
const hooks = target.proxy[lifecycleType] || (target.proxy[lifecycleType] = []);
|
|
||||||
/**
|
|
||||||
* Define property on public instances using `setup` syntax in Vue 3.x
|
|
||||||
*/
|
|
||||||
if (target.exposed) {
|
|
||||||
target.exposed[lifecycleType] = hooks;
|
|
||||||
}
|
|
||||||
const wrappedHook = (...args: unknown[]) => {
|
|
||||||
if (target.isUnmounted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return args ? hook(...args) : hook();
|
|
||||||
};
|
|
||||||
|
|
||||||
hooks.push(wrappedHook);
|
|
||||||
|
|
||||||
return wrappedHook;
|
|
||||||
} else {
|
|
||||||
console.warn('[@ionic/vue]: Ionic Lifecycle Hooks can only be used during execution of setup().');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const createHook = <T extends Function = () => any>(lifecycle: LifecycleHooks) => {
|
|
||||||
return (hook: T, target: ComponentInternalInstance | null = getCurrentInstance()) => injectHook(lifecycle, hook, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const onIonViewWillEnter = createHook(LifecycleHooks.WillEnter);
|
|
||||||
export const onIonViewDidEnter = createHook(LifecycleHooks.DidEnter);
|
|
||||||
export const onIonViewWillLeave = createHook(LifecycleHooks.WillLeave);
|
|
||||||
export const onIonViewDidLeave = createHook(LifecycleHooks.DidLeave);
|
|
@ -11,6 +11,12 @@ const injectHook = (lifecycleType: LifecycleHooks, hook: Function, component: Co
|
|||||||
// Add to public instance so it is accessible to IonRouterOutlet
|
// Add to public instance so it is accessible to IonRouterOutlet
|
||||||
const target = component as any;
|
const target = component as any;
|
||||||
const hooks = target.proxy[lifecycleType] || (target.proxy[lifecycleType] = []);
|
const hooks = target.proxy[lifecycleType] || (target.proxy[lifecycleType] = []);
|
||||||
|
/**
|
||||||
|
* Define property on public instances using `setup` syntax in Vue 3.x
|
||||||
|
*/
|
||||||
|
if (target.exposed) {
|
||||||
|
target.exposed[lifecycleType] = hooks;
|
||||||
|
}
|
||||||
const wrappedHook = (...args: unknown[]) => {
|
const wrappedHook = (...args: unknown[]) => {
|
||||||
if (target.isUnmounted) {
|
if (target.isUnmounted) {
|
||||||
return;
|
return;
|
||||||
|
@ -276,15 +276,15 @@ describe('Tabs', () => {
|
|||||||
cy.ionPageVisible('tab1');
|
cy.ionPageVisible('tab1');
|
||||||
|
|
||||||
cy.get('#child-one-query-string').click();
|
cy.get('#child-one-query-string').click();
|
||||||
cy.ionPageVisible('tab1childone');
|
cy.ionPageVisible('tab1child-one');
|
||||||
cy.ionPageHidden('tab1');
|
cy.ionPageHidden('tab1');
|
||||||
|
|
||||||
cy.get('ion-tab-button#tab-button-tab2').click();
|
cy.get('ion-tab-button#tab-button-tab2').click();
|
||||||
cy.ionPageVisible('tab2');
|
cy.ionPageVisible('tab2');
|
||||||
cy.ionPageHidden('tab1childone');
|
cy.ionPageHidden('tab1child-one');
|
||||||
|
|
||||||
cy.get('ion-tab-button#tab-button-tab1').click();
|
cy.get('ion-tab-button#tab-button-tab1').click();
|
||||||
cy.ionPageVisible('tab1childone');
|
cy.ionPageVisible('tab1child-one');
|
||||||
cy.ionPageHidden('tab2');
|
cy.ionPageHidden('tab2');
|
||||||
|
|
||||||
cy.url().should('include', '/tabs/tab1/child-one?key=value');
|
cy.url().should('include', '/tabs/tab1/child-one?key=value');
|
||||||
|
Reference in New Issue
Block a user