mirror of
https://github.com/status-im/react-native-fs.git
synced 2025-02-28 23:10:29 +00:00
Fixed progressDivider implementation in ios code
This commit is contained in:
parent
1bc9481a47
commit
14d6703b89
16
Downloader.m
16
Downloader.m
@ -71,17 +71,19 @@
|
|||||||
if ([_statusCode isEqualToNumber:[NSNumber numberWithInt:200]]) {
|
if ([_statusCode isEqualToNumber:[NSNumber numberWithInt:200]]) {
|
||||||
[_fileHandle writeData:data];
|
[_fileHandle writeData:data];
|
||||||
|
|
||||||
_bytesWritten = [NSNumber numberWithUnsignedInteger:[_bytesWritten unsignedIntegerValue] + data.length];
|
_bytesWritten = [NSNumber numberWithLong:[_bytesWritten longValue] + data.length];
|
||||||
|
|
||||||
if (_params.progressDivider <= 1) {
|
if (_params.progressDivider <= 1) {
|
||||||
return _params.progressCallback(_contentLength, _bytesWritten);
|
return _params.progressCallback(_contentLength, _bytesWritten);
|
||||||
} else {
|
} else {
|
||||||
NSLog(@"---Progress callback---");
|
double doubleBytesWritten = (double)[_bytesWritten longValue];
|
||||||
long double progress = Math.round(((double) _bytesWritten * 100) / _contentLength);
|
double doubleContentLength = (double)[_contentLength longValue];
|
||||||
if (progress % param.progressDivider == 0) {
|
double doublePercents = doubleBytesWritten / doubleContentLength * 100;
|
||||||
if ((progress != _lastProgressValue) || (_bytesWritten == _contentLength)) {
|
NSNumber* progress = [NSNumber numberWithUnsignedInt: floor(doublePercents)];
|
||||||
NSLog(@"---Progress callback EMIT--- %zu", progress);
|
if ([progress unsignedIntValue] % [_params.progressDivider integerValue] == 0) {
|
||||||
_lastProgressValue = [NSNumber numberWithLong:progress];
|
if (([progress unsignedIntValue] != [_lastProgressValue unsignedIntValue]) || ([_bytesWritten unsignedIntegerValue] == [_contentLength longValue])) {
|
||||||
|
NSLog(@"---Progress callback EMIT--- %zu", [progress unsignedIntValue]);
|
||||||
|
_lastProgressValue = [NSNumber numberWithUnsignedInt:[progress unsignedIntValue]];
|
||||||
return _params.progressCallback(_contentLength, _bytesWritten);
|
return _params.progressCallback(_contentLength, _bytesWritten);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user