From 98a351941d8a2f53b715c303be4560d66298af1d Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Fri, 27 Apr 2018 01:16:43 +0200 Subject: [PATCH] fix(nav): rename animate to animated --- .../animation-controller/animator.tsx | 49 ++++--- core/src/components/datetime/datetime.tsx | 9 -- .../test/gesture-controller.spec.tsx | 1 + core/src/components/nav/nav-interface.ts | 2 +- core/src/components/nav/nav.tsx | 8 +- .../nav/test/nav-controller.spec.ts | 133 ++---------------- .../components/router-outlet/route-outlet.tsx | 2 +- core/src/components/router/router.tsx | 10 -- .../components/router/test/matching.spec.tsx | 110 --------------- core/src/utils/transition.ts | 2 +- 10 files changed, 43 insertions(+), 283 deletions(-) diff --git a/core/src/components/animation-controller/animator.tsx b/core/src/components/animation-controller/animator.tsx index 2b1e700d3b..4011711a75 100644 --- a/core/src/components/animation-controller/animator.tsx +++ b/core/src/components/animation-controller/animator.tsx @@ -702,11 +702,8 @@ export class Animator { } else if (tweenEffect) { // EVERYTHING IN BETWEEN - let valNum = (((toNum - fromNum) * stepValue) + fromNum); + const valNum = (((toNum - fromNum) * stepValue) + fromNum); const unit = fx.to.effectUnit; - if (unit === 'px') { - valNum = valNum; - } val = valNum + unit; } @@ -819,7 +816,6 @@ export class Animator { const addClasses = this._beforeAddClasses; const removeClasses = this._beforeRemoveClasses; - let prop: string; for (let i = 0; i < elements.length; i++) { const el = elements[i]; const elementClassList = el.classList; @@ -834,6 +830,7 @@ export class Animator { // css classes to remove before the animation if (removeClasses) { + for (let j = 0; j < removeClasses.length; j++) { // ******** DOM WRITE **************** elementClassList.remove(removeClasses[j]); @@ -842,7 +839,7 @@ export class Animator { // inline styles to add before the animation if (this._beforeStyles) { - for (prop in this._beforeStyles) { + for (const prop in this._beforeStyles) { // ******** DOM WRITE **************** (el as any).style[prop] = this._beforeStyles[prop]; } @@ -919,24 +916,27 @@ export class Animator { // finished in reverse direction // css classes that were added before the animation should be removed - if (this._beforeAddClasses) { - for (j = 0; j < this._beforeAddClasses.length; j++) { + const beforeAddClasses = this._beforeAddClasses; + if (beforeAddClasses) { + for (j = 0; j < beforeAddClasses.length; j++) { // ******** DOM WRITE **************** - elementClassList.remove(this._beforeAddClasses[j]); + elementClassList.remove(beforeAddClasses[j]); } } // css classes that were removed before the animation should be added - if (this._beforeRemoveClasses) { - for (j = 0; j < this._beforeRemoveClasses.length; j++) { + const beforeRemoveClasses = this._beforeRemoveClasses; + if (beforeRemoveClasses) { + for (j = 0; j < beforeRemoveClasses.length; j++) { // ******** DOM WRITE **************** - elementClassList.add(this._beforeRemoveClasses[j]); + elementClassList.add(beforeRemoveClasses[j]); } } // inline styles that were added before the animation should be removed - if (this._beforeStyles) { - for (prop in this._beforeStyles) { + const beforeStyles = this._beforeStyles; + if (beforeStyles) { + for (prop in beforeStyles) { // ******** DOM WRITE **************** (el as any).style[prop] = ''; } @@ -946,26 +946,29 @@ export class Animator { // finished in forward direction // css classes to add after the animation - if (this._afterAddClasses) { - for (j = 0; j < this._afterAddClasses.length; j++) { + const afterAddClasses = this._afterAddClasses; + if (afterAddClasses) { + for (j = 0; j < afterAddClasses.length; j++) { // ******** DOM WRITE **************** - elementClassList.add(this._afterAddClasses[j]); + elementClassList.add(afterAddClasses[j]); } } // css classes to remove after the animation - if (this._afterRemoveClasses) { - for (j = 0; j < this._afterRemoveClasses.length; j++) { + const afterRemoveClasses = this._afterRemoveClasses; + if (afterRemoveClasses) { + for (j = 0; j < afterRemoveClasses.length; j++) { // ******** DOM WRITE **************** - elementClassList.remove(this._afterRemoveClasses[j]); + elementClassList.remove(afterRemoveClasses[j]); } } // inline styles to add after the animation - if (this._afterStyles) { - for (prop in this._afterStyles) { + const afterStyles = this._afterStyles; + if (afterStyles) { + for (prop in afterStyles) { // ******** DOM WRITE **************** - (el as any).style[prop] = this._afterStyles[prop]; + (el as any).style[prop] = afterStyles[prop]; } } } diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index f49f5c6610..f158aaebb0 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -274,15 +274,6 @@ export class Datetime { const picker = this.pickerCtrl.create(pickerOptions); - // picker.ionChange.subscribe(() => { - // this.validate(); - // picker.refresh(); - // }); - - // picker.onDidDismiss(() => { - // this._fireBlur(); - // }); - console.debug('Built Datetime: Picker with', pickerOptions); return picker; } diff --git a/core/src/components/gesture-controller/test/gesture-controller.spec.tsx b/core/src/components/gesture-controller/test/gesture-controller.spec.tsx index 2c23b9ac9b..51df2fde0f 100644 --- a/core/src/components/gesture-controller/test/gesture-controller.spec.tsx +++ b/core/src/components/gesture-controller/test/gesture-controller.spec.tsx @@ -1,6 +1,7 @@ import { GestureController, } from '../gesture-controller'; describe('gesture controller', () => { + it('should create an instance of GestureController', () => { const c = new GestureController(); expect(c.isCaptured()).toEqual(false); diff --git a/core/src/components/nav/nav-interface.ts b/core/src/components/nav/nav-interface.ts index 320913fde1..82aa07cfed 100644 --- a/core/src/components/nav/nav-interface.ts +++ b/core/src/components/nav/nav-interface.ts @@ -16,7 +16,7 @@ export interface NavResult { } export interface RouterOutletOptions { - animate?: boolean; + animated?: boolean; animationBuilder?: AnimationBuilder; duration?: number; easing?: string; diff --git a/core/src/components/nav/nav.tsx b/core/src/components/nav/nav.tsx index af57cf5e7a..52c4da8802 100644 --- a/core/src/components/nav/nav.tsx +++ b/core/src/components/nav/nav.tsx @@ -154,8 +154,8 @@ export class Nav implements NavOutlet { opts = {}; } // if animation wasn't set to true then default it to NOT animate - if (opts.animate !== true) { - opts.animate = false; + if (opts.animated !== true) { + opts.animated = false; } return this.queueTrns({ insertStart: 0, @@ -199,7 +199,7 @@ export class Nav implements NavOutlet { } else if (direction === 1) { finish = this.push(id, params, commonOpts); } else if (direction === -1) { - finish = this.setRoot(id, params, {...commonOpts, direction: 'back', animate: true}); + finish = this.setRoot(id, params, {...commonOpts, direction: 'back', animated: true}); } else { finish = this.setRoot(id, params, commonOpts); } @@ -559,7 +559,7 @@ export class Nav implements NavOutlet { const leavingEl = leavingView && leavingView.element!; const animationOpts: TransitionOptions = { mode: this.mode, - animate: this.animated, + animated: this.animated, showGoBack: this.canGoBack(enteringView), animationCtrl: this.animationCtrl, progressCallback, diff --git a/core/src/components/nav/test/nav-controller.spec.ts b/core/src/components/nav/test/nav-controller.spec.ts index 19a6f16162..75f5c61426 100644 --- a/core/src/components/nav/test/nav-controller.spec.ts +++ b/core/src/components/nav/test/nav-controller.spec.ts @@ -22,7 +22,7 @@ describe('NavController', () => { // Push 1 const view1 = mockView(MockView1); - await nav.push(view1, null, {animate: false}, push1Done); + await nav.push(view1, null, {animated: false}, push1Done); const hasCompleted = true; const requiresTransition = true; @@ -34,7 +34,7 @@ describe('NavController', () => { // Push 2 const view2 = mockView(MockView2); - await nav.push(view2, null, {animate: false}, push2Done); + await nav.push(view2, null, {animated: false}, push2Done); expect(push2Done).toHaveBeenCalledWith( hasCompleted, requiresTransition, view2, view1, 'forward' @@ -46,7 +46,7 @@ describe('NavController', () => { // Push 3 const view3 = mockView(MockView3); - await nav.push(view3, null, {animate: false}, push3Done); + await nav.push(view3, null, {animated: false}, push3Done); expect(push3Done).toHaveBeenCalledWith( hasCompleted, requiresTransition, view3, view2, 'forward' @@ -58,7 +58,7 @@ describe('NavController', () => { // Push 4 const view4 = mockView(MockView4); - await nav.push(view4, null, {animate: false}, push4Done); + await nav.push(view4, null, {animated: false}, push4Done); expect(push4Done).toHaveBeenCalledWith( hasCompleted, requiresTransition, view4, view3, 'forward' ); @@ -69,7 +69,7 @@ describe('NavController', () => { expect(nav.getByIndex(3)!.component).toEqual(MockView4); // Pop 1 - await nav.pop({animate: false}, pop1Done); + await nav.pop({animated: false}, pop1Done); expect(pop1Done).toHaveBeenCalledWith( hasCompleted, requiresTransition, view3, view4, 'back' ); @@ -79,7 +79,7 @@ describe('NavController', () => { expect(nav.getByIndex(2)!.component).toEqual(MockView3); // Pop 2 - await nav.pop({animate: false}, pop2Done); + await nav.pop({animated: false}, pop2Done); expect(pop2Done).toHaveBeenCalledWith( hasCompleted, requiresTransition, view2, view3, 'back' ); @@ -88,7 +88,7 @@ describe('NavController', () => { expect(nav.getByIndex(1)!.component).toEqual(MockView2); // Pop 3 - await nav.pop({animate: false}, pop3Done); + await nav.pop({animated: false}, pop3Done); expect(pop3Done).toHaveBeenCalledWith( hasCompleted, requiresTransition, view1, view2, 'back' ); @@ -145,18 +145,14 @@ describe('NavController', () => { await nav.push(view2, null, null, trnsDone); - // expect(instance1.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance1.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance1.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).toHaveBeenCalled(); expect(instance1.ionViewWillLeave).toHaveBeenCalled(); expect(instance1.ionViewDidLeave).toHaveBeenCalled(); expect(instance1.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).toHaveBeenCalled(); expect(instance2.ionViewWillEnter).toHaveBeenCalled(); expect(instance2.ionViewDidEnter).toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance2.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillUnload).not.toHaveBeenCalled(); @@ -182,10 +178,8 @@ describe('NavController', () => { mockViews(nav, [mockView(MockView1), mockView(MockView2), mockView(MockView3)]); await nav.insert(0, view4, null, opts, trnsDone); - // expect(instance4.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance4.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance4.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance4.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance4.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance4.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance4.ionViewWillUnload).not.toHaveBeenCalled(); @@ -254,50 +248,6 @@ describe('NavController', () => { }); }, 10000); - // it('should not insert any view in the stack if canLeave returns false', async () => { - // const view1 = mockView(MockView1); - // const view2 = mockView(MockView2); - // const view3 = mockView(MockView3); - // mockViews(nav, [view1, view2]); - - // const instance2 = spyOnLifecycles(view2); - - // let count = 0; - // instance2.ionViewCanLeave = function () { - // count++; - // return (count === 3); - // }; - - // await nav.push(view3); - // expect(nav.length()).toEqual(2); - // await nav.push(view3); - // expect(nav.length()).toEqual(2); - // await nav.push(view3); - // expect(nav.length()).toEqual(3); - - // }, 10000); - - // it('should not remove any view from the stack if canLeave returns false', async () => { - // const view1 = mockView(MockView1); - // const view2 = mockView(MockView2); - // mockViews(nav, [view1, view2]); - - // const instance2 = spyOnLifecycles(view2); - - // let count = 0; - // instance2.ionViewCanLeave = function () { - // count++; - // return (count === 3); - // }; - - // await nav.pop(); - // expect(nav.length()).toEqual(2); - // await nav.pop(); - // expect(nav.length()).toEqual(2); - // await nav.pop(); - // expect(nav.length()).toEqual(1); - // }, 10000); - }); describe('insertPages', () => { @@ -314,10 +264,8 @@ describe('NavController', () => { const view5 = mockView(MockView5); await nav.insertPages(1, [view4, view5], null, trnsDone); - // expect(instance4.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance4.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance4.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance4.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance4.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance4.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance4.ionViewWillUnload).not.toHaveBeenCalled(); @@ -369,18 +317,14 @@ describe('NavController', () => { await nav.pop(null, trnsDone); - // expect(instance1.ionViewCanEnter).toHaveBeenCalled(); expect(instance1.ionViewWillEnter).toHaveBeenCalled(); expect(instance1.ionViewDidEnter).toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance1.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillUnload).not.toHaveBeenCalled(); - // expect).not.toHaveBeenCalled(); expect(instance2.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance2.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).toHaveBeenCalled(); expect(instance2.ionViewWillLeave).toHaveBeenCalled(); expect(instance2.ionViewDidLeave).toHaveBeenCalled(); expect(instance2.ionViewWillUnload).toHaveBeenCalled(); @@ -456,34 +400,26 @@ describe('NavController', () => { await nav.popTo(0, null, trnsDone); - // expect(instance1.ionViewCanEnter).toHaveBeenCalled(); expect(instance1.ionViewWillEnter).toHaveBeenCalled(); expect(instance1.ionViewDidEnter).toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance1.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance2.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance2.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).toHaveBeenCalled(); expect(instance2.ionViewDidLeave).toHaveBeenCalled(); expect(instance2.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance3.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance3.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance3.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance3.ionViewWillLeave).toHaveBeenCalled(); expect(instance3.ionViewDidLeave).toHaveBeenCalled(); expect(instance3.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance4.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance4.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance4.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance4.ionViewCanLeave).toHaveBeenCalled(); expect(instance4.ionViewWillLeave).toHaveBeenCalled(); expect(instance4.ionViewDidLeave).toHaveBeenCalled(); expect(instance4.ionViewWillUnload).toHaveBeenCalled(); @@ -516,34 +452,26 @@ describe('NavController', () => { await nav.popToRoot(null, trnsDone); - // expect(instance1.ionViewCanEnter).toHaveBeenCalled(); expect(instance1.ionViewWillEnter).toHaveBeenCalled(); expect(instance1.ionViewDidEnter).toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance1.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance2.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance2.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).toHaveBeenCalled(); expect(instance2.ionViewDidLeave).toHaveBeenCalled(); expect(instance2.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance3.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance3.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance3.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance3.ionViewWillLeave).toHaveBeenCalled(); expect(instance3.ionViewDidLeave).toHaveBeenCalled(); expect(instance3.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance4.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance4.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance4.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance4.ionViewCanLeave).toHaveBeenCalled(); expect(instance4.ionViewWillLeave).toHaveBeenCalled(); expect(instance4.ionViewDidLeave).toHaveBeenCalled(); expect(instance4.ionViewWillUnload).toHaveBeenCalled(); @@ -593,34 +521,26 @@ describe('NavController', () => { await nav.removeIndex(0, 3, null, trnsDone); - // expect(instance1.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance1.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance1.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).toHaveBeenCalled(); expect(instance1.ionViewDidLeave).toHaveBeenCalled(); expect(instance1.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance2.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance2.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).toHaveBeenCalled(); expect(instance2.ionViewDidLeave).toHaveBeenCalled(); expect(instance2.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance3.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance3.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance3.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance3.ionViewWillLeave).toHaveBeenCalled(); expect(instance3.ionViewDidLeave).toHaveBeenCalled(); expect(instance3.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance4.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance4.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance4.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance4.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance4.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance4.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance4.ionViewWillUnload).not.toHaveBeenCalled(); @@ -652,42 +572,32 @@ describe('NavController', () => { await nav.removeIndex(2, 2, null, trnsDone); - // expect(instance1.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance1.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance1.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance1.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance2.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance2.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance2.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance3.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance3.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance3.ionViewWillLeave).toHaveBeenCalled(); expect(instance3.ionViewDidLeave).toHaveBeenCalled(); expect(instance3.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance4.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance4.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance4.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance4.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance4.ionViewWillLeave).toHaveBeenCalled(); expect(instance4.ionViewDidLeave).toHaveBeenCalled(); expect(instance4.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance5.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance5.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance5.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance5.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance5.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance5.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance5.ionViewWillUnload).not.toHaveBeenCalled(); @@ -719,34 +629,26 @@ describe('NavController', () => { await nav.removeIndex(2, 2, null, trnsDone); - // expect(instance1.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance1.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance1.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance1.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).toHaveBeenCalled(); expect(instance2.ionViewWillEnter).toHaveBeenCalled(); expect(instance2.ionViewDidEnter).toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance2.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance3.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance3.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance3.ionViewWillLeave).toHaveBeenCalled(); expect(instance3.ionViewDidLeave).toHaveBeenCalled(); expect(instance3.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance4.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance4.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance4.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance4.ionViewCanLeave).toHaveBeenCalled(); expect(instance4.ionViewWillLeave).toHaveBeenCalled(); expect(instance4.ionViewDidLeave).toHaveBeenCalled(); expect(instance4.ionViewWillUnload).toHaveBeenCalled(); @@ -778,26 +680,20 @@ describe('NavController', () => { const instance3 = spyOnLifecycles(view3); await nav.setRoot(view3, null, null, trnsDone); - // expect(instance1.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance1.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance1.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).toHaveBeenCalled(); expect(instance1.ionViewDidLeave).toHaveBeenCalled(); expect(instance1.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance2.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance2.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).toHaveBeenCalled(); expect(instance2.ionViewDidLeave).toHaveBeenCalled(); expect(instance2.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance3.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance3.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance3.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance3.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance3.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance3.ionViewWillUnload).not.toHaveBeenCalled(); @@ -824,26 +720,20 @@ describe('NavController', () => { const instance3 = spyOnLifecycles(view3); await nav.setRoot(view2, null, null, trnsDone); - // expect(instance1.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance1.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance1.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).toHaveBeenCalled(); expect(instance1.ionViewDidLeave).toHaveBeenCalled(); expect(instance1.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).toHaveBeenCalled(); expect(instance2.ionViewWillEnter).toHaveBeenCalled(); expect(instance2.ionViewDidEnter).toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance2.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance3.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance3.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanLeave).toHaveBeenCalled(); expect(instance3.ionViewWillLeave).toHaveBeenCalled(); expect(instance3.ionViewDidLeave).toHaveBeenCalled(); expect(instance3.ionViewWillUnload).toHaveBeenCalled(); @@ -869,26 +759,20 @@ describe('NavController', () => { const instance3 = spyOnLifecycles(view3); await nav.setRoot(view1, null, null, trnsDone); - // expect(instance1.ionViewCanEnter).toHaveBeenCalled(); expect(instance1.ionViewWillEnter).toHaveBeenCalled(); expect(instance1.ionViewDidEnter).toHaveBeenCalled(); - // expect(instance1.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillLeave).not.toHaveBeenCalled(); expect(instance1.ionViewDidLeave).not.toHaveBeenCalled(); expect(instance1.ionViewWillUnload).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance2.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance2.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance2.ionViewCanLeave).not.toHaveBeenCalled(); expect(instance2.ionViewWillLeave).toHaveBeenCalled(); expect(instance2.ionViewDidLeave).toHaveBeenCalled(); expect(instance2.ionViewWillUnload).toHaveBeenCalled(); - // expect(instance3.ionViewCanEnter).not.toHaveBeenCalled(); expect(instance3.ionViewWillEnter).not.toHaveBeenCalled(); expect(instance3.ionViewDidEnter).not.toHaveBeenCalled(); - // expect(instance3.ionViewCanLeave).toHaveBeenCalled(); expect(instance3.ionViewWillLeave).toHaveBeenCalled(); expect(instance3.ionViewDidLeave).toHaveBeenCalled(); expect(instance3.ionViewWillUnload).toHaveBeenCalled(); @@ -1066,13 +950,14 @@ describe('NavController', () => { function mockNavController(): Nav { const nav = new Nav() as any; + nav.animated = false; nav.el = win.document.createElement('ion-nav'); nav.win = win; nav.ionNavDidChange = {emit: function() { return; } }; nav.ionNavWillChange = {emit: function() { return; } }; nav.animationCtrl = new AnimationControllerImpl() as any; - nav.config = new Config({animate: false}); + nav.config = new Config({animated: false}); nav._viewInit = function (enteringView: ViewController) { if (!enteringView.element) { console.log(enteringView.component); diff --git a/core/src/components/router-outlet/route-outlet.tsx b/core/src/components/router-outlet/route-outlet.tsx index d321830300..c589ebb04c 100644 --- a/core/src/components/router-outlet/route-outlet.tsx +++ b/core/src/components/router-outlet/route-outlet.tsx @@ -74,7 +74,7 @@ export class RouterOutlet implements NavOutlet { await transition({ mode: this.mode, - animate: this.animated, + animated: this.animated, animationCtrl: this.animationCtrl, window: this.win, enteringEl: enteringEl, diff --git a/core/src/components/router/router.tsx b/core/src/components/router/router.tsx index e39be91307..c12b549671 100644 --- a/core/src/components/router/router.tsx +++ b/core/src/components/router/router.tsx @@ -67,16 +67,6 @@ export class Router { this.init = true; console.debug('[ion-router] router did load'); - - // const tree = readRoutes(this.el); - // this.routes = flattenRouterTree(tree); - // this.redirects = readRedirects(this.el); - - // // TODO: use something else - // requestAnimationFrame(() => { - // this.historyDirection(); - // this.writeNavStateRoot(this.getPath(), RouterDirection.None); - // }); } @Listen('ionRouteRedirectChanged') diff --git a/core/src/components/router/test/matching.spec.tsx b/core/src/components/router/test/matching.spec.tsx index 1b936aa6b4..7a8323dc5f 100644 --- a/core/src/components/router/test/matching.spec.tsx +++ b/core/src/components/router/test/matching.spec.tsx @@ -292,113 +292,3 @@ describe('matchesRedirect', () => { }); }); - -// describe('matchRoute', () => { -// it('should match simple route', () => { -// const path = ['path', 'to', 'component']; -// const routes: RouteChain[] = [ -// [{ id: 2, path: ['to'], params: undefined }], -// [{ id: 1, path: ['path'], params: undefined }], -// [{ id: 3, path: ['segment'], params: undefined }], -// [{ id: 4, path: [''], params: undefined }], -// ]; -// const match = routerPathToChain(path, routes); -// expect(match).toEqual({ id: 1, path: ['path'], children: [] }); -// expect(seg.next()).toEqual('to'); -// }); - -// it('should match default route', () => { -// const routes: RouteTree = [ -// { id: 2, path: ['to'], children: [], params: undefined }, -// { id: 1, path: ['path'], children: [], params: undefined }, -// { id: 3, path: ['segment'], children: [], params: undefined }, -// { id: 4, path: [''], children: [], params: undefined }, -// ]; -// const seg = new RouterSegments(['hola', 'path']); -// let match = matchRoute(seg, routes); -// expect(match).toBeNull(); - -// match = matchRoute(seg, routes); -// expect(match.id).toEqual(1); - -// for (let i = 0; i < 20; i++) { -// match = matchRoute(seg, routes); -// expect(match.id).toEqual(4); -// } -// }); - -// it('should not match any route', () => { -// const routes: RouteTree = [ -// { id: 2, path: ['to', 'to', 'to'], children: [], params: undefined }, -// { id: 1, path: ['adam', 'manu'], children: [], params: undefined }, -// { id: 3, path: ['hola', 'adam'], children: [], params: undefined }, -// { id: 4, path: [''], children: [], params: undefined }, -// ]; -// const seg = new RouterSegments(['hola', 'manu', 'adam']); -// const match = matchRoute(seg, routes); -// expect(match).toBeNull(); -// }); - -// it('should not match if there are not routes', () => { -// const routes: RouteTree = []; -// const seg = new RouterSegments(['adam']); -// expect(matchRoute(seg, routes)).toBeNull(); -// expect(matchRoute(seg, routes)).toBeNull(); -// expect(matchRoute(seg, routes)).toBeNull(); -// }); - -// it('should not match any route (2)', () => { -// const routes: RouteTree = [ -// { id: 1, path: ['adam', 'manu'], children: [], params: undefined }, -// { id: 3, path: ['hola', 'adam'], children: [], params: undefined }, -// ]; -// const seg = new RouterSegments(['adam']); -// expect(matchRoute(seg, routes)).toBeNull(); -// expect(matchRoute(seg, routes)).toBeNull(); -// expect(matchRoute(seg, routes)).toBeNull(); -// }); - -// it ('should match multiple segments', () => { -// const routes: RouteTree = [ -// { id: 1, path: ['adam', 'manu'], children: [], params: undefined }, -// { id: 2, path: ['manu', 'hello'], children: [], params: undefined }, -// { id: 3, path: ['hello'], children: [], params: undefined }, -// { id: 4, path: [''], children: [], params: undefined }, -// ]; -// const seg = new RouterSegments(['adam', 'manu', 'hello', 'manu', 'hello']); -// let match = matchRoute(seg, routes); -// expect(match.id).toEqual(1); - -// match = matchRoute(seg, routes); -// expect(match.id).toEqual(3); - -// match = matchRoute(seg, routes); -// expect(match.id).toEqual(2); - -// match = matchRoute(seg, routes); -// expect(match.id).toEqual(4); - -// match = matchRoute(seg, routes); -// expect(match.id).toEqual(4); -// }); - -// it('should match long multi segments', () => { -// const routes: RouteTree = [ -// { id: 1, path: ['adam', 'manu', 'hello', 'menu', 'hello'], children: [], params: undefined }, -// { id: 2, path: ['adam', 'manu', 'hello', 'menu'], children: [], params: undefined }, -// { id: 3, path: ['adam', 'manu'], children: [], params: undefined }, -// ]; -// const seg = new RouterSegments(['adam', 'manu', 'hello', 'menu', 'hello']); -// const match = matchRoute(seg, routes); -// expect(match.id).toEqual(1); -// expect(matchRoute(seg, routes)).toBeNull(); -// }); - -// it('should match long multi segments', () => { -// let match = matchRoute(new RouterSegments(['']), null); -// expect(match).toBeNull(); - -// match = matchRoute(new RouterSegments(['hola']), null); -// expect(match).toBeNull(); -// }); -// }); diff --git a/core/src/utils/transition.ts b/core/src/utils/transition.ts index 0e4ba1f0eb..d28cb9c037 100644 --- a/core/src/utils/transition.ts +++ b/core/src/utils/transition.ts @@ -13,7 +13,7 @@ export function transition(opts: TransitionOptions): Promise { } function getAnimationBuilder(opts: TransitionOptions): AnimationBuilder | undefined { - if (!opts.leavingEl || opts.animate === false || opts.duration === 0) { + if (!opts.leavingEl || opts.animated === false || opts.duration === 0) { return undefined; } if (opts.animationBuilder) {