1
+ import { Transition , TransitionOptions , Animation , ViewController } from 'ionic-angular' ;
2
+ import { CSS } from 'ionic-angular/util/dom' ;
3
+
4
+ export class ImageViewerEnter extends Transition {
5
+ constructor ( enteringView : ViewController , leavingView : ViewController , opts : TransitionOptions ) {
6
+ super ( enteringView , leavingView , opts ) ;
7
+
8
+ let ele = enteringView . pageRef ( ) . nativeElement ;
9
+
10
+ let fromPosition = enteringView . data . position ;
11
+ let toPosition = ele . querySelector ( 'img' ) . getBoundingClientRect ( ) ;
12
+ let flipS = fromPosition . width / toPosition . width ;
13
+ let flipY = fromPosition . top - toPosition . top ;
14
+ let flipX = fromPosition . left - toPosition . left ;
15
+
16
+ let backdrop = new Animation ( ele . querySelector ( 'ion-backdrop' ) ) ;
17
+ let image = new Animation ( ele . querySelector ( '.image' ) ) ;
18
+
19
+ image . fromTo ( 'translateY' , `${ flipY } px` , '0px' )
20
+ . fromTo ( 'translateX' , `${ flipX } px` , '0px' )
21
+ . fromTo ( 'scale' , flipS , '1' ) ;
22
+
23
+ backdrop . fromTo ( 'opacity' , '0.01' , '1' ) ;
24
+
25
+ this . easing ( 'ease-in' )
26
+ . duration ( 150 )
27
+ . add ( backdrop )
28
+ . add ( image ) ;
29
+
30
+ let enteringNavBar = new Animation ( enteringView . navbarRef ( ) ) ;
31
+ enteringNavBar . before . addClass ( 'show-navbar' ) ;
32
+ this . add ( enteringNavBar ) ;
33
+
34
+ let enteringBackButton = new Animation ( enteringView . backBtnRef ( ) ) ;
35
+ this . add ( enteringBackButton ) ;
36
+ enteringBackButton . before . addClass ( 'show-back-button' ) ;
37
+ }
38
+ }
39
+
40
+ export class ImageViewerLeave extends Transition {
41
+ constructor ( enteringView : ViewController , leavingView : ViewController , opts : TransitionOptions ) {
42
+ super ( enteringView , leavingView , opts ) ;
43
+
44
+ let ele = leavingView . pageRef ( ) . nativeElement ;
45
+
46
+ let toPosition = leavingView . data . position ;
47
+ let fromPosition = ele . querySelector ( 'img' ) . getBoundingClientRect ( ) ;
48
+
49
+ let offsetY = 0 ;
50
+ let imageYOffset = ele . querySelector ( '.image' ) . style [ CSS . transform ] ;
51
+ if ( imageYOffset ) {
52
+ let regexResult = imageYOffset . match ( / t r a n s l a t e Y \( ( - ? \d + ) p x \) / ) ;
53
+ offsetY = regexResult ? parseFloat ( regexResult [ 1 ] ) : offsetY ;
54
+ }
55
+
56
+ let flipS = toPosition . width / fromPosition . width ;
57
+ let flipY = toPosition . top - fromPosition . top + offsetY ;
58
+ let flipX = toPosition . left - fromPosition . left ;
59
+
60
+ let backdropOpacity = ele . querySelector ( 'ion-backdrop' ) . style [ 'opacity' ] ;
61
+
62
+ let backdrop = new Animation ( ele . querySelector ( 'ion-backdrop' ) ) ;
63
+ let image = new Animation ( ele . querySelector ( '.image' ) ) ;
64
+
65
+ image . fromTo ( 'translateY' , `${ offsetY } px` , `${ flipY } px` )
66
+ . fromTo ( 'translateX' , `0px` , `${ flipX } px` )
67
+ . fromTo ( 'scale' , '1' , flipS ) ;
68
+
69
+ backdrop . fromTo ( 'opacity' , backdropOpacity , '0' ) ;
70
+
71
+ this . easing ( 'ease-in-out' )
72
+ . duration ( 150 )
73
+ . add ( backdrop )
74
+ . add ( image ) ;
75
+ }
76
+ }
0 commit comments