microsoft / code-push

A cloud service that enables Cordova and React Native developers to deploy mobile app updates directly to their users’ devices.
https://microsoft.github.io/code-push/
Other
4.35k stars 492 forks source link

About update layout after applied upgrade #51

Closed TanTan-TT closed 8 years ago

TanTan-TT commented 8 years ago

Hi My code is

  CodePush.sync({}).then((status) => {
    if (status === CodePush.SyncStatus.UPDATE_APPLIED) {

         // do something relayout my view and show loading spinner
    }
  })

But loading spinner is not shown. I guess whether sync() method block something about UI?

geof90 commented 8 years ago

Firstly, thank you for your issue, however it is a react native client plugin issue so it rightfully belongs at the https://github.com/Microsoft/react-native-code-push repo.

Next, to explain what you are seeing. When the dialog button is pressed, the package will first be downloaded first. After it is downloaded then will the promise resolve with the UPDATE_APPLIED status. At the time when you receive that status, the call to localPackage.apply() will call into native code to begin the process to asynchronously restart the app. It is only in that short window of time that your spinner action will be executed, hence it might not show at all. See the implementation of sync() for more details: https://github.com/Microsoft/react-native-code-push/blob/master/CodePush.ios.js#L162

Therefore, at least for now, if you want to do something like show a spinner, you need to use the other API methods directly (ie. not via the sync function). I would recommend the best time to show a spinner to be during remotePackage.download(). Our sync function internally uses these API methods, so you can take a look at the implementation to see how you would use those methods yourself. https://github.com/Microsoft/react-native-code-push/blob/master/CodePush.ios.js#L149

We are definitely looking at improving the sync() functionality, and your spinner scenario is something we think is interesting and may support in the future, so thank you for your feedback!

TanTan-TT commented 8 years ago

@geof90 I got it. Thanks a lot.

TanTan-TT commented 8 years ago

@geof90 I send a new issue to react-native-code-push https://github.com/Microsoft/react-native-code-push/issues/40 For now, I will handle this scenario by myself.