-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce view transition directive
- Loading branch information
1 parent
1dd6046
commit d64f934
Showing
10 changed files
with
102 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
export function patchViewTransitionAPI(_global: any, api: _ZonePrivate) { | ||
|
||
} | ||
|
||
Zone.__load_patch('viewTransition', (global: any, Zone: ZoneType, api: _ZonePrivate) => { | ||
patchViewTransitionAPI(global, api); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,49 @@ | ||
import { DOCUMENT } from '@angular/common'; | ||
import { | ||
Directive, | ||
ElementRef, | ||
Inject, | ||
NgZone, | ||
Renderer2, | ||
} from '@angular/core'; | ||
import { DocumentWithViewTransitionAPI } from 'src/typings'; | ||
|
||
@Directive({ | ||
selector: '[appViewTransition]', | ||
}) | ||
export class ViewTransitionDirective { | ||
constructor( | ||
private zone: NgZone, | ||
@Inject(DOCUMENT) private document: Document, | ||
private element: ElementRef<HTMLElement>, | ||
private renderer: Renderer2 | ||
) {} | ||
|
||
ngOnInit() { | ||
this.renderer.setStyle(this.element.nativeElement, 'contain', 'layout'); | ||
this.setElementTransitionName(this.element.nativeElement.id); | ||
} | ||
|
||
setElementTransitionName(name: string) { | ||
this.renderer.setStyle( | ||
this.element.nativeElement, | ||
'viewTransitionName', | ||
name | ||
); | ||
} | ||
|
||
async startViewTransition(callback: () => Promise<void>) { | ||
if (!(this.document as DocumentWithViewTransitionAPI).startViewTransition) { | ||
console.warn('View transition API is not available in this browser.'); | ||
return await callback(); | ||
} | ||
|
||
this.setElementTransitionName(this.element.nativeElement.id + '-full'); | ||
|
||
(this.document as DocumentWithViewTransitionAPI).startViewTransition(() => { | ||
// TODO: patch zone.js to support view transition api callbacks | ||
this.zone.run(async () => await callback()); | ||
this.setElementTransitionName(this.element.nativeElement.id); | ||
}); | ||
} | ||
} |
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