Skip to content

Commit

Permalink
Merge pull request #47 from stetbern/master
Browse files Browse the repository at this point in the history
Fix bug in conversion of boolean values from RN to ObjC for downloadFile()
  • Loading branch information
birdofpreyru authored May 30, 2024
2 parents 0f2038b + f028b9a commit 6d09a74
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1248,8 +1248,8 @@ The type of options argument of [downloadFile()].
Defaults _false_.

- `discretionary` — **boolean** — Optional. Allow the OS to control
the timing and speed of the download to improve perceived performance
(iOS only).
the timing and speed of the download to improve perceived performance. This setting may prevent downloading with mobile internet or when the battery is low. Only works when `background` is activated
(iOS only, defaults to _false_).
- `cacheable` — **boolean** — Optional. Whether the download can be
stored in the shared NSURLCache (iOS only, defaults to _true_).

Expand Down
12 changes: 6 additions & 6 deletions ios/ReactNativeFs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ namespace JS {
double jobId() const { return [_v[@"jobId"] doubleValue]; }
NSString *fromUrl() const { return _v[@"fromUrl"]; }
NSString *toFile() const { return _v[@"toFile"]; }
bool background() const { return _v[@"background"]; }
bool background() const { return [_v[@"background"] boolValue]; }
double backgroundTimeout() const { return [_v[@"backgroundTimeout"] doubleValue]; }
bool cacheable() const { return _v[@"cacheable"]; }
bool cacheable() const { return [_v[@"cacheable"] boolValue]; }
double connectionTimeout() const { return [_v[@"connectionTimeout"] doubleValue]; }
bool discretionary() const { return _v[@"discretionary"]; }
bool discretionary() const { return [_v[@"discretionary"] boolValue]; }
id<NSObject> headers() const { return _v[@"headers"]; }
double progressDivider() const { return [_v[@"progressDivider"] doubleValue]; }
double progressInterval() const { return [_v[@"progressInterval"] doubleValue]; }
double readTimeout() const { return [_v[@"readTimeout"] doubleValue]; }
bool hasBeginCallback() const { return _v[@"hasBeginCallback"]; }
bool hasProgressCallback() const { return _v[@"hasProgressCallback"]; }
bool hasResumableCallback() const { return _v[@"hasResumableCallback"]; }
bool hasBeginCallback() const { return [_v[@"hasBeginCallback"] boolValue]; }
bool hasProgressCallback() const { return [_v[@"hasProgressCallback"] boolValue]; }
bool hasResumableCallback() const { return [_v[@"hasResumableCallback"] boolValue]; }

NativeDownloadFileOptionsT(NSDictionary *const v) : _v(v) {}
private:
Expand Down
2 changes: 1 addition & 1 deletion ios/ReactNativeFs.mm
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ - (instancetype) init
NSNumber* discretionary = [NSNumber numberWithBool:options.discretionary()];
params.discretionary = [discretionary boolValue];
NSNumber* cacheable = [NSNumber numberWithBool:options.cacheable()];
params.cacheable = cacheable ? [cacheable boolValue] : YES;
params.cacheable = [cacheable boolValue];
NSNumber* progressInterval= [NSNumber numberWithDouble:options.progressInterval()];
params.progressInterval = progressInterval;
NSNumber* progressDivider = [NSNumber numberWithDouble:options.progressDivider()];
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function downloadFile(options: DownloadFileOptionsT): {
toFile: normalizeFilePath(options.toFile),
background: !!options.background,
backgroundTimeout: options.backgroundTimeout || 3600000, // 1 hour
cacheable: !!options.cacheable,
cacheable: options.cacheable === undefined ? true : options.cacheable,
connectionTimeout: options.connectionTimeout || 5000,
discretionary: !!options.discretionary,
headers: options.headers || {},
Expand Down

0 comments on commit 6d09a74

Please sign in to comment.