@kesha-antonov/react-native-background-downloader 2.6.8 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  ![react-native-background-downloader banner](https://d1w2zhnqcy4l8f.cloudfront.net/content/falcon/production/projects/V5EEOX_fast/RNBD-190702083358.png)
2
2
 
3
- [![npm version](https://badge.fury.io/js/react-native-background-downloader.svg)](https://badge.fury.io/js/react-native-background-downloader)
3
+ [![npm version](https://badge.fury.io/js/@kesha-antonov%2Freact-native-background-downloader.svg)](https://badge.fury.io/js/@kesha-antonov%2Freact-native-background-downloader)
4
4
 
5
- # react-native-background-downloader
5
+ # @kesha-antonov/react-native-background-downloader
6
6
  ## *Note - This is fork of https://github.com/EkoLabs/react-native-background-downloader maintained by https://github.com/kesha-antonov * ##
7
7
 
8
8
  A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.
@@ -16,7 +16,7 @@ On Android we are simulating this process with a wonderful library called [Fetch
16
16
 
17
17
  The real challenge of using this method is making sure the app's UI is always up-to-date with the downloads that are happening in another process because your app might startup from scratch while the downloads are still running.
18
18
 
19
- `react-native-background-downloader` gives you an easy API to both downloading large files and re-attaching to those downloads once your app launches again.
19
+ `@kesha-antonov/react-native-background-downloader` gives you an easy API to both downloading large files and re-attaching to those downloads once your app launches again.
20
20
 
21
21
  > **Please Note** - This library was created to better facilitate background downloading on iOS. If you're not aiming to to use the download-in-background functionality, there are better solutions like [RNFS.downloadFile()](https://github.com/itinance/react-native-fs#downloadfileoptions-downloadfileoptions--jobid-number-promise-promisedownloadresult-) which will results in a more stable download experience for your app.
22
22
 
@@ -29,7 +29,7 @@ The real challenge of using this method is making sure the app's UI is always up
29
29
  ## Getting started
30
30
 
31
31
  ```Terminal
32
- $ yarn add @kesha-antonov/react-native-background-downloader
32
+ yarn add @kesha-antonov/react-native-background-downloader
33
33
  ```
34
34
 
35
35
  or
@@ -48,7 +48,7 @@ Any React Native version **`>= 0.60`** supports autolinking so nothing should be
48
48
 
49
49
  For anything **`< 0.60`** run the following link command
50
50
 
51
- `$ react-native link react-native-background-downloader`
51
+ `$ react-native link @kesha-antonov/react-native-background-downloader`
52
52
 
53
53
  ### Manual installation
54
54
 
@@ -57,7 +57,7 @@ For anything **`< 0.60`** run the following link command
57
57
  #### iOS
58
58
 
59
59
  1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
60
- 2. Go to `node_modules` ➜ `react-native-background-downloader` and add `RNBackgroundDownloader.xcodeproj`
60
+ 2. Go to `node_modules` ➜ `@kesha-antonov/react-native-background-downloader` and add `RNBackgroundDownloader.xcodeproj`
61
61
  3. In XCode, in the project navigator, select your project. Add `libRNBackgroundDownloader.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
62
62
  4. Run your project (`Cmd+R`)
63
63
 
@@ -69,7 +69,7 @@ For anything **`< 0.60`** run the following link command
69
69
  2. Append the following lines to `android/settings.gradle`:
70
70
  ```
71
71
  include ':react-native-background-downloader'
72
- project(':react-native-background-downloader').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-downloader/android')
72
+ project(':react-native-background-downloader').projectDir = new File(rootProject.projectDir, '../node_modules/@kesha-antonov/react-native-background-downloader/android')
73
73
  ```
74
74
  3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
75
75
  ```
@@ -100,7 +100,7 @@ Failing to add this code will result in canceled background downloads. If Xcode
100
100
 
101
101
  ```javascript
102
102
  import { Platform } from 'react-native'
103
- import { download, completeHandler } from 'react-native-background-downloader'
103
+ import { download, completeHandler } from '@kesha-antonov/react-native-background-downloader'
104
104
 
105
105
  const jobId = 'file123'
106
106
 
@@ -144,7 +144,7 @@ What happens to your downloads after the OS stopped your app? Well, they are sti
144
144
  Add this code to app's init stage, and you'll never lose a download again!
145
145
 
146
146
  ```javascript
147
- import RNBackgroundDownloader from 'react-native-background-downloader'
147
+ import RNBackgroundDownloader from '@kesha-antonov/react-native-background-downloader'
148
148
 
149
149
  let lostTasks = await RNBackgroundDownloader.checkForExistingDownloads()
150
150
  for (let task of lostTasks) {
package/index.d.ts ADDED
@@ -0,0 +1,118 @@
1
+ // Type definitions for @kesha-antonov/react-native-background-downloader 2.6
2
+ // Project: https://github.com/kesha-antonov/react-native-background-downloader
3
+ // Definitions by: Philip Su <https://github.com/fivecar>,
4
+ // Adam Hunter <https://github.com/adamrhunter>,
5
+ // Junseong Park <https://github.com/Kweiza>
6
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
+
8
+ export interface DownloadHeaders {
9
+ [key: string]: string | null;
10
+ }
11
+
12
+ type SetHeaders = (h: DownloadHeaders) => void;
13
+
14
+ export interface TaskInfoObject {
15
+ id: string;
16
+ percent: number;
17
+ bytesWritten: number;
18
+ totalBytes: number;
19
+ }
20
+ export type TaskInfo = string | TaskInfoObject;
21
+
22
+ export interface BeginHandlerObject {
23
+ expectedBytes: number;
24
+ headers: { [key: string]: string };
25
+ }
26
+
27
+ export type BeginHandler = ({
28
+ expectedBytes,
29
+ headers,
30
+ }: BeginHandlerObject) => any;
31
+ export type ProgressHandler = (
32
+ percent: number,
33
+ bytesWritten: number,
34
+ totalBytes: number
35
+ ) => any;
36
+ export type DoneHandler = () => any;
37
+ export type ErrorHandler = (error: any, errorCode: any) => any;
38
+ export type DownloadTaskState =
39
+ | "DOWNLOADING"
40
+ | "PAUSED"
41
+ | "DONE"
42
+ | "FAILED"
43
+ | "STOPPED";
44
+
45
+ export interface DownloadTask {
46
+ constructor: (taskInfo: TaskInfo) => DownloadTask;
47
+
48
+ id: string;
49
+ state: DownloadTaskState;
50
+ percent: number;
51
+ bytesWritten: number;
52
+ totalBytes: number;
53
+
54
+ begin: (handler: BeginHandler) => DownloadTask;
55
+ progress: (handler: ProgressHandler) => DownloadTask;
56
+ done: (handler: DoneHandler) => DownloadTask;
57
+ error: (handler: ErrorHandler) => DownloadTask;
58
+
59
+ _beginHandler: BeginHandler;
60
+ _progressHandler: ProgressHandler;
61
+ _doneHandler: DoneHandler;
62
+ _errorHandler: ErrorHandler;
63
+
64
+ pause: () => any;
65
+ resume: () => any;
66
+ stop: () => any;
67
+ }
68
+
69
+ export type CheckForExistingDownloads = () => Promise<DownloadTask[]>;
70
+ export type EnsureDownloadsAreRunning = () => Promise<void>;
71
+
72
+ export interface DownloadOption {
73
+ id: string;
74
+ url: string;
75
+ destination: string;
76
+ headers?: DownloadHeaders | undefined;
77
+ }
78
+
79
+ export type Download = (options: DownloadOption) => DownloadTask;
80
+ export type CompleteHandler = (id: string) => void;
81
+
82
+ export interface Directories {
83
+ documents: string;
84
+ }
85
+
86
+ export interface Network {
87
+ WIFI_ONLY: string;
88
+ ALL: string;
89
+ }
90
+
91
+ export interface Priority {
92
+ HIGH: string;
93
+ MEDIUM: string;
94
+ LOW: string;
95
+ }
96
+
97
+ export const setHeaders: SetHeaders;
98
+ export const checkForExistingDownloads: CheckForExistingDownloads;
99
+ export const ensureDownloadsAreRunning: EnsureDownloadsAreRunning;
100
+ export const download: Download;
101
+ export const completeHandler: CompleteHandler;
102
+ export const directories: Directories;
103
+ export const Network: Network;
104
+ export const Priority: Priority;
105
+
106
+ export interface RNBackgroundDownloader {
107
+ setHeaders: SetHeaders;
108
+ checkForExistingDownloads: CheckForExistingDownloads;
109
+ ensureDownloadsAreRunning: EnsureDownloadsAreRunning;
110
+ download: Download;
111
+ completeHandler: CompleteHandler;
112
+ directories: Directories;
113
+ Network: Network;
114
+ Priority: Priority;
115
+ }
116
+
117
+ declare const RNBackgroundDownloader: RNBackgroundDownloader;
118
+ export default RNBackgroundDownloader;
@@ -57,24 +57,24 @@ export default class DownloadTask {
57
57
 
58
58
  onBegin ({ expectedBytes, headers }) {
59
59
  this.state = 'DOWNLOADING'
60
- this?.beginHandler({ expectedBytes, headers })
60
+ this.beginHandler?.({ expectedBytes, headers })
61
61
  }
62
62
 
63
63
  onProgress (percent, bytesWritten, totalBytes) {
64
64
  this.percent = percent
65
65
  this.bytesWritten = bytesWritten
66
66
  this.totalBytes = totalBytes
67
- this?.progressHandler(percent, bytesWritten, totalBytes)
67
+ this.progressHandler?.(percent, bytesWritten, totalBytes)
68
68
  }
69
69
 
70
70
  onDone ({ location }) {
71
71
  this.state = 'DONE'
72
- this?.doneHandler({ location })
72
+ this.doneHandler?.({ location })
73
73
  }
74
74
 
75
75
  onError (error, errorCode) {
76
76
  this.state = 'FAILED'
77
- this?.errorHandler(error, errorCode)
77
+ this.errorHandler?.(error, errorCode)
78
78
  }
79
79
 
80
80
  pause () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kesha-antonov/react-native-background-downloader",
3
- "version": "2.6.8",
3
+ "version": "2.7.0",
4
4
  "description": "A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -25,11 +25,13 @@
25
25
  }
26
26
  ],
27
27
  "main": "index.js",
28
+ "types": "index.d.ts",
28
29
  "files": [
29
30
  "README.md",
30
31
  "LICENSE",
31
32
  "react-native-background-downloader.podspec",
32
33
  "package.json",
34
+ "index.d.ts",
33
35
  "index.js",
34
36
  "lib/",
35
37
  "ios/",