diff --git a/src/app/screens/main/MainViewScreen.tsx b/src/app/screens/main/MainViewScreen.tsx index bc4aaa7..a71dc92 100644 --- a/src/app/screens/main/MainViewScreen.tsx +++ b/src/app/screens/main/MainViewScreen.tsx @@ -116,13 +116,8 @@ export default function WebViewScreen(props: Props) { downloadToFile( 'https://download-api.51trust.com/ywx-android-sdk/common1.android.zip', 'common1.android.zip', - (bytesWritten, contentLength) => { - setProgress( - `进度: ${( - (bytesWritten / contentLength) * - 100 - ).toFixed(2)}%`, - ); + (_bytesWritten, _contentLength, pro) => { + setProgress(`进度: ${pro}%`); }, ) .then(() => { diff --git a/src/common/UpdateHelper.ts b/src/common/UpdateHelper.ts index 8205a5b..468568a 100644 --- a/src/common/UpdateHelper.ts +++ b/src/common/UpdateHelper.ts @@ -4,7 +4,11 @@ import { unzip } from 'react-native-zip-archive'; export const downloadToFile = async ( fileUrl: string, fileName: string, - listener?: (bytesWritten: number, contentLength: number) => void, + listener?: ( + bytesWritten: number, + contentLength: number, + progress: string, + ) => void, ) => { // /storage/emulated/0/Android/data/com.trust.ywx/files/bundles/android/common.android.bundle const downloadDest = `${RNFS.ExternalDirectoryPath}/bundles/${fileName}`; @@ -18,7 +22,12 @@ export const downloadToFile = async ( fromUrl: fileUrl, toFile: downloadDest, progress: (res: any) => { - listener && listener(res.bytesWritten, res.contentLength); + listener && + listener( + res.bytesWritten, + res.contentLength, + `进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`, + ); console.log( `进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`, );