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.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). */
@@ -103,7 +103,8 @@ export type Source = {
103
103
  export type Transition = {
104
104
  /**
105
105
  * 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.
106
+ * the default transition's (see `FastImage.setDefaults`) if it fades,
107
+ * otherwise the platform's usual length: 300 ms on Android, 250 ms on iOS.
107
108
  */
108
109
  duration?: number;
109
110
  /**
@@ -124,17 +125,16 @@ export type Transition = {
124
125
  * usually only the first time (the disk cache usually keeps them too).
125
126
  * - `'none'`: always fades.
126
127
  *
127
- * Downloads, local files and bundled images (`require()`) fade in. On
128
- * Android, a `cache: 'web'` image from its HTTP cache, without a request,
128
+ * On Android, a `cache: 'web'` image from its HTTP cache, without a request,
129
129
  * counts as one from the memory cache (these images aren't kept there).
130
130
  * @default 'memory'
131
131
  */
132
132
  skipOnCacheHit?: 'none' | 'memory' | 'all' | null;
133
133
  };
134
134
  /**
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).
135
+ * `onLoad`'s event: `nativeEvent` has the image's own `width` and `height`
136
+ * (see `onLoad`), and `target`, the view's React tag (on iOS and Android; not
137
+ * on the web).
138
138
  */
139
139
  export interface OnLoadEvent {
140
140
  nativeEvent: {
@@ -234,7 +234,6 @@ export interface OnProgressEvent {
234
234
  };
235
235
  }
236
236
  export interface ImageStyle extends ViewStyle {
237
- overlayColor?: ColorValue;
238
237
  tintColor?: ColorValue;
239
238
  objectFit?: ObjectFit;
240
239
  }
@@ -293,9 +292,9 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
293
292
  * How the image fits the view, as CSS's `object-fit` does.
294
293
  *
295
294
  * - `'cover'`: scales it uniformly (keeping its aspect ratio) so it covers
296
- * the view (minus padding), cropping what doesn't fit.
295
+ * the view (inside its borders), cropping what doesn't fit.
297
296
  * - `'contain'`: scales it uniformly (keeping its aspect ratio) so all of
298
- * it fits in the view (minus padding).
297
+ * it fits in the view (inside its borders).
299
298
  * - `'fill'`: scales its width and height separately to fill the view,
300
299
  * which can change its aspect ratio.
301
300
  * - `'none'`: shows it at its own size, centered, cropped if it's larger
@@ -308,36 +307,37 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
308
307
  * as CSS counts an image's pixels: a 300 × 200 image is 300 × 200 points.
309
308
  * A bundled image (`require()`) is its size in points.
310
309
  *
311
- * It can also be set in `style`; the prop wins. Either one overrides
312
- * `resizeMode`.
310
+ * It can also be set in `style`; the prop wins.
313
311
  *
314
312
  * @default 'cover'
315
313
  */
316
314
  objectFit?: ObjectFit;
317
315
  /**
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.
316
+ * Where the image is in the view, as CSS's `object-position` places it:
317
+ * where its edges are when it doesn't fill the view exactly (`contain`,
318
+ * `cover`, `none` and `scale-down`; with `fill` it always fills it).
319
+ *
320
+ * - A string in CSS's syntax: one or two keywords (`'top'`,
321
+ * `'left bottom'`), lengths in points (`'10px 20px'`, with `px`) or
322
+ * percentages (`'25% 75%'`), or offsets from an edge
323
+ * (`'right 10px bottom 20%'`). A percentage puts that point of the image
324
+ * at that point of the view: `'0% 0%'` is the top-left corner,
325
+ * `'100% 100%'` the bottom-right.
326
+ * - An object with one of `top` and `bottom` and one of `left` and
327
+ * `right`, each in points (a number) or a percentage (`'25%'`), e.g.
328
+ * `{ right: 10, bottom: '20%' }`. A missing axis is centered.
329
+ *
330
+ * Points are dp on Android. An invalid value is ignored (the image is
331
+ * centered), with a warning in development. `defaultSource` is placed
332
+ * the same way.
333
+ *
334
+ * @default '50% 50%'
335
+ * @example
336
+ * ```jsx
337
+ * <FastImage source={{ uri }} objectFit="cover" objectPosition="top" />
338
+ * ```
339
339
  */
340
- fallback?: boolean;
340
+ objectPosition?: ObjectPosition;
341
341
  /**
342
342
  * For views that get reused for other content, such as rows in FlashList
343
343
  * or recyclerlistview. Set it to something that identifies the content,
@@ -393,15 +393,21 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
393
393
  */
394
394
  paused?: boolean;
395
395
  /**
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`.
396
+ * Fades the image in when it loads. `true` fades for the default's
397
+ * duration (see `FastImage.setDefaults`), or the platform's usual length
398
+ * if the default doesn't fade; a number is the duration in milliseconds,
399
+ * `false` (or 0) is no fade, or pass a `Transition`.
400
+ *
401
+ * By default, images fade in on Android (300 ms), and not on iOS.
402
+ * `FastImage.setDefaults` changes that for every image; an image's own
403
+ * `transition` wins, and the settings it leaves out come from the
404
+ * default. `null` is the default.
398
405
  *
399
406
  * Downloads, local files (`file://`, `content://`) and bundled images
400
407
  * (`require()`) fade in. In lists that reuse views (e.g. FlashList), set
401
408
  * `recyclingKey`, so a reused view starts empty and its image fades in,
402
409
  * instead of showing the previous item's image until it loads.
403
410
  *
404
- * @default false
405
411
  * @example
406
412
  * ```jsx
407
413
  * <FastImage source={{ uri }} transition />
@@ -427,12 +433,9 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
427
433
  * draw.
428
434
  *
429
435
  * 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.
436
+ * the cached file. Photo library images are always decoded at about the
437
+ * view's size. Android 16 and later decode animated WebP at full size
438
+ * either way, and scale it as they draw it.
436
439
  *
437
440
  * If you control the images, serve them at the size they're shown
438
441
  * (resized on your server or by an image CDN), which also saves
@@ -461,8 +464,7 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
461
464
  *
462
465
  * To animate a blur, or to blur an animated image, use React Native's
463
466
  * `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
467
+ * `style={{ filter: [{ blur: 6 }] }}`. React Native's docs list `blur` for Android 12+ only; on iOS it's behind
466
468
  * an experimental React Native feature flag (`enableSwiftUIBasedFilters`,
467
469
  * SwiftUI-based filters).
468
470
  *
@@ -525,9 +527,9 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
525
527
  */
526
528
  onLoadEnd?(result: LoadResult): void;
527
529
  /**
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).
530
+ * The image's style: View's style props (`borderRadius` clips the image,
531
+ * and borders inset it, but padding doesn't), and `tintColor`, as with
532
+ * React Native's `Image` (the `tintColor` prop wins).
531
533
  */
532
534
  style?: StyleProp<ImageStyle>;
533
535
  /**
@@ -536,14 +538,14 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
536
538
  */
537
539
  tintColor?: ColorValue;
538
540
  /**
539
- * Render children within the image.
541
+ * FastImage is a single native view, which doesn't take children (since
542
+ * 10.0): use `FastImageBackground` for content over an image.
540
543
  *
541
- * @deprecated In the next major version, `FastImage` won't render
542
- * children: use `FastImageBackground`.
544
+ * @hidden
543
545
  */
544
- children?: React.ReactNode;
546
+ children?: "FastImage doesn't take children: use FastImageBackground for content over an image";
545
547
  }
546
- type ViewRef = React.ElementRef<typeof View>;
548
+ type ViewRef = React.ComponentRef<typeof View>;
547
549
  /** A preloaded source that loaded (and is now cached). */
548
550
  export interface PreloadSuccess {
549
551
  /** The source's uri. */
@@ -570,10 +572,18 @@ export interface PreloadFailure {
570
572
  export type PreloadResult = PreloadSuccess | PreloadFailure;
571
573
  export interface FastImageStaticProperties {
572
574
  /**
573
- * @deprecated Use the `objectFit` prop instead of `resizeMode`.
575
+ * @deprecated `resizeMode` was removed in 10.0, and a `resizeMode` prop
576
+ * is ignored: use `objectFit` instead (`stretch` is `fill`, `center` is
577
+ * `scale-down`). Kept so code that reads it doesn't throw.
574
578
  */
575
579
  resizeMode: typeof resizeMode;
580
+ /**
581
+ * @deprecated Use the strings instead, e.g. `priority: 'high'`.
582
+ */
576
583
  priority: typeof priority;
584
+ /**
585
+ * @deprecated Use the strings instead, e.g. `cache: 'immutable'`.
586
+ */
577
587
  cacheControl: typeof cacheControl;
578
588
  preload: (sources: Source[]) => Promise<PreloadResult[]>;
579
589
  /**
@@ -617,6 +627,22 @@ export interface FastImageStaticProperties {
617
627
  * to read the disk cache's size).
618
628
  */
619
629
  configureCache: (limits?: CacheLimits) => Promise<CacheState>;
630
+ /**
631
+ * Changes the defaults of every image (only those given; null goes back
632
+ * to the built-in one). An image already showing uses a change once one
633
+ * of its props changes, for its next load. Not saved: call it before
634
+ * images render, e.g. in index.js.
635
+ */
636
+ setDefaults: (defaults: FastImageDefaults) => void;
637
+ }
638
+ /** `FastImage.setDefaults`'s settings. */
639
+ export interface FastImageDefaults {
640
+ /**
641
+ * The `transition` of images that don't set one (an image's own settings
642
+ * win, and those it leaves out come from this). `null` goes back to the
643
+ * built-in default (see `transition`).
644
+ */
645
+ transition?: boolean | number | Transition | null;
620
646
  }
621
647
  declare const FastImage: React.ForwardRefExoticComponent<FastImageProps & React.RefAttributes<ViewRef>> & FastImageStaticProperties;
622
648
  export interface FastImageBackgroundProps extends Omit<FastImageProps, 'style' | 'children'> {
@@ -631,9 +657,8 @@ export interface FastImageBackgroundProps extends Omit<FastImageProps, 'style' |
631
657
  }
632
658
  /**
633
659
  * 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;
660
+ * view that the image fills, with the children on top (`FastImage` is a single
661
+ * native view, which doesn't take children). The other props go to the image;
637
662
  * the ref is the view's.
638
663
  */
639
664
  export declare const FastImageBackground: React.ForwardRefExoticComponent<FastImageBackgroundProps & React.RefAttributes<ViewRef>>;