@@ -42,79 +42,107 @@ const MenuIcon = ({icon, tint}: {icon: string, tint: string}) =>
4242 style = { [ styles . rectangleButtonIcon , { color : tint } ] }
4343 />
4444
45- class Row extends React . Component {
46- props : {
47- data : ViewType ,
48- active : boolean ,
45+ type RowProps = {
46+ data : ViewType ,
47+ active : boolean ,
48+ width : number ,
49+ }
50+
51+ type RowState = {
52+ style : {
53+ shadowRadius : Animated . Value ,
54+ transform : Array < { [ key : string ] : Animated . Value } > ,
55+ opacity : Animated . Value ,
56+ elevation : Animated . Value ,
57+ } ,
58+ }
59+
60+ class Row extends React . Component < void , RowProps , RowState > {
61+ static startStyle = {
62+ shadowRadius : 2 ,
63+ transform : [ { scale : 1 } ] ,
64+ opacity : 1 ,
65+ elevation : 2 ,
66+ }
67+
68+ static endStyle = {
69+ shadowRadius : 10 ,
70+ transform : [ { scale : 1.05 } ] ,
71+ opacity : 0.65 ,
72+ elevation : 4 ,
4973 }
5074
5175 state = {
5276 style : {
53- shadowRadius : new Animated . Value ( 2 ) ,
54- transform : [ { scale : new Animated . Value ( 1 ) } ] ,
55- opacity : new Animated . Value ( 1.0 ) ,
56- elevation : new Animated . Value ( 2 ) ,
77+ shadowRadius : new Animated . Value ( Row . startStyle . shadowRadius ) ,
78+ transform : [
79+ { scale : new Animated . Value ( Row . startStyle . transform [ 0 ] . scale ) } ,
80+ ] ,
81+ opacity : new Animated . Value ( Row . startStyle . opacity ) ,
82+ elevation : new Animated . Value ( Row . startStyle . elevation ) ,
5783 } ,
5884 }
5985
6086 componentWillReceiveProps ( nextProps ) {
61- if ( this . props . active !== nextProps . active ) {
62- if ( nextProps . active ) {
63- this . startActivationAnimation ( )
64- } else {
65- this . startDeactivationAnimation ( )
66- }
87+ if ( this . props . active === nextProps . active ) {
88+ return
89+ }
90+
91+ if ( nextProps . active ) {
92+ this . startActivationAnimation ( )
93+ } else {
94+ this . startDeactivationAnimation ( )
6795 }
6896 }
6997
7098 startActivationAnimation = ( ) => {
71- const { style } = this . state
99+ const { transform , shadowRadius , opacity , elevation } = this . state . style
72100 Animated . parallel ( [
73- Animated . timing ( style . transform [ 0 ] . scale , {
101+ Animated . timing ( transform [ 0 ] . scale , {
74102 duration : 100 ,
75103 easing : Easing . out ( Easing . quad ) ,
76- toValue : 1.05 ,
104+ toValue : Row . endStyle . transform [ 0 ] . scale ,
77105 } ) ,
78- Animated . timing ( style . shadowRadius , {
106+ Animated . timing ( shadowRadius , {
79107 duration : 100 ,
80108 easing : Easing . out ( Easing . quad ) ,
81- toValue : 10 ,
109+ toValue : Row . endStyle . shadowRadius ,
82110 } ) ,
83- Animated . timing ( style . opacity , {
111+ Animated . timing ( opacity , {
84112 duration : 100 ,
85113 easing : Easing . out ( Easing . quad ) ,
86- toValue : 0.65 ,
114+ toValue : Row . endStyle . opacity ,
87115 } ) ,
88- Animated . timing ( style . elevation , {
116+ Animated . timing ( elevation , {
89117 duration : 100 ,
90118 easing : Easing . out ( Easing . quad ) ,
91- toValue : 4 ,
119+ toValue : Row . endStyle . elevation ,
92120 } ) ,
93121 ] ) . start ( )
94122 }
95123
96124 startDeactivationAnimation = ( ) = > {
97- const { style } = this . state
125+ const { transform , shadowRadius , opacity , elevation } = this . state . style
98126 Animated . parallel ( [
99- Animated . timing ( style . transform [ 0 ] . scale , {
127+ Animated . timing ( transform [ 0 ] . scale , {
100128 duration : 100 ,
101129 easing : Easing . out ( Easing . quad ) ,
102- toValue : 1 ,
130+ toValue : Row . startStyle . transform [ 0 ] . scale ,
103131 } ) ,
104- Animated . timing ( style . shadowRadius , {
132+ Animated . timing ( shadowRadius , {
105133 duration : 100 ,
106134 easing : Easing . out ( Easing . quad ) ,
107- toValue : 2 ,
135+ toValue : Row . startStyle . shadowRadius ,
108136 } ) ,
109- Animated . timing ( style . opacity , {
137+ Animated . timing ( opacity , {
110138 duration : 100 ,
111139 easing : Easing . out ( Easing . quad ) ,
112- toValue : 1.0 ,
140+ toValue : Row . startStyle . opacity ,
113141 } ) ,
114- Animated . timing ( style . elevation , {
142+ Animated . timing ( elevation , {
115143 duration : 100 ,
116144 easing : Easing . out ( Easing . quad ) ,
117- toValue : 2 ,
145+ toValue : Row . startStyle . elevation ,
118146 } ) ,
119147 ] ) . start ( )
120148 }
0 commit comments