react-native-fast-image 9.3.7 → 10.0.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.
Files changed (76) hide show
  1. package/README.md +87 -61
  2. package/RNFastImage.podspec +14 -9
  3. package/android/build.gradle +21 -47
  4. package/android/consumer-rules.pro +7 -7
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageAnimatable.java +1 -1
  7. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageAnimated.java +2 -2
  8. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageApng.java +2 -2
  9. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageBlur.java +4 -6
  10. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageCacheControl.java +1 -1
  11. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageCacheLimits.java +4 -1
  12. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageCacheWrite.java +1 -1
  13. package/android/src/main/java/com/fastimage/FastImageCrop.java +92 -0
  14. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageEvent.java +2 -3
  15. package/android/src/main/java/com/fastimage/FastImageEvents.java +74 -0
  16. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageGif.java +1 -1
  17. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageGlide.java +3 -3
  18. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageGlideModule.java +1 -1
  19. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageKeyedGlideUrl.java +1 -1
  20. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageOkHttpProgressGlideModule.java +36 -9
  21. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageRequestListener.java +6 -1
  22. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSharedDownloads.java +1 -1
  23. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSource.java +1 -1
  24. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSourceSize.java +12 -2
  25. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSvg.java +3 -3
  26. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageSvgRenderer.java +1 -1
  27. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageUrl.java +1 -1
  28. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewConverter.java +7 -8
  29. package/android/src/main/java/com/fastimage/FastImageViewManager.java +591 -0
  30. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewModule.java +31 -28
  31. package/android/src/main/java/com/fastimage/FastImageViewPackage.java +51 -0
  32. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewWithUrl.java +352 -126
  33. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageWebGlideUrl.java +1 -1
  34. package/app.plugin.js +2 -7
  35. package/dist/index.cjs.js +276 -157
  36. package/dist/index.cjs.js.flow +33 -17
  37. package/dist/index.cjs.web.js +211 -61
  38. package/dist/index.cjs.web.js.flow +33 -17
  39. package/dist/index.d.ts +83 -58
  40. package/dist/index.js +278 -159
  41. package/dist/index.js.flow +33 -17
  42. package/dist/index.web.js +212 -62
  43. package/dist/index.web.js.flow +33 -17
  44. package/dist/objectFit.d.ts +2 -2
  45. package/dist/objectPosition.d.ts +42 -0
  46. package/dist/specs/FastImageViewNativeComponent.d.ts +48 -0
  47. package/dist/specs/NativeFastImageModule.d.ts +11 -0
  48. package/dist/warnings.d.ts +3 -0
  49. package/ios/FastImage/FFFDownsampledImage.h +4 -8
  50. package/ios/FastImage/FFFDownsampledImage.m +0 -34
  51. package/ios/FastImage/FFFastImageModule.h +8 -0
  52. package/ios/FastImage/{FFFastImageViewManager.m → FFFastImageModule.mm} +70 -59
  53. package/ios/FastImage/FFFastImageView.h +36 -7
  54. package/ios/FastImage/FFFastImageView.m +201 -164
  55. package/ios/FastImage/FFFastImageViewComponentView.h +11 -0
  56. package/ios/FastImage/FFFastImageViewComponentView.mm +325 -0
  57. package/ios/FastImage/RCTConvert+FFFastImage.h +1 -1
  58. package/ios/FastImage/RCTConvert+FFFastImage.m +7 -10
  59. package/package.json +28 -9
  60. package/src/constants.ts +28 -0
  61. package/src/index.js.flow +179 -0
  62. package/src/index.tsx +1103 -0
  63. package/src/index.web.tsx +548 -0
  64. package/src/objectFit.ts +48 -0
  65. package/src/objectPosition.ts +243 -0
  66. package/src/specs/FastImageViewNativeComponent.ts +83 -0
  67. package/src/specs/NativeFastImageModule.ts +35 -0
  68. package/src/warnings.ts +37 -0
  69. package/android/src/main/AndroidManifestNew.xml +0 -3
  70. package/android/src/main/java/com/dylanvann/fastimage/FastImageCookieHandler.java +0 -63
  71. package/android/src/main/java/com/dylanvann/fastimage/FastImageEvents.java +0 -49
  72. package/android/src/main/java/com/dylanvann/fastimage/FastImageProgressListener.java +0 -18
  73. package/android/src/main/java/com/dylanvann/fastimage/FastImageShadowNode.java +0 -21
  74. package/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java +0 -379
  75. package/android/src/main/java/com/dylanvann/fastimage/FastImageViewPackage.java +0 -27
  76. package/ios/FastImage/FFFastImageViewManager.h +0 -5
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import React, { forwardRef, memo, useRef } from "react";
2
- import { Image, NativeModules, Platform, StyleSheet, View, requireNativeComponent } from "react-native";
1
+ import React, { Children, forwardRef, memo } from "react";
2
+ import { Image, Platform, StyleSheet, TurboModuleRegistry, View, codegenNativeComponent } from "react-native";
3
3
  //#region src/constants.ts
4
4
  const resizeMode = {
5
5
  contain: "contain",
@@ -34,13 +34,6 @@ function fromStyle(style, key) {
34
34
  }
35
35
  return style && typeof style === "object" ? style[key] : void 0;
36
36
  }
37
- const RESIZE_MODE_FIT = {
38
- contain: "contain",
39
- cover: "cover",
40
- stretch: "fill",
41
- center: "center",
42
- repeat: "repeat"
43
- };
44
37
  const FITS = {
45
38
  fill: true,
46
39
  contain: true,
@@ -48,31 +41,204 @@ const FITS = {
48
41
  none: true,
49
42
  "scale-down": true
50
43
  };
51
- function resolveObjectFit(objectFit, style, resizeMode) {
52
- var _RESIZE_MODE_FIT$resi;
44
+ function resolveObjectFit(objectFit, style) {
53
45
  const fit = objectFit != null ? objectFit : fromStyle(style, "objectFit");
54
- if (fit && FITS[fit] === true) return fit;
55
- return (_RESIZE_MODE_FIT$resi = RESIZE_MODE_FIT[resizeMode]) !== null && _RESIZE_MODE_FIT$resi !== void 0 ? _RESIZE_MODE_FIT$resi : "cover";
46
+ return fit && FITS[fit] === true ? fit : "cover";
47
+ }
48
+ //#endregion
49
+ //#region src/warnings.ts
50
+ const warned = /* @__PURE__ */ new Set();
51
+ function warnOnce(key, message, level) {
52
+ if (!warned.has(key)) {
53
+ warned.add(key);
54
+ console[level](message);
55
+ }
56
+ }
57
+ function warnIfChildren(children) {
58
+ if (Children.toArray(children).length > 0) warnOnce("children", "react-native-fast-image: FastImage doesn't render children (since 10.0): use FastImageBackground for content over an image.", "error");
59
+ }
60
+ //#endregion
61
+ //#region src/objectPosition.ts
62
+ const START = {
63
+ fraction: 0,
64
+ offset: 0
65
+ };
66
+ const CENTER = {
67
+ fraction: .5,
68
+ offset: 0
69
+ };
70
+ const END = {
71
+ fraction: 1,
72
+ offset: 0
73
+ };
74
+ /** The default, `50% 50%`. */
75
+ const CENTERED = {
76
+ x: CENTER,
77
+ y: CENTER
78
+ };
79
+ const NUMBER = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
80
+ function length(text) {
81
+ const lower = text.toLowerCase();
82
+ if (lower.endsWith("%")) {
83
+ const number = lower.slice(0, -1);
84
+ return NUMBER.test(number) ? {
85
+ fraction: Number(number) / 100,
86
+ offset: 0
87
+ } : null;
88
+ }
89
+ if (lower.endsWith("px")) {
90
+ const number = lower.slice(0, -2);
91
+ return NUMBER.test(number) ? {
92
+ fraction: 0,
93
+ offset: Number(number)
94
+ } : null;
95
+ }
96
+ return NUMBER.test(lower) && Number(lower) === 0 ? START : null;
97
+ }
98
+ function token(text) {
99
+ const lower = text.toLowerCase();
100
+ if (lower === "left" || lower === "right" || lower === "top" || lower === "bottom" || lower === "center") return { keyword: lower };
101
+ const axis = length(text);
102
+ return axis ? { length: axis } : null;
103
+ }
104
+ const X = {
105
+ left: START,
106
+ center: CENTER,
107
+ right: END
108
+ };
109
+ const Y = {
110
+ top: START,
111
+ center: CENTER,
112
+ bottom: END
113
+ };
114
+ const x = (t) => "length" in t ? t.length : X[t.keyword];
115
+ const y = (t) => "length" in t ? t.length : Y[t.keyword];
116
+ function fromEdge(edge, axis) {
117
+ return edge === "left" || edge === "top" ? axis : {
118
+ fraction: 1 - axis.fraction,
119
+ offset: -axis.offset || 0
120
+ };
121
+ }
122
+ function parse(text) {
123
+ const tokens = [];
124
+ for (const part of text.trim().split(/\s+/)) {
125
+ const t = token(part);
126
+ if (!t) return null;
127
+ tokens.push(t);
128
+ }
129
+ if (tokens.length === 1) {
130
+ const [a] = tokens;
131
+ if ("keyword" in a && (a.keyword === "top" || a.keyword === "bottom")) return {
132
+ x: CENTER,
133
+ y: Y[a.keyword]
134
+ };
135
+ return {
136
+ x: x(a),
137
+ y: CENTER
138
+ };
139
+ }
140
+ if (tokens.length === 2) {
141
+ const [a, b] = tokens;
142
+ const ax = x(a);
143
+ const by = y(b);
144
+ if (ax && by) return {
145
+ x: ax,
146
+ y: by
147
+ };
148
+ if ("keyword" in a && "keyword" in b) {
149
+ const bx = X[b.keyword];
150
+ const ay = Y[a.keyword];
151
+ if (bx && ay) return {
152
+ x: bx,
153
+ y: ay
154
+ };
155
+ }
156
+ return null;
157
+ }
158
+ if (tokens.length === 4) {
159
+ const [a, b, c, d] = tokens;
160
+ if (!("keyword" in a && "length" in b && "keyword" in c && "length" in d)) return null;
161
+ const horizontal = (k) => k === "left" || k === "right";
162
+ const vertical = (k) => k === "top" || k === "bottom";
163
+ if (horizontal(a.keyword) && vertical(c.keyword)) return {
164
+ x: fromEdge(a.keyword, b.length),
165
+ y: fromEdge(c.keyword, d.length)
166
+ };
167
+ if (vertical(a.keyword) && horizontal(c.keyword)) return {
168
+ x: fromEdge(c.keyword, d.length),
169
+ y: fromEdge(a.keyword, b.length)
170
+ };
171
+ }
172
+ return null;
173
+ }
174
+ const parsed = /* @__PURE__ */ new Map();
175
+ function objectLength(value) {
176
+ if (typeof value === "number") return Number.isFinite(value) ? {
177
+ fraction: 0,
178
+ offset: value
179
+ } : null;
180
+ return typeof value === "string" && value.endsWith("%") ? length(value) : null;
181
+ }
182
+ /**
183
+ * The position for objectPosition, or null if it isn't valid. A string is
184
+ * CSS's syntax; an object has one of `top` and `bottom` and one of `left`
185
+ * and `right`, each in points or a percentage, and a missing axis is
186
+ * centered. Unset is centered.
187
+ */
188
+ function resolveObjectPosition(position) {
189
+ if (position == null) return CENTERED;
190
+ if (typeof position === "string") {
191
+ let result = parsed.get(position);
192
+ if (result === void 0) {
193
+ result = parse(position);
194
+ if (parsed.size < 100) parsed.set(position, result);
195
+ }
196
+ return result;
197
+ }
198
+ if (typeof position !== "object") return null;
199
+ const edges = position;
200
+ const axis = (start, end) => {
201
+ const hasStart = edges[start] != null;
202
+ const hasEnd = edges[end] != null;
203
+ if (hasStart && hasEnd) return null;
204
+ if (!hasStart && !hasEnd) return CENTER;
205
+ const edge = hasStart ? start : end;
206
+ const value = objectLength(edges[edge]);
207
+ return value && fromEdge(edge, value);
208
+ };
209
+ const resolvedX = axis("left", "right");
210
+ const resolvedY = axis("top", "bottom");
211
+ return resolvedX && resolvedY ? {
212
+ x: resolvedX,
213
+ y: resolvedY
214
+ } : null;
215
+ }
216
+ /**
217
+ * The position for objectPosition, or centered if it isn't valid (as CSS
218
+ * ignores it), with a warning in development.
219
+ */
220
+ function objectPositionOrCentered(position) {
221
+ const resolved = resolveObjectPosition(position);
222
+ if (resolved) return resolved;
223
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
224
+ const value = JSON.stringify(position);
225
+ warnOnce(`objectPosition ${value}`, `react-native-fast-image: objectPosition ${value} isn't a position, so the image is centered. Use CSS's syntax with px or % (e.g. 'right 10px bottom 20%'), or { top | bottom, left | right } in points or percentages.`, "warn");
226
+ }
227
+ return CENTERED;
56
228
  }
57
229
  //#endregion
230
+ //#region src/specs/FastImageViewNativeComponent.ts
231
+ var FastImageViewNativeComponent_default = codegenNativeComponent("FastImageView");
232
+ //#endregion
233
+ //#region src/specs/NativeFastImageModule.ts
234
+ var NativeFastImageModule_default = TurboModuleRegistry.get("FastImageModule");
235
+ //#endregion
58
236
  //#region src/index.tsx
59
237
  const resolveDefaultSource = (defaultSource) => {
60
238
  if (!defaultSource) return null;
61
- if (Platform.OS === "android") {
62
- const resolved = Image.resolveAssetSource(defaultSource);
63
- if (resolved) return resolved.uri;
64
- return null;
65
- }
66
- return defaultSource;
67
- };
68
- const NATIVE_RESIZE_MODE = {
69
- fill: "stretch",
70
- contain: "contain",
71
- cover: "cover",
72
- none: "none",
73
- "scale-down": "scale-down",
74
- center: "center",
75
- repeat: "repeat"
239
+ const resolved = Image.resolveAssetSource(defaultSource);
240
+ if (!resolved) return null;
241
+ return Platform.OS === "android" ? resolved.uri : resolved;
76
242
  };
77
243
  function loopCount(loop) {
78
244
  if (loop === void 0) return -1;
@@ -91,127 +257,81 @@ function loadResult(event) {
91
257
  error: (_event$error = event.error) !== null && _event$error !== void 0 ? _event$error : "Failed to load the image"
92
258
  };
93
259
  }
94
- function withProgress(onProgress) {
95
- return onProgress && ((event) => {
96
- const { loaded, total } = event.nativeEvent;
97
- event.nativeEvent.progress = total > 0 ? Math.min(1, Math.max(0, loaded / total)) : 0;
98
- onProgress(event);
99
- });
260
+ function handledEvents({ onLoadStart, onProgress, onLoad, onError, onLoadEnd }) {
261
+ return (onLoadStart ? 1 : 0) | (onProgress ? 2 : 0) | (onLoad ? 4 : 0) | (onError ? 8 : 0) | (onLoadEnd ? 16 : 0);
262
+ }
263
+ function usualFadeMs() {
264
+ return Platform.OS === "ios" ? 250 : 300;
100
265
  }
101
- const DEFAULT_FADE_MS = Platform.OS === "ios" ? 250 : 300;
102
- function transitionProps(transition) {
103
- var _transition$duration;
104
- const { duration, betweenImages, skipOnCacheHit } = typeof transition === "number" ? { duration: transition } : typeof transition === "object" && transition ? {
105
- ...transition,
106
- duration: (_transition$duration = transition.duration) !== null && _transition$duration !== void 0 ? _transition$duration : DEFAULT_FADE_MS
107
- } : { duration: transition ? DEFAULT_FADE_MS : 0 };
266
+ const NO_TRANSITION = {
267
+ transitionDuration: 0,
268
+ transitionBetweenImages: false,
269
+ transitionSkipOnCacheHit: "memory"
270
+ };
271
+ function resolveTransition(transition, base) {
272
+ if (transition == null) return base;
273
+ if (transition === false) return {
274
+ ...base,
275
+ transitionDuration: 0
276
+ };
277
+ const usual = base.transitionDuration > 0 ? base.transitionDuration : usualFadeMs();
278
+ if (transition === true) return {
279
+ ...base,
280
+ transitionDuration: usual
281
+ };
282
+ const { duration, betweenImages, skipOnCacheHit } = typeof transition === "number" ? { duration: transition } : transition;
283
+ const resolvedDuration = duration !== null && duration !== void 0 ? duration : usual;
108
284
  return {
109
- transitionDuration: typeof duration === "number" && duration > 0 ? duration : 0,
110
- transitionBetweenImages: !!betweenImages,
111
- transitionSkipOnCacheHit: skipOnCacheHit || "memory"
285
+ transitionDuration: typeof resolvedDuration === "number" && resolvedDuration > 0 ? resolvedDuration : 0,
286
+ transitionBetweenImages: betweenImages !== null && betweenImages !== void 0 ? betweenImages : base.transitionBetweenImages,
287
+ transitionSkipOnCacheHit: skipOnCacheHit !== null && skipOnCacheHit !== void 0 ? skipOnCacheHit : base.transitionSkipOnCacheHit
112
288
  };
113
289
  }
114
- function withoutCache(source) {
115
- const { cache: _cache, ...rest } = source || {};
116
- return rest;
290
+ function builtInTransition() {
291
+ return resolveTransition(Platform.OS === "android", NO_TRANSITION);
117
292
  }
118
- function FastImageBase({ source, defaultSource, tintColor, onLoadStart, onProgress, onLoad, onError, onLoadEnd, style, fallback, children, objectFit, resizeMode = "cover", loop, transition, forwardedRef, onLayout, pointerEvents, hitSlop, onStartShouldSetResponder, onStartShouldSetResponderCapture, onMoveShouldSetResponder, onMoveShouldSetResponderCapture, onResponderGrant, onResponderReject, onResponderStart, onResponderMove, onResponderEnd, onResponderRelease, onResponderTerminationRequest, onResponderTerminate, onTouchStart, onTouchMove, onTouchEnd, onTouchCancel, onTouchEndCapture, ...viewProps }) {
119
- const { onClick, ...props } = viewProps;
120
- const fallbackResult = useRef(void 0);
121
- const wrapperProps = {
122
- onLayout,
123
- onClick,
124
- pointerEvents,
125
- hitSlop,
126
- onStartShouldSetResponder,
127
- onStartShouldSetResponderCapture,
128
- onMoveShouldSetResponder,
129
- onMoveShouldSetResponderCapture,
130
- onResponderGrant,
131
- onResponderReject,
132
- onResponderStart,
133
- onResponderMove,
134
- onResponderEnd,
135
- onResponderRelease,
136
- onResponderTerminationRequest,
137
- onResponderTerminate,
138
- onTouchStart,
139
- onTouchMove,
140
- onTouchEnd,
141
- onTouchCancel,
142
- onTouchEndCapture
143
- };
144
- const imageProps = {
145
- ...props,
146
- pointerEvents: pointerEvents === "box-none" ? "none" : void 0
147
- };
293
+ let defaultTransition;
294
+ function FastImageBase({ source, defaultSource, tintColor, onLoadStart, onProgress, onLoad, onError, onLoadEnd, style, children, objectFit, objectPosition, loop, transition, forwardedRef, ...viewProps }) {
295
+ var _props$recyclingKey, _defaultTransition;
296
+ const { fallback, resizeMode: _resizeMode, ...props } = viewProps;
297
+ if (__DEV__ && fallback !== void 0) warnOnce("fallback", "react-native-fast-image: `fallback` was removed in 10.0, and does nothing: images always load natively. Remove it, or use React Native's Image for those images.", "warn");
298
+ if (__DEV__) warnIfChildren(children);
148
299
  const resolvedTintColor = tintColor != null ? tintColor : fromStyle(style, "tintColor");
149
- const mode = NATIVE_RESIZE_MODE[resolveObjectFit(objectFit, style, resizeMode)];
150
- if (fallback) {
151
- const cleanedSource = typeof source === "number" ? source : Array.isArray(source) ? source.map(withoutCache) : withoutCache(source);
152
- const resolvedSource = Image.resolveAssetSource(cleanedSource);
153
- return /* @__PURE__ */ React.createElement(View, {
154
- style: [styles.imageContainer, style],
155
- ...wrapperProps,
156
- ref: forwardedRef
157
- }, /* @__PURE__ */ React.createElement(Image, {
158
- ...imageProps,
159
- style: [styles.fallbackImage, { tintColor: resolvedTintColor }],
160
- source: resolvedSource,
161
- defaultSource,
162
- onLoadStart,
163
- onProgress: withProgress(onProgress),
164
- onLoad: onLoadEnd ? (event) => {
165
- const { width, height } = event.nativeEvent.source;
166
- fallbackResult.current = {
167
- ok: true,
168
- width,
169
- height
170
- };
171
- onLoad === null || onLoad === void 0 || onLoad(event);
172
- } : onLoad,
173
- onError: onLoadEnd ? (event) => {
174
- fallbackResult.current = {
175
- ok: false,
176
- error: String(event.nativeEvent.error)
177
- };
178
- onError === null || onError === void 0 || onError(event);
179
- } : onError,
180
- onLoadEnd: onLoadEnd && (() => {
181
- var _fallbackResult$curre;
182
- return onLoadEnd((_fallbackResult$curre = fallbackResult.current) !== null && _fallbackResult$curre !== void 0 ? _fallbackResult$curre : {
183
- ok: false,
184
- error: "Failed to load the image"
185
- });
186
- }),
187
- resizeMode: mode === "none" || mode === "scale-down" ? "center" : mode
188
- }), children);
189
- }
300
+ const fit = resolveObjectFit(objectFit, style);
301
+ const position = objectPositionOrCentered(objectPosition);
190
302
  const sources = Array.isArray(source) ? source.length === 1 ? void 0 : source : void 0;
191
303
  const single = Array.isArray(source) ? source[0] : source;
192
304
  const resolvedSource = sources ? void 0 : Image.resolveAssetSource(single);
193
305
  const resolvedDefaultSource = resolveDefaultSource(defaultSource);
194
- return /* @__PURE__ */ React.createElement(View, {
195
- style: [styles.imageContainer, style],
196
- ...wrapperProps,
197
- ref: forwardedRef
198
- }, /* @__PURE__ */ React.createElement(FastImageView, {
199
- ...imageProps,
200
- tintColor: resolvedTintColor,
306
+ return /* @__PURE__ */ React.createElement(FastImageViewNativeComponent_default, {
307
+ ...props,
308
+ ref: forwardedRef,
309
+ style: [styles.image, style],
310
+ recyclingKey: (_props$recyclingKey = props.recyclingKey) !== null && _props$recyclingKey !== void 0 ? _props$recyclingKey : void 0,
201
311
  loopCount: loopCount(loop),
202
- ...transitionProps(transition),
203
- style: StyleSheet.absoluteFill,
312
+ ...resolveTransition(transition, (_defaultTransition = defaultTransition) !== null && _defaultTransition !== void 0 ? _defaultTransition : builtInTransition()),
204
313
  source: resolvedSource,
205
314
  sources,
206
315
  defaultSource: resolvedDefaultSource,
207
316
  onFastImageLoadStart: onLoadStart,
208
- onFastImageProgress: withProgress(onProgress),
209
- trackProgress: !!onProgress,
317
+ onFastImageProgress: onProgress,
318
+ handledEvents: handledEvents({
319
+ onLoadStart,
320
+ onProgress,
321
+ onLoad,
322
+ onError,
323
+ onLoadEnd
324
+ }),
210
325
  onFastImageLoad: onLoad,
211
326
  onFastImageError: onError,
212
327
  onFastImageLoadEnd: onLoadEnd && ((event) => onLoadEnd(loadResult(event.nativeEvent))),
213
- resizeMode: mode
214
- }), children);
328
+ tintColor: resolvedTintColor,
329
+ objectFit: fit,
330
+ objectPositionX: position.x.fraction,
331
+ objectPositionXOffset: position.x.offset,
332
+ objectPositionY: position.y.fraction,
333
+ objectPositionYOffset: position.y.offset
334
+ });
215
335
  }
216
336
  const FastImageMemo = memo(FastImageBase);
217
337
  const FastImageComponent = forwardRef((props, ref) => /* @__PURE__ */ React.createElement(FastImageMemo, {
@@ -223,13 +343,21 @@ const noResult = {
223
343
  ok: false,
224
344
  error: "No result"
225
345
  };
346
+ function nativeModule() {
347
+ if (!NativeFastImageModule_default) throw new Error("react-native-fast-image: the native module FastImageModule isn't in this app. Rebuild the app after installing the package (run pod install on iOS). It needs the New Architecture, and isn't in Expo Go: use a development build. In Jest, mock the function (e.g. jest.spyOn(FastImage, \"preload\")).");
348
+ return NativeFastImageModule_default;
349
+ }
226
350
  const FastImage = FastImageComponent;
227
- FastImage.resizeMode = resizeMode;
228
351
  FastImage.cacheControl = cacheControl;
229
352
  FastImage.priority = priority;
353
+ FastImage.resizeMode = resizeMode;
354
+ FastImage.setDefaults = ({ transition } = {}) => {
355
+ if (transition === null) defaultTransition = void 0;
356
+ else if (transition !== void 0) defaultTransition = resolveTransition(transition, builtInTransition());
357
+ };
230
358
  const ONE_SOURCE = "Takes one source, not an array of sizes: pass the size to use";
231
359
  const isSourceObject = (source) => typeof source === "object" && source !== null && !Array.isArray(source);
232
- FastImage.preload = (sources) => Promise.resolve(NativeModules.FastImageView.preload(sources.map((s) => isSourceObject(s) ? s : {}))).then((results) => sources.map((source, i) => {
360
+ FastImage.preload = (sources) => Promise.resolve(nativeModule().preload(sources.map((s) => isSourceObject(s) ? s : {}))).then((results) => sources.map((source, i) => {
233
361
  var _results$i;
234
362
  if (Array.isArray(source)) return {
235
363
  ok: false,
@@ -251,32 +379,31 @@ FastImage.preload = (sources) => Promise.resolve(NativeModules.FastImageView.pre
251
379
  uri
252
380
  };
253
381
  }));
254
- FastImage.clearMemoryCache = () => Promise.resolve(NativeModules.FastImageView.clearMemoryCache());
255
- FastImage.clearDiskCache = () => Promise.resolve(NativeModules.FastImageView.clearDiskCache());
256
- FastImage.configureCache = (limits = {}) => Promise.resolve(NativeModules.FastImageView.configureCache(limits));
382
+ FastImage.clearMemoryCache = () => nativeModule().clearMemoryCache();
383
+ FastImage.clearDiskCache = () => nativeModule().clearDiskCache();
384
+ FastImage.configureCache = (limits) => {
385
+ const set = {};
386
+ const reset = [];
387
+ for (const [name, value] of Object.entries(limits !== null && limits !== void 0 ? limits : {})) if (value === null) reset.push(name);
388
+ else if (typeof value === "number") set[name] = value;
389
+ return nativeModule().configureCache({
390
+ ...set,
391
+ reset
392
+ });
393
+ };
257
394
  FastImage.writeToCache = (source, file) => Array.isArray(source) ? Promise.resolve({
258
395
  ok: false,
259
396
  error: ONE_SOURCE
260
- }) : Promise.resolve(NativeModules.FastImageView.writeToCache(isSourceObject(source) ? source : {}, file));
397
+ }) : Promise.resolve(nativeModule().writeToCache(isSourceObject(source) ? source : {}, file));
261
398
  FastImage.getCachePath = (source) => Array.isArray(source) ? Promise.resolve({
262
399
  ok: false,
263
400
  error: ONE_SOURCE
264
- }) : Promise.resolve(NativeModules.FastImageView.getCachePath(isSourceObject(source) ? source : {}));
265
- const styles = StyleSheet.create({
266
- fallbackImage: {
267
- position: "absolute",
268
- top: 0,
269
- left: 0,
270
- width: "100%",
271
- height: "100%"
272
- },
273
- imageContainer: { overflow: "hidden" }
274
- });
401
+ }) : Promise.resolve(nativeModule().getCachePath(isSourceObject(source) ? source : {}));
402
+ const styles = StyleSheet.create({ image: { overflow: "hidden" } });
275
403
  /**
276
404
  * An image with content on top of it, like React Native's `ImageBackground`: a
277
- * view that the image fills, with the children on top. Use it rather than
278
- * giving `FastImage` children, which it won't render in the next major version
279
- * (the image will be a single native view). The other props go to the image;
405
+ * view that the image fills, with the children on top (`FastImage` is a single
406
+ * native view, which doesn't take children). The other props go to the image;
280
407
  * the ref is the view's.
281
408
  */
282
409
  const FastImageBackground = forwardRef(({ style, imageStyle, imageRef, children, importantForAccessibility, ...props }, ref) => /* @__PURE__ */ React.createElement(View, {
@@ -291,13 +418,5 @@ const FastImageBackground = forwardRef(({ style, imageStyle, imageRef, children,
291
418
  ref: imageRef
292
419
  }), children));
293
420
  FastImageBackground.displayName = "FastImageBackground";
294
- const FastImageView = requireNativeComponent("FastImageView", FastImage, { nativeOnly: {
295
- onFastImageLoadStart: true,
296
- onFastImageProgress: true,
297
- onFastImageLoad: true,
298
- onFastImageError: true,
299
- onFastImageLoadEnd: true,
300
- trackProgress: true
301
- } });
302
421
  //#endregion
303
422
  export { FastImageBackground, FastImage as default };
@@ -1,25 +1,23 @@
1
1
  // @flow
2
2
 
3
- import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes'
4
- import type { SyntheticEvent } from 'react-native/Libraries/Types/CoreEventTypes'
3
+ import type { NativeSyntheticEvent, ViewProps } from 'react-native'
5
4
 
6
- export type OnLoadEvent = SyntheticEvent<
5
+ export type OnLoadEvent = NativeSyntheticEvent<
7
6
  $ReadOnly<{
8
7
  width: number,
9
8
  height: number,
10
- // The view's React tag. Missing on Android with the legacy architecture.
11
- // TODO: make it required once the New Architecture is the minimum.
9
+ // The view's React tag (on iOS and Android; not on the web).
12
10
  target?: number,
13
11
  }>,
14
12
  >
15
13
 
16
- export type OnErrorEvent = SyntheticEvent<
14
+ export type OnErrorEvent = NativeSyntheticEvent<
17
15
  $ReadOnly<{|
18
16
  error: string,
19
17
  |}>,
20
18
  >
21
19
 
22
- export type OnProgressEvent = SyntheticEvent<
20
+ export type OnProgressEvent = NativeSyntheticEvent<
23
21
  $ReadOnly<{|
24
22
  loaded: number,
25
23
  total: number,
@@ -28,6 +26,12 @@ export type OnProgressEvent = SyntheticEvent<
28
26
  |}>,
29
27
  >
30
28
 
29
+ export type Priority = $ReadOnly<{|
30
+ low: 'low',
31
+ normal: 'normal',
32
+ high: 'high',
33
+ |}>
34
+
31
35
  export type ResizeMode = $ReadOnly<{|
32
36
  contain: 'contain',
33
37
  cover: 'cover',
@@ -36,20 +40,22 @@ export type ResizeMode = $ReadOnly<{|
36
40
  repeat: 'repeat',
37
41
  |}>
38
42
 
39
- export type Priority = $ReadOnly<{|
40
- low: 'low',
41
- normal: 'normal',
42
- high: 'high',
43
- |}>
44
-
45
43
  export type CacheControl = $ReadOnly<{|
46
44
  immutable: 'immutable',
47
45
  web: 'web',
48
46
  cacheOnly: 'cacheOnly',
49
47
  |}>
50
48
 
51
- export type ResizeModes = $Values<ResizeMode>
52
49
  export type ObjectFit = 'fill' | 'contain' | 'cover' | 'none' | 'scale-down'
50
+ export type PositionLength = number | string
51
+ export type ObjectPosition =
52
+ | string
53
+ | $ReadOnly<{|
54
+ top?: PositionLength,
55
+ bottom?: PositionLength,
56
+ left?: PositionLength,
57
+ right?: PositionLength,
58
+ |}>
53
59
  export type Priorities = $Values<Priority>
54
60
  export type CacheControls = $Values<CacheControl>
55
61
 
@@ -82,6 +88,10 @@ export type Transition = $ReadOnly<{|
82
88
  skipOnCacheHit?: ?('none' | 'memory' | 'all'),
83
89
  |}>
84
90
 
91
+ export type FastImageDefaults = $ReadOnly<{|
92
+ transition?: ?(boolean | number | Transition),
93
+ |}>
94
+
85
95
  export type PreloadSuccess = {|
86
96
  uri: string,
87
97
  ok: true,
@@ -125,9 +135,7 @@ export type FastImageProps = $ReadOnly<{|
125
135
 
126
136
  tintColor?: number | string,
127
137
  objectFit?: ?ObjectFit,
128
- // Deprecated: use objectFit.
129
- resizeMode?: ?ResizeModes,
130
- fallback?: ?boolean,
138
+ objectPosition?: ?ObjectPosition,
131
139
  recyclingKey?: ?string,
132
140
  loop?: ?(boolean | number),
133
141
  imageRendering?: ?('auto' | 'smooth' | 'pixelated'),
@@ -136,6 +144,9 @@ export type FastImageProps = $ReadOnly<{|
136
144
  downsample?: ?boolean,
137
145
  blurRadius?: ?number,
138
146
  testID?: ?string,
147
+ // FastImage is a single native view, which doesn't take children (since
148
+ // 10.0): use FastImageBackground.
149
+ children?: "FastImage doesn't take children: use FastImageBackground for content over an image",
139
150
  |}>
140
151
 
141
152
  export type FastImageBackgroundProps = $ReadOnly<{|
@@ -148,14 +159,19 @@ export type FastImageBackgroundProps = $ReadOnly<{|
148
159
  declare export var FastImageBackground: React$ComponentType<FastImageBackgroundProps>
149
160
 
150
161
  declare export default class FastImage extends React$Component<FastImageProps> {
162
+ // Deprecated: removed in 10.0, and a resizeMode prop is ignored; use
163
+ // objectFit. Kept so code that reads it doesn't throw.
151
164
  static resizeMode: ResizeMode;
165
+ // Deprecated: use the strings instead, e.g. priority: 'high'.
152
166
  static priority: Priority;
167
+ // Deprecated: use the strings instead, e.g. cache: 'immutable'.
153
168
  static cacheControl: CacheControl;
154
169
  static preload: PreloadFn;
155
170
  static clearMemoryCache: () => Promise<ClearCacheResult>;
156
171
  static clearDiskCache: () => Promise<ClearCacheResult>;
157
172
  static getCachePath: (source: FastImageSource) => Promise<CachePathResult>;
158
173
  static configureCache: (limits?: CacheLimits) => Promise<CacheState>;
174
+ static setDefaults: (defaults: FastImageDefaults) => void;
159
175
  static writeToCache: (
160
176
  source: FastImageSource,
161
177
  file: string,