transition runs outside of angular

This commit is contained in:
Adam Bradley
2015-08-18 15:09:01 -05:00
parent ea28263602
commit 554b1b2d9a
4 changed files with 56 additions and 45 deletions

View File

@ -1,4 +1,4 @@
import {Directive, View, ElementRef, Host, Optional, forwardRef, Injector} from 'angular2/angular2'; import {Directive, View, ElementRef, Host, Optional, forwardRef, Injector, NgZone} from 'angular2/angular2';
import {IonicComponent} from '../../config/annotations'; import {IonicComponent} from '../../config/annotations';
import {ViewController} from '../view/view-controller'; import {ViewController} from '../view/view-controller';
@ -22,9 +22,10 @@ export class Nav extends ViewController {
constructor( constructor(
@Optional() hostViewCtrl: ViewController, @Optional() hostViewCtrl: ViewController,
injector: Injector, injector: Injector,
elementRef: ElementRef elementRef: ElementRef,
zone: NgZone
) { ) {
super(hostViewCtrl, injector, elementRef); super(hostViewCtrl, injector, elementRef, zone);
} }
onIonInit() { onIonInit() {

View File

@ -1,4 +1,4 @@
import {Directive, Component, View, Host, ElementRef, forwardRef, Injector} from 'angular2/angular2'; import {Directive, Component, View, Host, ElementRef, forwardRef, Injector, NgZone} from 'angular2/angular2';
import {ViewController} from '../view/view-controller'; import {ViewController} from '../view/view-controller';
import {ViewItem} from '../view/view-item'; import {ViewItem} from '../view/view-item';
@ -29,12 +29,13 @@ export class Tab extends ViewController {
constructor( constructor(
@Host() tabs: Tabs, @Host() tabs: Tabs,
elementRef: ElementRef, elementRef: ElementRef,
injector: Injector injector: Injector,
zone: NgZone
) { ) {
// A Tab is both a container of many views, and is a view itself. // A Tab is both a container of many views, and is a view itself.
// A Tab is one ViewItem within it's Host Tabs (which extends ViewController) // A Tab is one ViewItem within it's Host Tabs (which extends ViewController)
// A Tab is a ViewController for its child ViewItems // A Tab is a ViewController for its child ViewItems
super(tabs, injector, elementRef); super(tabs, injector, elementRef, zone);
this.tabs = tabs; this.tabs = tabs;
this.childNavbar(true); this.childNavbar(true);

View File

@ -1,4 +1,4 @@
import {Component, Directive, View, Injector, NgFor, ElementRef, Optional, Host, forwardRef} from 'angular2/angular2'; import {Component, Directive, View, Injector, NgFor, ElementRef, Optional, Host, forwardRef, NgZone} from 'angular2/angular2';
import {ViewController} from '../view/view-controller'; import {ViewController} from '../view/view-controller';
import {ViewItem} from '../view/view-item'; import {ViewItem} from '../view/view-item';
@ -33,9 +33,10 @@ export class Tabs extends ViewController {
@Optional() hostViewCtrl: ViewController, @Optional() hostViewCtrl: ViewController,
@Optional() viewItem: ViewItem, @Optional() viewItem: ViewItem,
injector: Injector, injector: Injector,
elementRef: ElementRef elementRef: ElementRef,
zone: NgZone
) { ) {
super(hostViewCtrl, injector, elementRef); super(hostViewCtrl, injector, elementRef, zone);
// Tabs may also be an actual ViewItem which was navigated to // Tabs may also be an actual ViewItem which was navigated to
// if Tabs is static and not navigated to within a ViewController // if Tabs is static and not navigated to within a ViewController

View File

@ -1,4 +1,4 @@
import {Compiler, ElementRef, Injector, bind} from 'angular2/angular2'; import {Compiler, ElementRef, Injector, bind, NgZone} from 'angular2/angular2';
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader'; import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager'; import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
@ -19,7 +19,8 @@ export class ViewController extends Ion {
constructor( constructor(
parentViewCtrl: ViewController, parentViewCtrl: ViewController,
injector: Injector, injector: Injector,
elementRef: ElementRef elementRef: ElementRef,
zone: NgZone
) { ) {
let config = injector.get(IonicConfig); let config = injector.get(IonicConfig);
super(elementRef, config); super(elementRef, config);
@ -32,6 +33,7 @@ export class ViewController extends Ion {
this.router = injector.get(IonicRouter); this.router = injector.get(IonicRouter);
this.app = injector.get(IonicApp); this.app = injector.get(IonicApp);
this.config = config; this.config = config;
this.zone = zone;
this.router.addViewController(this); this.router.addViewController(this);
@ -215,51 +217,57 @@ export class ViewController extends Ion {
// wait for the new item to complete setup // wait for the new item to complete setup
enteringItem.stage(() => { enteringItem.stage(() => {
enteringItem.shouldDestroy = false; this.zone.runOutsideAngular(() => {
enteringItem.shouldCache = false;
enteringItem.willEnter();
leavingItem.willLeave();
// set that the new item pushed on the stack is staged to be entering/leaving enteringItem.shouldDestroy = false;
// staged state is important for the transition to find the correct item enteringItem.shouldCache = false;
enteringItem.state = STAGED_ENTERING_STATE; enteringItem.willEnter();
leavingItem.state = STAGED_LEAVING_STATE; leavingItem.willLeave();
// init the transition animation // set that the new item pushed on the stack is staged to be entering/leaving
let transAnimation = Transition.create(this, opts); // staged state is important for the transition to find the correct item
if (!opts.animate) { enteringItem.state = STAGED_ENTERING_STATE;
// force it to not animate the elements, just apply the "to" styles leavingItem.state = STAGED_LEAVING_STATE;
transAnimation.duration(0);
}
let duration = transAnimation.duration(); // init the transition animation
if (duration > 64) { let transAnimation = Transition.create(this, opts);
// block any clicks during the transition and provide a if (!opts.animate) {
// fallback to remove the clickblock if something goes wrong // force it to not animate the elements, just apply the "to" styles
ClickBlock(true, duration + 200); transAnimation.duration(0);
} }
// start the transition let duration = transAnimation.duration();
transAnimation.play().then(() => { if (duration > 64) {
// block any clicks during the transition and provide a
// fallback to remove the clickblock if something goes wrong
ClickBlock(true, duration + 200);
}
// transition has completed, update each item's state // start the transition
enteringItem.state = ACTIVE_STATE; transAnimation.play().then(() => {
leavingItem.state = CACHED_STATE;
// dispose any items that shouldn't stay around // transition has completed, update each item's state
transAnimation.dispose(); enteringItem.state = ACTIVE_STATE;
leavingItem.state = CACHED_STATE;
enteringItem.didEnter(); // dispose any items that shouldn't stay around
leavingItem.didLeave(); transAnimation.dispose();
// all done! enteringItem.didEnter();
this.transitionComplete(); leavingItem.didLeave();
// all done!
this.zone.run(() => {
this.transitionComplete();
callback();
});
});
callback();
}); });
}); }
}
});
swipeBackStart() { swipeBackStart() {
if (this.isTransitioning() || this.items.length < 2) { if (this.isTransitioning() || this.items.length < 2) {