@@ -88,19 +88,28 @@ class LoginScreenView extends Component {
88
88
} ;
89
89
constructor ( ) {
90
90
super ( ) ;
91
-
91
+ this . timer = [ ] ;
92
92
this . _image = require ( '../image/twitter.png' ) ;
93
93
}
94
94
componentDidMount ( ) {
95
95
this . resetAnimation ( ) ;
96
96
}
97
+ componentWillUnmount ( ) {
98
+ this . onClearTimer ( ) ;
99
+ }
100
+ onClearTimer = ( ) => {
101
+ this . timer &&
102
+ this . timer . map ( ( item , index ) => {
103
+ item && clearTimeout ( item ) ;
104
+ } ) ;
105
+ } ;
97
106
resetAnimation ( ) {
98
107
this . setState ( {
99
108
appReady : false ,
100
109
rootKey : Math . random ( )
101
110
} ) ;
102
111
103
- setTimeout ( ( ) => {
112
+ this . timer [ 0 ] = setTimeout ( ( ) => {
104
113
this . setState ( {
105
114
appReady : true
106
115
} ) ;
@@ -133,57 +142,53 @@ class LoginScreenView extends Component {
133
142
this . props . showDialog ( diaOptin ) ;
134
143
} ;
135
144
onCheckForUpdate = ( ) => {
145
+ this . onClearTimer ( ) ;
136
146
this . props . showDialog ( dialogType . UPDATE_DIALOG ) ;
137
147
CodePush . checkForUpdate ( CONFIG . CODEPUS_KEY )
138
148
. then ( update => {
139
149
if ( ! update ) {
140
150
InteractionManager . runAfterInteractions ( ( ) => {
141
151
this . props . showDialog ( dialogType . UP_TO_DATE ) ;
142
- setTimeout ( ( ) => {
152
+ this . timer [ 1 ] = setTimeout ( ( ) => {
143
153
this . props . hideDialog ( ) ;
144
154
} , 1000 ) ;
145
155
} ) ;
146
156
} else {
147
- //this.props.showDialog(dialogType.AWAITING_USER_ACTION);
157
+ //InteractionManager.runAfterInteractions(() => {
158
+ this . props . showDialog ( dialogType . GUODU_DIALOG ) ;
159
+ // });
148
160
InteractionManager . runAfterInteractions ( ( ) => {
149
- Alert . alert ( '有可用更新' + update . label , update . description , [
150
- {
151
- text : '取消' ,
152
- onPress : ( ) => {
153
- this . props . showDialog ( dialogType . UPDATE_IGNORED ) ;
154
- setTimeout ( ( ) => {
155
- this . props . hideDialog ( ) ;
156
- } , 500 ) ;
157
- }
158
- } ,
159
- {
160
- text : '更新' ,
161
- onPress : ( ) => {
162
- update
163
- . download ( mess => {
164
- let receivedBytes = ( mess . receivedBytes / 1024 ) . toFixed ( 3 ) ;
165
- let totalBytes = ( mess . totalBytes / 1024 ) . toFixed ( 3 ) ;
166
- let per = parseInt ( receivedBytes / totalBytes * 100 ) ;
167
- this . props . showDialog ( dialogType . DOWNLOADING_PACKAGE ( per ) ) ;
168
- } )
169
- . then ( LocalPackage => {
170
- InteractionManager . runAfterInteractions ( ( ) => {
171
- this . props . showDialog ( dialogType . UPDATE_INSTALLED ) ;
172
- setTimeout ( ( ) => {
173
- LocalPackage . install ( CodePush . InstallMode . IMMEDIATE , 0 ) ;
174
- } , 500 ) ;
175
- } ) ;
176
- } ) ;
177
- }
178
- }
179
- ] ) ;
161
+ update . cancelBtn = ( ) => {
162
+ this . props . showDialog ( dialogType . UPDATE_IGNORED ) ;
163
+ this . timer [ 3 ] = setTimeout ( ( ) => {
164
+ this . props . hideDialog ( ) ;
165
+ } , 500 ) ;
166
+ } ;
167
+ update . confirmBtn = ( ) => {
168
+ update
169
+ . download ( mess => {
170
+ let receivedBytes = ( mess . receivedBytes / 1024 ) . toFixed ( 3 ) ;
171
+ let totalBytes = ( mess . totalBytes / 1024 ) . toFixed ( 3 ) ;
172
+ let per = parseInt ( receivedBytes / totalBytes * 100 ) ;
173
+ this . props . showDialog ( dialogType . DOWNLOADING_PACKAGE ( per ) ) ;
174
+ } )
175
+ . then ( LocalPackage => {
176
+ InteractionManager . runAfterInteractions ( ( ) => {
177
+ this . props . showDialog ( dialogType . UPDATE_INSTALLED ) ;
178
+ this . timer [ 2 ] = setTimeout ( ( ) => {
179
+ LocalPackage . install ( CodePush . InstallMode . IMMEDIATE , 0 ) ;
180
+ } , 500 ) ;
181
+ } ) ;
182
+ } ) ;
183
+ } ;
184
+ this . props . showDialog ( dialogType . AWAITING_USER_ACTION ( update ) ) ;
180
185
} ) ;
181
186
}
182
187
} )
183
188
. catch ( error => {
184
189
InteractionManager . runAfterInteractions ( ( ) => {
185
190
this . props . showDialog ( dialogType . UNKNOWN_ERROR ) ;
186
- setTimeout ( ( ) => {
191
+ this . timer [ 4 ] = setTimeout ( ( ) => {
187
192
this . props . hideDialog ( ) ;
188
193
} , 500 ) ;
189
194
} ) ;
0 commit comments