mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 11:41:20 +08:00
chore(): sync feature-6.1 with main
This commit is contained in:
@ -1,17 +1,20 @@
|
||||
import { LocationStrategy } from '@angular/common';
|
||||
import { ElementRef, OnChanges, OnDestroy, OnInit, Directive, HostListener, Input, Optional } from '@angular/core';
|
||||
import { ElementRef, OnChanges, OnInit, Directive, HostListener, Input, Optional } from '@angular/core';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { AnimationBuilder, RouterDirection } from '@ionic/core';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
import { NavController } from '../../providers/nav-controller';
|
||||
|
||||
/**
|
||||
* Adds support for Ionic routing directions and animations to the base Angular router link directive.
|
||||
*
|
||||
* When the router link is clicked, the directive will assign the direction and
|
||||
* animation so that the routing integration will transition correctly.
|
||||
*/
|
||||
@Directive({
|
||||
selector: '[routerLink]',
|
||||
})
|
||||
export class RouterLinkDelegateDirective implements OnInit, OnChanges, OnDestroy {
|
||||
private subscription?: Subscription;
|
||||
|
||||
export class RouterLinkDelegateDirective implements OnInit, OnChanges {
|
||||
@Input()
|
||||
routerDirection: RouterDirection = 'forward';
|
||||
|
||||
@ -34,10 +37,9 @@ export class RouterLinkDelegateDirective implements OnInit, OnChanges, OnDestroy
|
||||
this.updateTargetUrlAndHref();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.subscription) {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
@HostListener('click')
|
||||
onClick(): void {
|
||||
this.navCtrl.setDirection(this.routerDirection, undefined, undefined, this.routerAnimation);
|
||||
}
|
||||
|
||||
private updateTargetUrlAndHref() {
|
||||
@ -46,13 +48,4 @@ export class RouterLinkDelegateDirective implements OnInit, OnChanges, OnDestroy
|
||||
this.elementRef.nativeElement.href = href;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@HostListener('click', ['$event'])
|
||||
onClick(ev: UIEvent): void {
|
||||
this.navCtrl.setDirection(this.routerDirection, undefined, undefined, this.routerAnimation);
|
||||
ev.preventDefault();
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ export class StackController {
|
||||
enteringView.ref.changeDetectorRef.reattach();
|
||||
|
||||
return this.transition(enteringView, leavingView, animation, this.canGoBack(1), false, animationBuilder)
|
||||
.then(() => cleanupAsync(enteringView, views, viewsSnapshot, this.location))
|
||||
.then(() => cleanupAsync(enteringView, views, viewsSnapshot, this.location, this.zone))
|
||||
.then(() => ({
|
||||
enteringView,
|
||||
direction,
|
||||
@ -201,7 +201,7 @@ export class StackController {
|
||||
this.skipTransition = true;
|
||||
this.pop(1);
|
||||
} else if (this.activeView) {
|
||||
cleanup(this.activeView, this.views, this.views, this.location);
|
||||
cleanup(this.activeView, this.views, this.views, this.location, this.zone);
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,11 +294,17 @@ export class StackController {
|
||||
}
|
||||
}
|
||||
|
||||
const cleanupAsync = (activeRoute: RouteView, views: RouteView[], viewsSnapshot: RouteView[], location: Location) => {
|
||||
const cleanupAsync = (
|
||||
activeRoute: RouteView,
|
||||
views: RouteView[],
|
||||
viewsSnapshot: RouteView[],
|
||||
location: Location,
|
||||
zone: NgZone
|
||||
) => {
|
||||
if (typeof (requestAnimationFrame as any) === 'function') {
|
||||
return new Promise<void>((resolve) => {
|
||||
requestAnimationFrame(() => {
|
||||
cleanup(activeRoute, views, viewsSnapshot, location);
|
||||
cleanup(activeRoute, views, viewsSnapshot, location, zone);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@ -306,8 +312,18 @@ const cleanupAsync = (activeRoute: RouteView, views: RouteView[], viewsSnapshot:
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
const cleanup = (activeRoute: RouteView, views: RouteView[], viewsSnapshot: RouteView[], location: Location) => {
|
||||
viewsSnapshot.filter((view) => !views.includes(view)).forEach(destroyView);
|
||||
const cleanup = (
|
||||
activeRoute: RouteView,
|
||||
views: RouteView[],
|
||||
viewsSnapshot: RouteView[],
|
||||
location: Location,
|
||||
zone: NgZone
|
||||
) => {
|
||||
/**
|
||||
* Re-enter the Angular zone when destroying page components. This will allow
|
||||
* lifecycle events (`ngOnDestroy`) to be run inside the Angular zone.
|
||||
*/
|
||||
zone.run(() => viewsSnapshot.filter((view) => !views.includes(view)).forEach(destroyView));
|
||||
|
||||
views.forEach((view) => {
|
||||
/**
|
||||
|
Reference in New Issue
Block a user