react-native-fast-image 8.19.1 → 8.20.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
@@ -230,9 +230,9 @@ Called when the image starts to load.
230
230
 
231
231
  ### `onProgress?: (event) => void`
232
232
 
233
- Called when the image is loading.
233
+ Called while the image downloads, with the bytes `loaded` so far, the `total`, and `progress` (`loaded / total`, from 0 to 1; the last event has 1). Not called while the total is unknown (a response without a `Content-Length`).
234
234
 
235
- e.g. `onProgress={e => console.log(e.nativeEvent.loaded / e.nativeEvent.total)}`
235
+ e.g. `onProgress={e => console.log(e.nativeEvent.progress)}`
236
236
 
237
237
  ---
238
238
 
package/dist/index.cjs.js CHANGED
@@ -84,6 +84,13 @@ function loadResult(event) {
84
84
  error: (_event$error = event.error) !== null && _event$error !== void 0 ? _event$error : "Failed to load the image"
85
85
  };
86
86
  }
87
+ function withProgress(onProgress) {
88
+ return onProgress && ((event) => {
89
+ const { loaded, total } = event.nativeEvent;
90
+ event.nativeEvent.progress = total > 0 ? Math.min(1, Math.max(0, loaded / total)) : 0;
91
+ onProgress(event);
92
+ });
93
+ }
87
94
  function withoutCache(source) {
88
95
  const { cache: _cache, ...rest } = source || {};
89
96
  return rest;
@@ -114,7 +121,7 @@ function FastImageBase({ source, defaultSource, tintColor, onLoadStart, onProgre
114
121
  source: resolvedSource,
115
122
  defaultSource,
116
123
  onLoadStart,
117
- onProgress,
124
+ onProgress: withProgress(onProgress),
118
125
  onLoad: onLoadEnd ? (event) => {
119
126
  const { width, height } = event.nativeEvent.source;
120
127
  fallbackResult.current = {
@@ -155,7 +162,7 @@ function FastImageBase({ source, defaultSource, tintColor, onLoadStart, onProgre
155
162
  source: resolvedSource,
156
163
  defaultSource: resolvedDefaultSource,
157
164
  onFastImageLoadStart: onLoadStart,
158
- onFastImageProgress: onProgress,
165
+ onFastImageProgress: withProgress(onProgress),
159
166
  onFastImageLoad: onLoad,
160
167
  onFastImageError: onError,
161
168
  onFastImageLoadEnd: onLoadEnd && ((event) => onLoadEnd(loadResult(event.nativeEvent))),
@@ -23,6 +23,8 @@ export type OnProgressEvent = SyntheticEvent<
23
23
  $ReadOnly<{|
24
24
  loaded: number,
25
25
  total: number,
26
+ // loaded / total, from 0 to 1.
27
+ progress: number,
26
28
  |}>,
27
29
  >
28
30
 
package/dist/index.d.ts CHANGED
@@ -84,6 +84,7 @@ export interface OnProgressEvent {
84
84
  nativeEvent: {
85
85
  loaded: number;
86
86
  total: number;
87
+ progress: number;
87
88
  };
88
89
  }
89
90
  export interface ImageStyle extends ViewStyle {
package/dist/index.js CHANGED
@@ -57,6 +57,13 @@ function loadResult(event) {
57
57
  error: (_event$error = event.error) !== null && _event$error !== void 0 ? _event$error : "Failed to load the image"
58
58
  };
59
59
  }
60
+ function withProgress(onProgress) {
61
+ return onProgress && ((event) => {
62
+ const { loaded, total } = event.nativeEvent;
63
+ event.nativeEvent.progress = total > 0 ? Math.min(1, Math.max(0, loaded / total)) : 0;
64
+ onProgress(event);
65
+ });
66
+ }
60
67
  function withoutCache(source) {
61
68
  const { cache: _cache, ...rest } = source || {};
62
69
  return rest;
@@ -87,7 +94,7 @@ function FastImageBase({ source, defaultSource, tintColor, onLoadStart, onProgre
87
94
  source: resolvedSource,
88
95
  defaultSource,
89
96
  onLoadStart,
90
- onProgress,
97
+ onProgress: withProgress(onProgress),
91
98
  onLoad: onLoadEnd ? (event) => {
92
99
  const { width, height } = event.nativeEvent.source;
93
100
  fallbackResult.current = {
@@ -128,7 +135,7 @@ function FastImageBase({ source, defaultSource, tintColor, onLoadStart, onProgre
128
135
  source: resolvedSource,
129
136
  defaultSource: resolvedDefaultSource,
130
137
  onFastImageLoadStart: onLoadStart,
131
- onFastImageProgress: onProgress,
138
+ onFastImageProgress: withProgress(onProgress),
132
139
  onFastImageLoad: onLoad,
133
140
  onFastImageError: onError,
134
141
  onFastImageLoadEnd: onLoadEnd && ((event) => onLoadEnd(loadResult(event.nativeEvent))),
@@ -23,6 +23,8 @@ export type OnProgressEvent = SyntheticEvent<
23
23
  $ReadOnly<{|
24
24
  loaded: number,
25
25
  total: number,
26
+ // loaded / total, from 0 to 1.
27
+ progress: number,
26
28
  |}>,
27
29
  >
28
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-fast-image",
3
- "version": "8.19.1",
3
+ "version": "8.20.0",
4
4
  "description": "🚩 FastImage, performant React Native image component.",
5
5
  "keywords": [
6
6
  "cache",