refactor(app): 优化文件下载进度显示
- 修改 MainViewScreen.tsx 中的进度显示逻辑,简化为直接显示百分比 - 更新 UpdateHelper.ts 中的 downloadToFile 函数,增加进度字符串参数- 优化下载进度的计算和显示格式
这个提交包含在:
父节点
39a9fa3a65
当前提交
5400f38946
@ -116,13 +116,8 @@ export default function WebViewScreen(props: Props) {
|
|||||||
downloadToFile(
|
downloadToFile(
|
||||||
'https://download-api.51trust.com/ywx-android-sdk/common1.android.zip',
|
'https://download-api.51trust.com/ywx-android-sdk/common1.android.zip',
|
||||||
'common1.android.zip',
|
'common1.android.zip',
|
||||||
(bytesWritten, contentLength) => {
|
(_bytesWritten, _contentLength, pro) => {
|
||||||
setProgress(
|
setProgress(`进度: ${pro}%`);
|
||||||
`进度: ${(
|
|
||||||
(bytesWritten / contentLength) *
|
|
||||||
100
|
|
||||||
).toFixed(2)}%`,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
@ -4,7 +4,11 @@ import { unzip } from 'react-native-zip-archive';
|
|||||||
export const downloadToFile = async (
|
export const downloadToFile = async (
|
||||||
fileUrl: string,
|
fileUrl: string,
|
||||||
fileName: 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
|
// /storage/emulated/0/Android/data/com.trust.ywx/files/bundles/android/common.android.bundle
|
||||||
const downloadDest = `${RNFS.ExternalDirectoryPath}/bundles/${fileName}`;
|
const downloadDest = `${RNFS.ExternalDirectoryPath}/bundles/${fileName}`;
|
||||||
@ -18,7 +22,12 @@ export const downloadToFile = async (
|
|||||||
fromUrl: fileUrl,
|
fromUrl: fileUrl,
|
||||||
toFile: downloadDest,
|
toFile: downloadDest,
|
||||||
progress: (res: any) => {
|
progress: (res: any) => {
|
||||||
listener && listener(res.bytesWritten, res.contentLength);
|
listener &&
|
||||||
|
listener(
|
||||||
|
res.bytesWritten,
|
||||||
|
res.contentLength,
|
||||||
|
`进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`,
|
||||||
|
);
|
||||||
console.log(
|
console.log(
|
||||||
`进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`,
|
`进度: ${((res.bytesWritten / res.contentLength) * 100).toFixed(2)}%`,
|
||||||
);
|
);
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户