File tree Expand file tree Collapse file tree 1 file changed +22
-12
lines changed Expand file tree Collapse file tree 1 file changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -70,28 +70,38 @@ class NavBarContent extends React.Component {
70
70
this . state = {
71
71
opacity : this . props . willDisappear ? new Animated . Value ( 1 ) : new Animated . Value ( 0 ) ,
72
72
} ;
73
+
74
+ this . doAnimation = this . doAnimation . bind ( this ) ;
75
+ }
76
+
77
+ componentDidMount ( ) {
78
+ // componentWillReceiveProps is not called on initial render, ensure animation is.
79
+ this . doAnimation ( ) ;
73
80
}
74
81
75
82
componentWillReceiveProps ( newProps ) {
76
83
if ( newProps . route !== this . props . route ) {
77
84
this . state . opacity . setValue ( this . props . willDisappear ? 1 : 0 ) ;
78
-
79
- setTimeout ( ( ) => {
80
- Animated . timing (
81
- this . state . opacity ,
82
- {
83
- fromValue : this . props . willDisappear ? 1 : 0 ,
84
- toValue : this . props . willDisappear ? 0 : 1 ,
85
- duration : 300 ,
86
- easing : Easing . easeOutQuad ,
87
- }
88
- ) . start ( ) ;
89
- } , 0 ) ;
85
+ this . doAnimation ( ) ;
90
86
} else if ( newProps . route === this . props . route ) {
91
87
this . state . opacity . setValue ( 1 ) ;
92
88
}
93
89
}
94
90
91
+ doAnimation ( ) {
92
+ setTimeout ( ( ) => {
93
+ Animated . timing (
94
+ this . state . opacity ,
95
+ {
96
+ fromValue : this . props . willDisappear ? 1 : 0 ,
97
+ toValue : this . props . willDisappear ? 0 : 1 ,
98
+ duration : 300 ,
99
+ easing : Easing . easeOutQuad ,
100
+ }
101
+ ) . start ( ) ;
102
+ } , 0 ) ;
103
+ }
104
+
95
105
goBack ( ) {
96
106
if ( ! this . props . willDisappear ) {
97
107
this . props . goBack ( ) ;
You can’t perform that action at this time.
0 commit comments