react-native-fast-image 8.8.0 → 8.8.1

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
@@ -243,11 +243,17 @@ FastImage.preload([
243
243
  ])
244
244
  ```
245
245
 
246
- It resolves when all the images have loaded or failed, with a result for each source, in order: `{ uri, ok, width, height, error }`. `width` and `height` are the image's size (as in `onLoad`), which is also a way to find an image's size without showing it. A few sources load at a time (3, or `SDWebImagePrefetcher`'s `maxConcurrentPrefetchCount` on iOS), so a long list doesn't hold up the images the app is showing, and at low priority unless the source sets `priority`. It never rejects:
246
+ It resolves when all the images have loaded or failed, with a result for each source, in order: `{ uri, ok: true, width, height }` if it loaded, or `{ uri, ok: false, error }` if it didn't (checking `ok` narrows the type in TypeScript). `width` and `height` are the image's size (as in `onLoad`), which is also a way to find an image's size without showing it. A few sources load at a time (3, or `SDWebImagePrefetcher`'s `maxConcurrentPrefetchCount` on iOS), so a long list doesn't hold up the images the app is showing, and at low priority unless the source sets `priority`. It never rejects:
247
247
 
248
248
  ```js
249
249
  const results = await FastImage.preload(sources)
250
- const failed = results.filter((result) => !result.ok)
250
+ for (const result of results) {
251
+ if (result.ok) {
252
+ console.log(result.uri, result.width, result.height)
253
+ } else {
254
+ console.warn(result.uri, result.error)
255
+ }
256
+ }
251
257
  ```
252
258
 
253
259
  ### `FastImage.clearMemoryCache: () => Promise<void>`
package/dist/index.cjs.js CHANGED
@@ -125,18 +125,29 @@ const FastImageComponent = (0, react.forwardRef)((props, ref) => /* @__PURE__ */
125
125
  ...props
126
126
  }));
127
127
  FastImageComponent.displayName = "FastImage";
128
+ const noResult = {
129
+ ok: false,
130
+ error: "No result"
131
+ };
128
132
  const FastImage = FastImageComponent;
129
133
  FastImage.resizeMode = resizeMode;
130
134
  FastImage.cacheControl = cacheControl;
131
135
  FastImage.priority = priority;
132
136
  FastImage.preload = (sources) => Promise.resolve(react_native.NativeModules.FastImageView.preload(sources.map((s) => s || {}))).then((results) => sources.map((source, i) => {
133
137
  var _results$i;
134
- return {
135
- uri: source ? source.uri : void 0,
136
- ...(_results$i = results === null || results === void 0 ? void 0 : results[i]) !== null && _results$i !== void 0 ? _results$i : {
137
- ok: false,
138
- error: "No result"
139
- }
138
+ const uri = source ? source.uri : void 0;
139
+ const result = (_results$i = results === null || results === void 0 ? void 0 : results[i]) !== null && _results$i !== void 0 ? _results$i : noResult;
140
+ if (!result.ok) return {
141
+ ...result,
142
+ uri
143
+ };
144
+ return typeof uri === "string" ? {
145
+ ...result,
146
+ uri
147
+ } : {
148
+ ok: false,
149
+ error: "Invalid source: no uri",
150
+ uri
140
151
  };
141
152
  }));
142
153
  FastImage.clearMemoryCache = () => react_native.NativeModules.FastImageView.clearMemoryCache();
@@ -43,14 +43,21 @@ export type ResizeModes = $Values<ResizeMode>
43
43
  export type Priorities = $Values<Priority>
44
44
  export type CacheControls = $Values<CacheControl>
45
45
 
46
- export type PreloadResult = {|
46
+ export type PreloadSuccess = {|
47
+ uri: string,
48
+ ok: true,
49
+ width: number,
50
+ height: number,
51
+ |}
52
+
53
+ export type PreloadFailure = {|
47
54
  uri?: string,
48
- ok: boolean,
49
- width?: number,
50
- height?: number,
51
- error?: string,
55
+ ok: false,
56
+ error: string,
52
57
  |}
53
58
 
59
+ export type PreloadResult = PreloadSuccess | PreloadFailure
60
+
54
61
  export type PreloadFn = (
55
62
  sources: Array<FastImageSource>,
56
63
  ) => Promise<Array<PreloadResult>>
package/dist/index.d.ts CHANGED
@@ -102,13 +102,18 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
102
102
  */
103
103
  children?: React.ReactNode;
104
104
  }
105
- export interface PreloadResult {
105
+ export interface PreloadSuccess {
106
+ uri: string;
107
+ ok: true;
108
+ width: number;
109
+ height: number;
110
+ }
111
+ export interface PreloadFailure {
106
112
  uri?: string;
107
- ok: boolean;
108
- width?: number;
109
- height?: number;
110
- error?: string;
113
+ ok: false;
114
+ error: string;
111
115
  }
116
+ export type PreloadResult = PreloadSuccess | PreloadFailure;
112
117
  export interface FastImageStaticProperties {
113
118
  resizeMode: typeof resizeMode;
114
119
  priority: typeof priority;
package/dist/index.js CHANGED
@@ -102,18 +102,29 @@ const FastImageComponent = forwardRef((props, ref) => /* @__PURE__ */ React.crea
102
102
  ...props
103
103
  }));
104
104
  FastImageComponent.displayName = "FastImage";
105
+ const noResult = {
106
+ ok: false,
107
+ error: "No result"
108
+ };
105
109
  const FastImage = FastImageComponent;
106
110
  FastImage.resizeMode = resizeMode;
107
111
  FastImage.cacheControl = cacheControl;
108
112
  FastImage.priority = priority;
109
113
  FastImage.preload = (sources) => Promise.resolve(NativeModules.FastImageView.preload(sources.map((s) => s || {}))).then((results) => sources.map((source, i) => {
110
114
  var _results$i;
111
- return {
112
- uri: source ? source.uri : void 0,
113
- ...(_results$i = results === null || results === void 0 ? void 0 : results[i]) !== null && _results$i !== void 0 ? _results$i : {
114
- ok: false,
115
- error: "No result"
116
- }
115
+ const uri = source ? source.uri : void 0;
116
+ const result = (_results$i = results === null || results === void 0 ? void 0 : results[i]) !== null && _results$i !== void 0 ? _results$i : noResult;
117
+ if (!result.ok) return {
118
+ ...result,
119
+ uri
120
+ };
121
+ return typeof uri === "string" ? {
122
+ ...result,
123
+ uri
124
+ } : {
125
+ ok: false,
126
+ error: "Invalid source: no uri",
127
+ uri
117
128
  };
118
129
  }));
119
130
  FastImage.clearMemoryCache = () => NativeModules.FastImageView.clearMemoryCache();
@@ -43,14 +43,21 @@ export type ResizeModes = $Values<ResizeMode>
43
43
  export type Priorities = $Values<Priority>
44
44
  export type CacheControls = $Values<CacheControl>
45
45
 
46
- export type PreloadResult = {|
46
+ export type PreloadSuccess = {|
47
+ uri: string,
48
+ ok: true,
49
+ width: number,
50
+ height: number,
51
+ |}
52
+
53
+ export type PreloadFailure = {|
47
54
  uri?: string,
48
- ok: boolean,
49
- width?: number,
50
- height?: number,
51
- error?: string,
55
+ ok: false,
56
+ error: string,
52
57
  |}
53
58
 
59
+ export type PreloadResult = PreloadSuccess | PreloadFailure
60
+
54
61
  export type PreloadFn = (
55
62
  sources: Array<FastImageSource>,
56
63
  ) => Promise<Array<PreloadResult>>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-fast-image",
3
- "version": "8.8.0",
3
+ "version": "8.8.1",
4
4
  "description": "🚩 FastImage, performant React Native image component.",
5
5
  "keywords": [
6
6
  "cache",