forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router): Add feature to support the View Transitions API (angula…
…r#51314) The View Transitions API enables easy animations when transitioning between different DOM states. This commit adds an opt-in feature to the Router which runs the component activation and deactivation logic in the document.startViewTransition callback. If the browser does not support this API, route activation and deactivation will happen synchronously. resolves angular#49401 PR Close angular#51314
- Loading branch information
1 parent
ac56efa
commit 73e4bf2
Showing
12 changed files
with
190 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/// <reference types="@types/dom-view-transitions" /> | ||
|
||
import {afterNextRender, InjectionToken, Injector, NgZone} from '@angular/core'; | ||
|
||
export const CREATE_VIEW_TRANSITION = | ||
new InjectionToken<typeof createViewTransition>(ngDevMode ? 'view transition helper' : ''); | ||
|
||
/** | ||
* A helper function for using browser view transitions. This function skips the call to | ||
* `startViewTransition` if the browser does not support it. | ||
* | ||
* @returns A Promise that resolves when the view transition callback begins. | ||
*/ | ||
export function createViewTransition(injector: Injector): Promise<void> { | ||
// Create promises outside the Angular zone to avoid causing extra change detections | ||
return injector.get(NgZone).runOutsideAngular(() => { | ||
if (!document.startViewTransition) { | ||
return Promise.resolve(); | ||
} | ||
|
||
let resolveViewTransitionStarted: () => void; | ||
const viewTransitionStarted = new Promise<void>((resolve) => { | ||
resolveViewTransitionStarted = resolve; | ||
}); | ||
document.startViewTransition(() => { | ||
resolveViewTransitionStarted(); | ||
return createRenderPromise(injector); | ||
}); | ||
return viewTransitionStarted; | ||
}); | ||
} | ||
|
||
/** | ||
* Creates a promise that resolves after next render. | ||
*/ | ||
function createRenderPromise(injector: Injector) { | ||
return new Promise<void>(resolve => { | ||
afterNextRender(resolve, {injector}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters