microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.98k stars 1.47k forks source link

How can I show the progress when an update comes with react native code push? I want to show my loading modal when the update comes. #2637

Closed cnlkkrb closed 9 months ago

cnlkkrb commented 10 months ago
const AppRoot = () => {
  const [progress, setProgress] = useState(false);

  const checkForUpdate = async () => {
    try {
      const update = await CodePush.checkForUpdate();
      if (update) {
        setProgress(true);

    CodePush.sync(
      {
        deploymentKey: 'M8_hdiay-n8fu3sIJ-o8VW7a7P9rqYHQf3YlG',
        updateDialog: false,
        installMode: CodePush.InstallMode.IMMEDIATE,
      },
      syncStatus => {
        switch (syncStatus) {
          case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
            break;
          case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
            break;
          case CodePush.SyncStatus.INSTALLING_UPDATE:
            break;
          case CodePush.SyncStatus.UPDATE_INSTALLED:
            break;
        }
      },
    );
  }
} catch (error) {
  console.error('CodePush update error:', error);
} finally {
  setProgress(false)
}

};

      useEffect(() => {
        checkForUpdate();
      }, []);
    {!!progress ? (
                <Modal visible={true} transparent>
                  <View
                    style={{
                      backgroundColor: 'rgba(0,0,0,0.8)',
                      flex: 1,
                      justifyContent: 'center',
                      alignItems: 'center',
                    }}>
                    <Text style={styles.text}>Güncellemeler Yükleniyor...</Text>
                    <View style={{alignItems: 'center'}}>
                      <ActivityIndicator
                        size={'large'}
                        style={{marginVertical: 8}}
                        color={'#004880'}
                      />
                    </View>
                  </View>
                </Modal>
              ) : null}
MikhailSuendukov commented 9 months ago

Hi @cnlkkrb and thanks for reaching us out. You can find instructions on how to do this in the documentation, so I'll close this issue. But if you have any more questions, feel free to reopen it.