@@ -88,19 +88,28 @@ class LoginScreenView extends Component {
8888 } ;
8989 constructor ( ) {
9090 super ( ) ;
91-
91+ this . timer = [ ] ;
9292 this . _image = require ( '../image/twitter.png' ) ;
9393 }
9494 componentDidMount ( ) {
9595 this . resetAnimation ( ) ;
9696 }
97+ componentWillUnmount ( ) {
98+ this . onClearTimer ( ) ;
99+ }
100+ onClearTimer = ( ) => {
101+ this . timer &&
102+ this . timer . map ( ( item , index ) => {
103+ item && clearTimeout ( item ) ;
104+ } ) ;
105+ } ;
97106 resetAnimation ( ) {
98107 this . setState ( {
99108 appReady : false ,
100109 rootKey : Math . random ( )
101110 } ) ;
102111
103- setTimeout ( ( ) => {
112+ this . timer [ 0 ] = setTimeout ( ( ) => {
104113 this . setState ( {
105114 appReady : true
106115 } ) ;
@@ -133,57 +142,53 @@ class LoginScreenView extends Component {
133142 this . props . showDialog ( diaOptin ) ;
134143 } ;
135144 onCheckForUpdate = ( ) => {
145+ this . onClearTimer ( ) ;
136146 this . props . showDialog ( dialogType . UPDATE_DIALOG ) ;
137147 CodePush . checkForUpdate ( CONFIG . CODEPUS_KEY )
138148 . then ( update => {
139149 if ( ! update ) {
140150 InteractionManager . runAfterInteractions ( ( ) => {
141151 this . props . showDialog ( dialogType . UP_TO_DATE ) ;
142- setTimeout ( ( ) => {
152+ this . timer [ 1 ] = setTimeout ( ( ) => {
143153 this . props . hideDialog ( ) ;
144154 } , 1000 ) ;
145155 } ) ;
146156 } else {
147- //this.props.showDialog(dialogType.AWAITING_USER_ACTION);
157+ //InteractionManager.runAfterInteractions(() => {
158+ this . props . showDialog ( dialogType . GUODU_DIALOG ) ;
159+ // });
148160 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 ) ) ;
180185 } ) ;
181186 }
182187 } )
183188 . catch ( error => {
184189 InteractionManager . runAfterInteractions ( ( ) => {
185190 this . props . showDialog ( dialogType . UNKNOWN_ERROR ) ;
186- setTimeout ( ( ) => {
191+ this . timer [ 4 ] = setTimeout ( ( ) => {
187192 this . props . hideDialog ( ) ;
188193 } , 500 ) ;
189194 } ) ;
0 commit comments