1
- import { DOCUMENT } from '@angular/common' ;
2
- import { Component , Inject , Input , Renderer2 } from '@angular/core' ;
1
+ import { Component , Input , Renderer2 , ViewChild , signal } from '@angular/core' ;
3
2
import { Router } from '@angular/router' ;
4
3
import { DeeplinkService } from 'src/app/shared/deeplink.service' ;
5
- import {
6
- CSSStyleDeclarationWithViewTransitionAPI ,
7
- DocumentWithViewTransitionAPI ,
8
- PackageType ,
9
- } from 'src/typings' ;
4
+ import { PackageType } from 'src/typings' ;
5
+ import { ViewTransitionDirective } from '../view-transition.directive' ;
10
6
11
7
@Component ( {
12
8
selector : 'app-card' ,
@@ -18,13 +14,26 @@ export class CardComponent {
18
14
19
15
@Input ( ) isFullMode = true ;
20
16
17
+ @ViewChild ( ViewTransitionDirective )
18
+ viewTransitionRef ! : ViewTransitionDirective ;
19
+
20
+ id = signal ( '' ) ;
21
+
21
22
constructor (
22
23
private renderer : Renderer2 ,
23
24
private deeplink : DeeplinkService ,
24
- private router : Router ,
25
- @ Inject ( DOCUMENT ) private document : Document
25
+
26
+ private router : Router
26
27
) { }
27
28
29
+ ngOnChanges ( ) {
30
+ this . id . set ( 'card-' + this . package ! . rev + ( this . isFullMode ? '-full' : '' ) ) ;
31
+ }
32
+
33
+ ngAfterContentInit ( ) {
34
+ debugger ;
35
+ }
36
+
28
37
onAvatarImageError ( avatarImage : HTMLImageElement , avatarIcon : HTMLElement ) {
29
38
this . renderer . setStyle ( avatarImage , 'display' , 'none' ) ;
30
39
this . renderer . setStyle ( avatarIcon , 'display' , 'block' ) ;
@@ -78,28 +87,17 @@ export class CardComponent {
78
87
}
79
88
80
89
async navigateTo ( pkg : PackageType , event : Event ) {
81
-
82
- this . #startViewTransition(
83
- ( ) => {
84
- this . router . navigate ( [ `pkg` , pkg . name ] , {
85
- state : {
86
- pkg,
87
- query : this . deeplink . getState ( ) ,
88
- } ,
89
- } ) ;
90
- }
91
- ) ;
90
+ await this . viewTransitionRef . startViewTransition ( async ( ) => {
91
+ await this . onViewTransition ( pkg ) ;
92
+ } ) ;
92
93
}
93
94
94
- #startViewTransition( onStart : ( ) => void , onFinish : ( ) => void = ( ) => { } ) {
95
- if ( ! ( this . document as DocumentWithViewTransitionAPI ) . startViewTransition ) {
96
- console . warn ( 'View transition API is not available in this browser.' ) ;
97
- return onStart ( ) ;
98
- }
99
-
100
- const transition = (
101
- this . document as DocumentWithViewTransitionAPI
102
- ) . startViewTransition ( onStart ) ;
103
- transition . finished . finally ( onFinish ) ;
95
+ async onViewTransition ( pkg : PackageType ) {
96
+ return await this . router . navigate ( [ `pkg` , pkg . name ] , {
97
+ state : {
98
+ pkg,
99
+ query : this . deeplink . getState ( ) ,
100
+ } ,
101
+ } ) ;
104
102
}
105
103
}
0 commit comments