react-native-fast-image 9.3.7 → 10.1.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 (78) hide show
  1. package/README.md +97 -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 +13 -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 +49 -14
  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 +12 -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 +24 -9
  29. package/android/src/main/java/com/fastimage/FastImageViewManager.java +591 -0
  30. package/android/src/main/java/com/{dylanvann/fastimage → fastimage}/FastImageViewModule.java +50 -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 +34 -17
  37. package/dist/index.cjs.web.js +211 -61
  38. package/dist/index.cjs.web.js.flow +34 -17
  39. package/dist/index.d.ts +108 -58
  40. package/dist/index.js +278 -159
  41. package/dist/index.js.flow +34 -17
  42. package/dist/index.web.js +212 -62
  43. package/dist/index.web.js.flow +34 -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} +89 -59
  53. package/ios/FastImage/FFFastImageSource.h +4 -0
  54. package/ios/FastImage/FFFastImageSource.m +5 -1
  55. package/ios/FastImage/FFFastImageView.h +36 -7
  56. package/ios/FastImage/FFFastImageView.m +229 -172
  57. package/ios/FastImage/FFFastImageViewComponentView.h +11 -0
  58. package/ios/FastImage/FFFastImageViewComponentView.mm +325 -0
  59. package/ios/FastImage/RCTConvert+FFFastImage.h +1 -1
  60. package/ios/FastImage/RCTConvert+FFFastImage.m +9 -10
  61. package/package.json +28 -9
  62. package/src/constants.ts +28 -0
  63. package/src/index.js.flow +180 -0
  64. package/src/index.tsx +1128 -0
  65. package/src/index.web.tsx +548 -0
  66. package/src/objectFit.ts +48 -0
  67. package/src/objectPosition.ts +243 -0
  68. package/src/specs/FastImageViewNativeComponent.ts +83 -0
  69. package/src/specs/NativeFastImageModule.ts +35 -0
  70. package/src/warnings.ts +37 -0
  71. package/android/src/main/AndroidManifestNew.xml +0 -3
  72. package/android/src/main/java/com/dylanvann/fastimage/FastImageCookieHandler.java +0 -63
  73. package/android/src/main/java/com/dylanvann/fastimage/FastImageEvents.java +0 -49
  74. package/android/src/main/java/com/dylanvann/fastimage/FastImageProgressListener.java +0 -18
  75. package/android/src/main/java/com/dylanvann/fastimage/FastImageShadowNode.java +0 -21
  76. package/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java +0 -379
  77. package/android/src/main/java/com/dylanvann/fastimage/FastImageViewPackage.java +0 -27
  78. package/ios/FastImage/FFFastImageViewManager.h +0 -5
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
2
  import { ColorValue, View, StyleProp, ViewStyle, ImageRequireSource, AccessibilityProps, ViewProps } from 'react-native';
3
3
  import { cacheControl, priority, resizeMode } from './constants';
4
+ import { type ObjectPosition } from './objectPosition';
4
5
  /** How the image fits the view: see [`objectFit`](#objectfit). */
5
6
  export type ObjectFit = 'fill' | 'contain' | 'cover' | 'none' | 'scale-down';
6
- /** How the image fits the view: see [`resizeMode`](#resizemode). */
7
- export type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center' | 'repeat';
7
+ export type { ObjectPosition, PositionLength } from './objectPosition';
8
8
  /** An image's load priority: see [`source.priority`](#sourcepriority). */
9
9
  export type Priority = 'low' | 'normal' | 'high';
10
10
  /** How fresh an image must be: see [`source.cache`](#sourcecache). */
@@ -86,6 +86,31 @@ export type Source = {
86
86
  * @default true
87
87
  */
88
88
  memoryCache?: boolean;
89
+ /**
90
+ * Whether the image is kept on disk. With `false` it isn't kept in the
91
+ * disk cache or an HTTP cache, or read from them. Use it for images the
92
+ * app shouldn't
93
+ * keep once they've been shown (e.g. disappearing messages, or where a
94
+ * security policy doesn't allow caching sensitive images), images that
95
+ * change every time they load, or large images shown once, which would
96
+ * push other images out of the disk cache.
97
+ * The image is downloaded again whenever it isn't in memory, e.g. for a
98
+ * view of another size (or on Android, a change of `blurRadius` or
99
+ * `objectFit`), so with `memoryCache: false` too it's downloaded each
100
+ * time it's shown. With `cache: 'web'` it isn't kept in memory either,
101
+ * so it's downloaded every time it loads. With `cache: 'cacheOnly'` it's
102
+ * only looked for in memory. On Android, a large download is held in a
103
+ * temporary file while it loads, as every download is, deleted as soon
104
+ * as it's opened.
105
+ *
106
+ * `FastImage.preload`, `getCachePath` and `writeToCache` resolve not `ok`
107
+ * for it: there's no file, and a view decodes the image for its own
108
+ * size, so it may download a preloaded one again. A source for the same
109
+ * url (or `cacheKey`) without `diskCache: false` still stores the image.
110
+ *
111
+ * @default true
112
+ */
113
+ diskCache?: boolean;
89
114
  /**
90
115
  * With several sources (`source` as an array), the image's width at this
91
116
  * uri, in pixels (times `scale`, if given).
@@ -103,7 +128,8 @@ export type Source = {
103
128
  export type Transition = {
104
129
  /**
105
130
  * How long the fade takes, in milliseconds; 0 means no fade. Defaults to
106
- * the platform's usual length: 300 ms on Android, 250 ms on iOS.
131
+ * the default transition's (see `FastImage.setDefaults`) if it fades,
132
+ * otherwise the platform's usual length: 300 ms on Android, 250 ms on iOS.
107
133
  */
108
134
  duration?: number;
109
135
  /**
@@ -124,17 +150,16 @@ export type Transition = {
124
150
  * usually only the first time (the disk cache usually keeps them too).
125
151
  * - `'none'`: always fades.
126
152
  *
127
- * Downloads, local files and bundled images (`require()`) fade in. On
128
- * Android, a `cache: 'web'` image from its HTTP cache, without a request,
153
+ * On Android, a `cache: 'web'` image from its HTTP cache, without a request,
129
154
  * counts as one from the memory cache (these images aren't kept there).
130
155
  * @default 'memory'
131
156
  */
132
157
  skipOnCacheHit?: 'none' | 'memory' | 'all' | null;
133
158
  };
134
159
  /**
135
- * `onLoad`'s event: `nativeEvent` has the image's `width` and `height`, in
136
- * pixels, and `target`, the view's React tag (missing on Android with the
137
- * legacy architecture).
160
+ * `onLoad`'s event: `nativeEvent` has the image's own `width` and `height`
161
+ * (see `onLoad`), and `target`, the view's React tag (on iOS and Android; not
162
+ * on the web).
138
163
  */
139
164
  export interface OnLoadEvent {
140
165
  nativeEvent: {
@@ -234,7 +259,6 @@ export interface OnProgressEvent {
234
259
  };
235
260
  }
236
261
  export interface ImageStyle extends ViewStyle {
237
- overlayColor?: ColorValue;
238
262
  tintColor?: ColorValue;
239
263
  objectFit?: ObjectFit;
240
264
  }
@@ -293,9 +317,9 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
293
317
  * How the image fits the view, as CSS's `object-fit` does.
294
318
  *
295
319
  * - `'cover'`: scales it uniformly (keeping its aspect ratio) so it covers
296
- * the view (minus padding), cropping what doesn't fit.
320
+ * the view (inside its borders), cropping what doesn't fit.
297
321
  * - `'contain'`: scales it uniformly (keeping its aspect ratio) so all of
298
- * it fits in the view (minus padding).
322
+ * it fits in the view (inside its borders).
299
323
  * - `'fill'`: scales its width and height separately to fill the view,
300
324
  * which can change its aspect ratio.
301
325
  * - `'none'`: shows it at its own size, centered, cropped if it's larger
@@ -308,36 +332,37 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
308
332
  * as CSS counts an image's pixels: a 300 × 200 image is 300 × 200 points.
309
333
  * A bundled image (`require()`) is its size in points.
310
334
  *
311
- * It can also be set in `style`; the prop wins. Either one overrides
312
- * `resizeMode`.
335
+ * It can also be set in `style`; the prop wins.
313
336
  *
314
337
  * @default 'cover'
315
338
  */
316
339
  objectFit?: ObjectFit;
317
340
  /**
318
- * How the image fills the view.
319
- *
320
- * - `'contain'`: as `objectFit="contain"`.
321
- * - `'cover'`: as `objectFit="cover"`.
322
- * - `'stretch'`: as `objectFit="fill"`.
323
- * - `'center'`: as `objectFit="scale-down"`, except that on Android an
324
- * image smaller than the view is shown at its size in pixels on the
325
- * screen, so smaller than on iOS and the web.
326
- * - `'repeat'`: repeats it to cover the view, from its top-left corner, at
327
- * the image's own size in pixels (a bundled image at its size in
328
- * points), scaled down to fit if it's larger than the view. An animated
329
- * image repeats its first frame, and `defaultSource` repeats too.
330
- *
331
- * @default 'cover'
332
- * @deprecated Use `objectFit` instead.
333
- */
334
- resizeMode?: ResizeMode;
335
- /**
336
- * If true, the image is shown with React Native's `Image` instead, styled
337
- * and laid out the same way. FastImage's own features, such as its
338
- * caching options, `priority` and `transition`, don't apply.
341
+ * Where the image is in the view, as CSS's `object-position` places it:
342
+ * where its edges are when it doesn't fill the view exactly (`contain`,
343
+ * `cover`, `none` and `scale-down`; with `fill` it always fills it).
344
+ *
345
+ * - A string in CSS's syntax: one or two keywords (`'top'`,
346
+ * `'left bottom'`), lengths in points (`'10px 20px'`, with `px`) or
347
+ * percentages (`'25% 75%'`), or offsets from an edge
348
+ * (`'right 10px bottom 20%'`). A percentage puts that point of the image
349
+ * at that point of the view: `'0% 0%'` is the top-left corner,
350
+ * `'100% 100%'` the bottom-right.
351
+ * - An object with one of `top` and `bottom` and one of `left` and
352
+ * `right`, each in points (a number) or a percentage (`'25%'`), e.g.
353
+ * `{ right: 10, bottom: '20%' }`. A missing axis is centered.
354
+ *
355
+ * Points are dp on Android. An invalid value is ignored (the image is
356
+ * centered), with a warning in development. `defaultSource` is placed
357
+ * the same way.
358
+ *
359
+ * @default '50% 50%'
360
+ * @example
361
+ * ```jsx
362
+ * <FastImage source={{ uri }} objectFit="cover" objectPosition="top" />
363
+ * ```
339
364
  */
340
- fallback?: boolean;
365
+ objectPosition?: ObjectPosition;
341
366
  /**
342
367
  * For views that get reused for other content, such as rows in FlashList
343
368
  * or recyclerlistview. Set it to something that identifies the content,
@@ -393,15 +418,21 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
393
418
  */
394
419
  paused?: boolean;
395
420
  /**
396
- * Fades the image in when it loads. `true` uses the platform's usual
397
- * fade, a number is the duration in milliseconds, or pass a `Transition`.
421
+ * Fades the image in when it loads. `true` fades for the default's
422
+ * duration (see `FastImage.setDefaults`), or the platform's usual length
423
+ * if the default doesn't fade; a number is the duration in milliseconds,
424
+ * `false` (or 0) is no fade, or pass a `Transition`.
425
+ *
426
+ * By default, images fade in on Android (300 ms), and not on iOS.
427
+ * `FastImage.setDefaults` changes that for every image; an image's own
428
+ * `transition` wins, and the settings it leaves out come from the
429
+ * default. `null` is the default.
398
430
  *
399
431
  * Downloads, local files (`file://`, `content://`) and bundled images
400
432
  * (`require()`) fade in. In lists that reuse views (e.g. FlashList), set
401
433
  * `recyclingKey`, so a reused view starts empty and its image fades in,
402
434
  * instead of showing the previous item's image until it loads.
403
435
  *
404
- * @default false
405
436
  * @example
406
437
  * ```jsx
407
438
  * <FastImage source={{ uri }} transition />
@@ -427,12 +458,9 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
427
458
  * draw.
428
459
  *
429
460
  * It doesn't change `onLoad`'s width and height (the image's own size) or
430
- * the cached file. On iOS it needs SDWebImage 5.19.7 or later: before
431
- * 5.19 images are decoded at full size, and 5.19.0 to 5.19.6 show photos
432
- * stored sideways with an EXIF orientation (most phone photos) sideways.
433
- * Photo library images are always decoded at about the view's size.
434
- * Android 16 and later decode animated WebP at full size either way, and
435
- * scale it as they draw it.
461
+ * the cached file. Photo library images are always decoded at about the
462
+ * view's size. Android 16 and later decode animated WebP at full size
463
+ * either way, and scale it as they draw it.
436
464
  *
437
465
  * If you control the images, serve them at the size they're shown
438
466
  * (resized on your server or by an image CDN), which also saves
@@ -461,8 +489,7 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
461
489
  *
462
490
  * To animate a blur, or to blur an animated image, use React Native's
463
491
  * `filter` style instead, which the GPU draws:
464
- * `style={{ filter: [{ blur: 6 }] }}`. It needs the New Architecture.
465
- * React Native's docs list `blur` for Android 12+ only; on iOS it's behind
492
+ * `style={{ filter: [{ blur: 6 }] }}`. React Native's docs list `blur` for Android 12+ only; on iOS it's behind
466
493
  * an experimental React Native feature flag (`enableSwiftUIBasedFilters`,
467
494
  * SwiftUI-based filters).
468
495
  *
@@ -525,9 +552,9 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
525
552
  */
526
553
  onLoadEnd?(result: LoadResult): void;
527
554
  /**
528
- * The image's style: View's style props (`borderRadius` clips the image),
529
- * and `tintColor`, as with React Native's `Image` (the `tintColor` prop
530
- * wins).
555
+ * The image's style: View's style props (`borderRadius` clips the image,
556
+ * and borders inset it, but padding doesn't), and `tintColor`, as with
557
+ * React Native's `Image` (the `tintColor` prop wins).
531
558
  */
532
559
  style?: StyleProp<ImageStyle>;
533
560
  /**
@@ -536,14 +563,14 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
536
563
  */
537
564
  tintColor?: ColorValue;
538
565
  /**
539
- * Render children within the image.
566
+ * FastImage is a single native view, which doesn't take children (since
567
+ * 10.0): use `FastImageBackground` for content over an image.
540
568
  *
541
- * @deprecated In the next major version, `FastImage` won't render
542
- * children: use `FastImageBackground`.
569
+ * @hidden
543
570
  */
544
- children?: React.ReactNode;
571
+ children?: "FastImage doesn't take children: use FastImageBackground for content over an image";
545
572
  }
546
- type ViewRef = React.ElementRef<typeof View>;
573
+ type ViewRef = React.ComponentRef<typeof View>;
547
574
  /** A preloaded source that loaded (and is now cached). */
548
575
  export interface PreloadSuccess {
549
576
  /** The source's uri. */
@@ -570,10 +597,18 @@ export interface PreloadFailure {
570
597
  export type PreloadResult = PreloadSuccess | PreloadFailure;
571
598
  export interface FastImageStaticProperties {
572
599
  /**
573
- * @deprecated Use the `objectFit` prop instead of `resizeMode`.
600
+ * @deprecated `resizeMode` was removed in 10.0, and a `resizeMode` prop
601
+ * is ignored: use `objectFit` instead (`stretch` is `fill`, `center` is
602
+ * `scale-down`). Kept so code that reads it doesn't throw.
574
603
  */
575
604
  resizeMode: typeof resizeMode;
605
+ /**
606
+ * @deprecated Use the strings instead, e.g. `priority: 'high'`.
607
+ */
576
608
  priority: typeof priority;
609
+ /**
610
+ * @deprecated Use the strings instead, e.g. `cache: 'immutable'`.
611
+ */
577
612
  cacheControl: typeof cacheControl;
578
613
  preload: (sources: Source[]) => Promise<PreloadResult[]>;
579
614
  /**
@@ -617,6 +652,22 @@ export interface FastImageStaticProperties {
617
652
  * to read the disk cache's size).
618
653
  */
619
654
  configureCache: (limits?: CacheLimits) => Promise<CacheState>;
655
+ /**
656
+ * Changes the defaults of every image (only those given; null goes back
657
+ * to the built-in one). An image already showing uses a change once one
658
+ * of its props changes, for its next load. Not saved: call it before
659
+ * images render, e.g. in index.js.
660
+ */
661
+ setDefaults: (defaults: FastImageDefaults) => void;
662
+ }
663
+ /** `FastImage.setDefaults`'s settings. */
664
+ export interface FastImageDefaults {
665
+ /**
666
+ * The `transition` of images that don't set one (an image's own settings
667
+ * win, and those it leaves out come from this). `null` goes back to the
668
+ * built-in default (see `transition`).
669
+ */
670
+ transition?: boolean | number | Transition | null;
620
671
  }
621
672
  declare const FastImage: React.ForwardRefExoticComponent<FastImageProps & React.RefAttributes<ViewRef>> & FastImageStaticProperties;
622
673
  export interface FastImageBackgroundProps extends Omit<FastImageProps, 'style' | 'children'> {
@@ -631,9 +682,8 @@ export interface FastImageBackgroundProps extends Omit<FastImageProps, 'style' |
631
682
  }
632
683
  /**
633
684
  * An image with content on top of it, like React Native's `ImageBackground`: a
634
- * view that the image fills, with the children on top. Use it rather than
635
- * giving `FastImage` children, which it won't render in the next major version
636
- * (the image will be a single native view). The other props go to the image;
685
+ * view that the image fills, with the children on top (`FastImage` is a single
686
+ * native view, which doesn't take children). The other props go to the image;
637
687
  * the ref is the view's.
638
688
  */
639
689
  export declare const FastImageBackground: React.ForwardRefExoticComponent<FastImageBackgroundProps & React.RefAttributes<ViewRef>>;