Hi everyone today i'm trying to convert bytes received from update to percentage but no matter the method used i can't do it .
i make a constant codePushDownloadDidProgress were i convert the received bytes in to percentage multiplied by 100 than divided by total bytes but it gives me this result insteal a integer result:
.i tryed using math.floor but it doesn't work .i use code push for the update here is my code:
import React, {useEffect, useState} from 'react';
import Navigation from './navigation';
import codePush from 'react-native-code-push';
import LoaderBox from './components/LoaderBox';
import ProgressBox from './components/ProgressBox';
export default function App() {
const [syncMessage, setSyncMessage] = useState(true);
const [syncProgress, setSyncProgress] = useState(false);
const [progress, setProgress] = useState(0);
const codePushStatusDidChange = (status: any) => {
switch (status) {
case codePush.SyncStatus.CHECKING_FOR_UPDATE:
setSyncMessage(true);
break;
case codePush.SyncStatus.DOWNLOADING_PACKAGE:
console.log('Downloading package.');
setSyncMessage(false);
setSyncProgress(true);
break;
case codePush.SyncStatus.INSTALLING_UPDATE:
console.log('Installing update.');
setSyncProgress(true);
setSyncMessage(false);
break;
case codePush.SyncStatus.UP_TO_DATE:
console.log('Up-to-date.');
setSyncMessage(false);
break;
case codePush.SyncStatus.UPDATE_INSTALLED:
console.log('Update installed.');
setSyncProgress(false);
break;
}
};
const codePushDownloadDidProgress = (progression: {
receivedBytes: string;
totalBytes: string;
}) => {
let progressReceived =
(progression.receivedBytes * 100) / progression.totalBytes;
setProgress(progressReceived);
};
const syncImmediate = () => {
console.log('sincronized');
codePush.sync(
{
checkFrequency: codePush.CheckFrequency.ON_APP_START,
installMode: codePush.InstallMode.IMMEDIATE,
},
codePushStatusDidChange,
codePushDownloadDidProgress,
);
};
syncImmediate();
return (
<>
{syncMessage && <LoaderBox />}
{!syncMessage && !syncProgress && <Navigation />}
{syncProgress && <ProgressBox prog={progress} />}
</>
);
}
App = codePush(App);
thank you in avance for your help