react-native-nitro-image-pipeline 1.4.0 → 1.6.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 (72) hide show
  1. package/README.md +124 -8
  2. package/android/CMakeLists.txt +4 -0
  3. package/android/src/main/cpp/GaussianBlur.cpp +165 -0
  4. package/android/src/main/cpp/GaussianBlur.hpp +52 -0
  5. package/android/src/main/cpp/GaussianBlurJni.cpp +50 -0
  6. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/HybridNitroImagePipeline.kt +167 -75
  7. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/PipelineImageLoader.kt +177 -0
  8. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/transform/BlurTransformation.kt +36 -81
  9. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/transform/HardwareBitmapTransformation.kt +45 -0
  10. package/ios/GaussianBlur.swift +48 -9
  11. package/ios/HybridNitroImagePipeline.swift +109 -41
  12. package/ios/PipelineImageLoader.swift +195 -0
  13. package/ios/RoundedCornersProcessor.swift +5 -0
  14. package/lib/commonjs/NativePipelineImage.js +72 -0
  15. package/lib/commonjs/NativePipelineImage.js.map +1 -0
  16. package/lib/commonjs/PipelineImage.js.map +1 -1
  17. package/lib/commonjs/index.js +27 -0
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/resolveImageSource.js +89 -0
  20. package/lib/commonjs/resolveImageSource.js.map +1 -0
  21. package/lib/commonjs/useImage.js +8 -4
  22. package/lib/commonjs/useImage.js.map +1 -1
  23. package/lib/commonjs/usePipelineImageLoader.js +74 -0
  24. package/lib/commonjs/usePipelineImageLoader.js.map +1 -0
  25. package/lib/module/NativePipelineImage.js +68 -0
  26. package/lib/module/NativePipelineImage.js.map +1 -0
  27. package/lib/module/PipelineImage.js.map +1 -1
  28. package/lib/module/index.js +3 -0
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/resolveImageSource.js +83 -0
  31. package/lib/module/resolveImageSource.js.map +1 -0
  32. package/lib/module/useImage.js +8 -4
  33. package/lib/module/useImage.js.map +1 -1
  34. package/lib/module/usePipelineImageLoader.js +70 -0
  35. package/lib/module/usePipelineImageLoader.js.map +1 -0
  36. package/lib/typescript/src/NativePipelineImage.d.ts +71 -0
  37. package/lib/typescript/src/NativePipelineImage.d.ts.map +1 -0
  38. package/lib/typescript/src/PipelineImage.d.ts +7 -2
  39. package/lib/typescript/src/PipelineImage.d.ts.map +1 -1
  40. package/lib/typescript/src/index.d.ts +4 -1
  41. package/lib/typescript/src/index.d.ts.map +1 -1
  42. package/lib/typescript/src/resolveImageSource.d.ts +56 -0
  43. package/lib/typescript/src/resolveImageSource.d.ts.map +1 -0
  44. package/lib/typescript/src/specs/nitro-image-toolkit.nitro.d.ts +56 -1
  45. package/lib/typescript/src/specs/nitro-image-toolkit.nitro.d.ts.map +1 -1
  46. package/lib/typescript/src/useImage.d.ts +10 -4
  47. package/lib/typescript/src/useImage.d.ts.map +1 -1
  48. package/lib/typescript/src/usePipelineImageLoader.d.ts +17 -0
  49. package/lib/typescript/src/usePipelineImageLoader.d.ts.map +1 -0
  50. package/nitrogen/generated/android/c++/JHybridNitroImagePipelineSpec.cpp +13 -0
  51. package/nitrogen/generated/android/c++/JHybridNitroImagePipelineSpec.hpp +1 -0
  52. package/nitrogen/generated/android/c++/JViewOptions.hpp +77 -0
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/HybridNitroImagePipelineSpec.kt +5 -0
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/ViewOptions.kt +66 -0
  55. package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Bridge.cpp +10 -0
  56. package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Bridge.hpp +44 -0
  57. package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Umbrella.hpp +8 -0
  58. package/nitrogen/generated/ios/c++/HybridNitroImagePipelineSpecSwift.hpp +14 -0
  59. package/nitrogen/generated/ios/swift/HybridNitroImagePipelineSpec.swift +1 -0
  60. package/nitrogen/generated/ios/swift/HybridNitroImagePipelineSpec_cxx.swift +15 -0
  61. package/nitrogen/generated/ios/swift/ViewOptions.swift +101 -0
  62. package/nitrogen/generated/shared/c++/HybridNitroImagePipelineSpec.cpp +1 -0
  63. package/nitrogen/generated/shared/c++/HybridNitroImagePipelineSpec.hpp +7 -0
  64. package/nitrogen/generated/shared/c++/ViewOptions.hpp +104 -0
  65. package/package.json +4 -3
  66. package/src/NativePipelineImage.tsx +108 -0
  67. package/src/PipelineImage.tsx +7 -2
  68. package/src/index.ts +12 -0
  69. package/src/resolveImageSource.ts +83 -0
  70. package/src/specs/nitro-image-toolkit.nitro.ts +57 -1
  71. package/src/useImage.ts +26 -15
  72. package/src/usePipelineImageLoader.ts +90 -0
@@ -0,0 +1,71 @@
1
+ import { type ComponentRef } from 'react';
2
+ import type { HostComponent } from 'react-native';
3
+ import { NativeNitroImage } from 'react-native-nitro-image';
4
+ import { type ImageSource } from './resolveImageSource';
5
+ import type { CacheOption, CornerRadii, ResizeOptions } from './specs/nitro-image-toolkit.nitro';
6
+ type ReactProps<T> = T extends HostComponent<infer P> ? P : never;
7
+ type NativeImageProps = ReactProps<typeof NativeNitroImage>;
8
+ /**
9
+ * The instance `<NativePipelineImage>` exposes through its `ref` — the
10
+ * underlying `NativeNitroImage` host view, with the usual native-view
11
+ * methods (`measure`, …).
12
+ */
13
+ export type NativePipelineImageRef = ComponentRef<typeof NativeNitroImage>;
14
+ export interface NativePipelineImageProps extends Omit<NativeImageProps, 'image'> {
15
+ /**
16
+ * The image to load through the pipeline: a URL string (`https://`,
17
+ * `file://`, an absolute path) or a `require()`d asset — see
18
+ * {@linkcode ImageSource}.
19
+ */
20
+ url: ImageSource;
21
+ /**
22
+ * Gaussian blur sigma in **points** (density-independent), like
23
+ * `PipelineImage`. Applied natively with the screen scale.
24
+ * @default 0
25
+ */
26
+ blur?: number;
27
+ /**
28
+ * Corner radius in **points** — a single number or per-corner radii.
29
+ * When omitted, it's derived from `style`'s `borderRadius`-family
30
+ * properties instead — set this prop to override that.
31
+ * @default undefined (derived from `style`, or square corners if unset there)
32
+ */
33
+ cornerRadius?: number | CornerRadii;
34
+ cache?: CacheOption;
35
+ /**
36
+ * Target bitmap size in **pixels**, overriding the size the native side
37
+ * measures from the view. Rarely needed.
38
+ * @default undefined (measure the view natively)
39
+ */
40
+ resize?: ResizeOptions;
41
+ }
42
+ /**
43
+ * The fully native-driven variant of `PipelineImage`: after the first render
44
+ * there is **zero JS work per image**. The native view starts the request
45
+ * when it attaches to the window — at its own laid-out size, so nothing
46
+ * waits for an `onLayout` round trip — and cancels it (releasing the bitmap)
47
+ * when it detaches, which makes off-screen list cells free. Loads go through
48
+ * the same pipeline and caches as `useImage`/`preLoadImage`.
49
+ *
50
+ * Compared to `PipelineImage`:
51
+ * - No `onLoad`/`onError` callbacks — the loaded `Image` never crosses into
52
+ * JS. Use `PipelineImage` (or `useImage`) when you need them.
53
+ * - The bitmap is loaded once at the size the view first has; if the view is
54
+ * resized later, the bitmap scales with it instead of reloading.
55
+ * @example
56
+ * ```tsx
57
+ * <NativePipelineImage
58
+ * url="https://example.com/photo.jpg"
59
+ * style={{ width: 300, height: 200, borderRadius: 24 }}
60
+ * blur={4}
61
+ * />
62
+ * ```
63
+ */
64
+ export declare const NativePipelineImage: import("react").ForwardRefExoticComponent<NativePipelineImageProps & import("react").RefAttributes<import("react").Component<{
65
+ hybridRef?: import("react-native-nitro-modules").NitroViewWrappedCallback<((ref: import("react-native-nitro-modules").HybridView<import("react-native-nitro-image/lib/typescript/specs/ImageView.nitro").NativeNitroImageViewProps, import("react-native-nitro-image/lib/typescript/specs/ImageView.nitro").NativeNitroImageViewMethods>) => void) | undefined> | undefined;
66
+ image?: import("react-native-nitro-image").Image | import("react-native-nitro-image").ImageLoader;
67
+ resizeMode?: import("react-native-nitro-image/lib/typescript/specs/ImageView.nitro").ResizeMode;
68
+ recyclingKey?: string;
69
+ } & import("react-native").ViewProps, {}, any> & import("react-native").ReactNativeElement>>;
70
+ export {};
71
+ //# sourceMappingURL=NativePipelineImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativePipelineImage.d.ts","sourceRoot":"","sources":["../../../src/NativePipelineImage.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAc,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,sBAAsB,CAAC;AACzE,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,mCAAmC,CAAC;AAG3C,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAClE,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,YAAY,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE3E,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CACpD,gBAAgB,EAChB,OAAO,CACR;IACC;;;;OAIG;IACH,GAAG,EAAE,WAAW,CAAC;IACjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACpC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,mBAAmB;;;;;4FA0B9B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { type ComponentRef } from 'react';
2
2
  import { type HostComponent } from 'react-native';
3
3
  import { type Image, NativeNitroImage } from 'react-native-nitro-image';
4
+ import type { ImageSource } from './resolveImageSource';
4
5
  import type { CacheOption, CornerRadii } from './specs/nitro-image-toolkit.nitro';
5
6
  type ReactProps<T> = T extends HostComponent<infer P> ? P : never;
6
7
  type NativeImageProps = ReactProps<typeof NativeNitroImage>;
@@ -11,8 +12,12 @@ type NativeImageProps = ReactProps<typeof NativeNitroImage>;
11
12
  */
12
13
  export type PipelineImageRef = ComponentRef<typeof NativeNitroImage>;
13
14
  export interface PipelineImageProps extends Omit<NativeImageProps, 'image'> {
14
- /** URL of the image to load through the pipeline. */
15
- url: string;
15
+ /**
16
+ * The image to load through the pipeline: a URL string (`https://`,
17
+ * `file://`, an absolute path) or a `require()`d asset — see
18
+ * {@linkcode ImageSource}.
19
+ */
20
+ url: ImageSource;
16
21
  /**
17
22
  * Gaussian blur sigma in **points** (density-independent). Unlike
18
23
  * `useImage`/`loadImage`, where it is bitmap pixels, the component
@@ -1 +1 @@
1
- {"version":3,"file":"PipelineImage.d.ts","sourceRoot":"","sources":["../../../src/PipelineImage.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAKlB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAOxE,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAEZ,MAAM,mCAAmC,CAAC;AAG3C,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAClE,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAErE,MAAM,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;IACzE;;;;OAIG;IACH,GAAG,EAAE,WAAW,CAAC;IACjB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACpC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC,iCAAiC;IACjC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,aAAa;;;;;4FAqEzB,CAAC"}
@@ -1,6 +1,9 @@
1
+ export { NativePipelineImage, type NativePipelineImageProps, type NativePipelineImageRef, } from './NativePipelineImage';
1
2
  export { NitroImagePipeline } from './NitroImagePipeline';
2
3
  export { PipelineImage, type PipelineImageProps, type PipelineImageRef, } from './PipelineImage';
4
+ export { type ImageSource, resolveImageUrl, UNREGISTERED_ASSET_URL, } from './resolveImageSource';
3
5
  export { cornerRadiusForStyle, resizeForLayout, resizeForStyle, } from './resizeForStyle';
4
- export type { CacheOption, CornerRadii, Options, ResizeOptions, } from './specs/nitro-image-toolkit.nitro';
6
+ export type { CacheOption, CornerRadii, Options, ResizeOptions, ViewOptions, } from './specs/nitro-image-toolkit.nitro';
5
7
  export { useImage } from './useImage';
8
+ export { usePipelineImageLoader } from './usePipelineImageLoader';
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,aAAa,GACd,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,WAAW,EAChB,eAAe,EACf,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,aAAa,EACb,WAAW,GACZ,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * What the pipeline can load: a URL string, or the id a `require()`d image
3
+ * asset evaluates to.
4
+ *
5
+ * As a string, `url` is passed to the native loader as-is. Accepted forms:
6
+ *
7
+ * - `https://` / `http://` — fetched over the network and cached on disk.
8
+ * - `file://` URLs and plain absolute paths (`/var/…/photo.jpg`) — read from
9
+ * the file system. The result is cached in memory only; there is nothing
10
+ * to gain from copying a local file into the disk cache.
11
+ * - Android also accepts `content://` URIs and, from a release build's
12
+ * resources, a bare drawable name — which is what `require()` resolves to
13
+ * there. iOS resolves `require()` to a `file://` URL into the app bundle.
14
+ *
15
+ * A `require('./photo.png')` is resolved with `Image.resolveAssetSource`, so
16
+ * it works the same in debug (streamed from Metro) and release (bundled).
17
+ */
18
+ export type ImageSource = string | number;
19
+ /**
20
+ * Turns an {@linkcode ImageSource} into the URL string the native pipeline
21
+ * loads: strings pass through unchanged, a `require()`d asset is resolved via
22
+ * `Image.resolveAssetSource` (the scale-matched variant, like `<Image>`).
23
+ *
24
+ * The components and hooks call this for you; use it when calling
25
+ * `NitroImagePipeline.loadImage`/`preLoadImage` directly with a `require()`.
26
+ * @throws If `source` is a number that is not a registered asset.
27
+ * @example
28
+ * ```ts
29
+ * const image = await NitroImagePipeline.loadImage(
30
+ * resolveImageUrl(require('./photo.png')),
31
+ * { blur: 4 },
32
+ * );
33
+ * ```
34
+ */
35
+ export declare function resolveImageUrl(source: ImageSource): string;
36
+ /**
37
+ * A URL no loader can resolve, standing in for a `require()` id that is not
38
+ * a registered asset. Its scheme has no fetcher on either platform, so the
39
+ * request fails at load time — the same way a missing file does — instead of
40
+ * throwing from a component's render.
41
+ */
42
+ export declare const UNREGISTERED_ASSET_URL = "unregistered-asset://";
43
+ /**
44
+ * {@linkcode resolveImageUrl} for code that runs during render: an
45
+ * unregistered `require()` id yields {@linkcode UNREGISTERED_ASSET_URL} (and
46
+ * a warning in development) rather than throwing.
47
+ */
48
+ export declare function resolveImageUrlOrFallback(source: ImageSource): string;
49
+ /**
50
+ * A stable, per-source `recyclingKey` for `<NativeNitroImage>`: the URL
51
+ * itself for strings, and a tag derived from the asset id for a `require()`
52
+ * (resolving it would cost an asset-registry lookup per render for nothing
53
+ * more than a distinct key).
54
+ */
55
+ export declare function recyclingKeyFor(source: ImageSource): string;
56
+ //# sourceMappingURL=resolveImageSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveImageSource.d.ts","sourceRoot":"","sources":["../../../src/resolveImageSource.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAS3D;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,0BAA0B,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAWrE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAE3D"}
@@ -1,4 +1,4 @@
1
- import type { Image } from 'react-native-nitro-image';
1
+ import type { Image, ImageLoader } from 'react-native-nitro-image';
2
2
  import type { HybridObject } from 'react-native-nitro-modules';
3
3
  export type CacheOption = 'memory' | 'disk' | 'none';
4
4
  /**
@@ -60,11 +60,66 @@ export type Options = {
60
60
  */
61
61
  resize?: ResizeOptions;
62
62
  };
63
+ /**
64
+ * Options for {@linkcode NitroImagePipeline.createImageLoader}. Unlike
65
+ * {@linkcode Options} (used by `loadImage`, where values are bitmap pixels),
66
+ * `blur` and `cornerRadius` here are in **points** (density-independent):
67
+ * the loader runs inside a view and converts to pixels natively with the
68
+ * screen scale. The one exception is {@linkcode resize}, which stays an
69
+ * explicit **pixel** size like everywhere else in the library.
70
+ */
71
+ export type ViewOptions = {
72
+ /**
73
+ * Gaussian blur sigma in **points**. Multiplied by the screen scale
74
+ * natively, so the same value looks the same on every device.
75
+ * @default 0 (no blur)
76
+ */
77
+ blur?: number;
78
+ cache?: CacheOption;
79
+ /**
80
+ * Corner radius in **points**, uniform or per-corner. Converted to pixels
81
+ * with the screen scale and baked into the bitmap at the display size.
82
+ * @default 0 (square corners)
83
+ */
84
+ cornerRadius?: number | CornerRadii;
85
+ /**
86
+ * Target bitmap size in **pixels**, overriding the size measured from the
87
+ * view. Rarely needed — without it the loader resizes to the view's
88
+ * laid-out size × screen scale, which is what you want in a UI.
89
+ * @default undefined (measure the view)
90
+ */
91
+ resize?: ResizeOptions;
92
+ };
63
93
  export interface NitroImagePipeline extends HybridObject<{
64
94
  ios: 'swift';
65
95
  android: 'kotlin';
66
96
  }> {
97
+ /**
98
+ * Loads `url` through the pipeline. Besides `http(s)://`, `url` may be a
99
+ * `file://` URL or a plain absolute path (read from the file system, cached
100
+ * in memory only), a `data:` URL, or — on Android — a `content://` URI or
101
+ * the bare resource name a `require()` resolves to in a release build. Use
102
+ * `resolveImageUrl(require('./photo.png'))` to pass a bundled asset.
103
+ */
67
104
  loadImage(url: string, options?: Options): Promise<Image>;
105
+ /**
106
+ * Creates an {@linkcode ImageLoader} for `url` that a `<NativeNitroImage>`
107
+ * view drives entirely natively: the request starts when the view attaches
108
+ * to the window — at the view's own laid-out size, with no JS round trips —
109
+ * and is cancelled (and the bitmap released) when it detaches, so
110
+ * off-screen list cells stop costing memory. Loads go through the same
111
+ * pipeline and caches as {@linkcode loadImage}/{@linkcode preLoadImage}.
112
+ *
113
+ * `options` are in **points** (see {@linkcode ViewOptions}); the loader
114
+ * applies the screen scale natively. If the view has no size yet when it
115
+ * attaches, the load waits for its first layout.
116
+ */
117
+ createImageLoader(url: string, options?: ViewOptions): ImageLoader;
118
+ /**
119
+ * Warms the disk cache with the download for `url`, without decoding it.
120
+ * Local sources (`file://`, paths, resources) have no download to warm it
121
+ * with and are a no-op.
122
+ */
68
123
  preLoadImage(url: string): Promise<void>;
69
124
  preLoadImages(urls: string[]): Promise<void>;
70
125
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"nitro-image-toolkit.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/nitro-image-toolkit.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,CA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CAAC;IAC1D;;;;;;;;;;;OAWG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IACnE;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C;;;;OAIG;IACH,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAG3D;;;;;;;;OAQG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B"}
@@ -1,4 +1,5 @@
1
1
  import type { Image } from 'react-native-nitro-image';
2
+ import { type ImageSource } from './resolveImageSource';
2
3
  import type { CacheOption, CornerRadii, ResizeOptions } from './specs/nitro-image-toolkit.nitro';
3
4
  type Result = {
4
5
  image: undefined;
@@ -11,15 +12,20 @@ type Result = {
11
12
  error: Error;
12
13
  };
13
14
  /**
14
- * A hook to asynchronously load an image from the
15
- * given {@linkcode AsyncImageSource} into memory.
15
+ * A hook to asynchronously load an image from `url` through the pipeline
16
+ * into memory.
16
17
  * @example
17
18
  * ```ts
18
- * const { image, error } = useImage({ filePath: '/tmp/image.jpg' })
19
+ * const { image, error } = useImage({ url: 'https://example.com/photo.jpg' });
20
+ * const { image: logo } = useImage({ url: require('./logo.png') });
19
21
  * ```
20
22
  */
21
23
  export declare function useImage({ url, blur, cornerRadius, resize, cache, enabled, }: {
22
- url: string;
24
+ /**
25
+ * The image to load: a URL string (`https://`, `file://`, an absolute path)
26
+ * or a `require()`d asset — see {@linkcode ImageSource}.
27
+ */
28
+ url: ImageSource;
23
29
  /**
24
30
  * Gaussian blur strength, as the standard deviation (sigma) of the blur in
25
31
  * source-image pixels (of the resized bitmap when `resize` is set). Matches
@@ -1 +1 @@
1
- {"version":3,"file":"useImage.d.ts","sourceRoot":"","sources":["../../../src/useImage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,mCAAmC,CAAC;AAE3C,KAAK,MAAM,GAEP;IACE,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC;CAClB,GAED;IACE,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;CAClB,GAED;IACE,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEN;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,EACvB,GAAG,EACH,IAAQ,EACR,YAAgB,EAChB,MAAM,EACN,KAAK,EACL,OAAc,GACf,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACpC;;;;OAIG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,MAAM,CA4ET"}
1
+ {"version":3,"file":"useImage.d.ts","sourceRoot":"","sources":["../../../src/useImage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,sBAAsB,CAAC;AACzE,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,mCAAmC,CAAC;AAE3C,KAAK,MAAM,GAEP;IACE,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC;CAClB,GAED;IACE,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;CAClB,GAED;IACE,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEN;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,EACvB,GAAG,EACH,IAAQ,EACR,YAAgB,EAChB,MAAM,EACN,KAAK,EACL,OAAc,GACf,EAAE;IACD;;;OAGG;IACH,GAAG,EAAE,WAAW,CAAC;IACjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACpC;;;;OAIG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,MAAM,CAiFT"}
@@ -0,0 +1,17 @@
1
+ import type { ImageLoader } from 'react-native-nitro-image';
2
+ import { type ImageSource } from './resolveImageSource';
3
+ import type { ViewOptions } from './specs/nitro-image-toolkit.nitro';
4
+ /**
5
+ * Creates (and memoizes) an {@linkcode ImageLoader} for `source` — a URL
6
+ * string or a `require()`d asset, see {@linkcode ImageSource} — to pass to
7
+ * `<NativeNitroImage image={...} />`. The view drives it entirely natively:
8
+ * the request starts when the view attaches — at the view's laid-out size,
9
+ * with no JS round trips — and is cancelled when it detaches. See
10
+ * {@linkcode NitroImagePipeline.createImageLoader}.
11
+ *
12
+ * `blur`/`cornerRadius` are in **points** (unlike `useImage`, where they are
13
+ * bitmap pixels); the screen scale is applied natively. Inline object
14
+ * literals are fine — options are compared by value, not identity.
15
+ */
16
+ export declare function usePipelineImageLoader(source: ImageSource, options?: ViewOptions): ImageLoader;
17
+ //# sourceMappingURL=usePipelineImageLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePipelineImageLoader.d.ts","sourceRoot":"","sources":["../../../src/usePipelineImageLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EACL,KAAK,WAAW,EAEjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAEV,WAAW,EACZ,MAAM,mCAAmC,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,WAAW,GACpB,WAAW,CA6Db"}
@@ -9,6 +9,8 @@
9
9
 
10
10
  // Forward declaration of `HybridImageSpec` to properly resolve imports.
11
11
  namespace margelo::nitro::image { class HybridImageSpec; }
12
+ // Forward declaration of `HybridImageLoaderSpec` to properly resolve imports.
13
+ namespace margelo::nitro::image { class HybridImageLoaderSpec; }
12
14
  // Forward declaration of `Options` to properly resolve imports.
13
15
  namespace margelo::nitro::nitroimagepipeline { struct Options; }
14
16
  // Forward declaration of `CacheOption` to properly resolve imports.
@@ -17,12 +19,16 @@ namespace margelo::nitro::nitroimagepipeline { enum class CacheOption; }
17
19
  namespace margelo::nitro::nitroimagepipeline { struct CornerRadii; }
18
20
  // Forward declaration of `ResizeOptions` to properly resolve imports.
19
21
  namespace margelo::nitro::nitroimagepipeline { struct ResizeOptions; }
22
+ // Forward declaration of `ViewOptions` to properly resolve imports.
23
+ namespace margelo::nitro::nitroimagepipeline { struct ViewOptions; }
20
24
 
21
25
  #include <memory>
22
26
  #include <NitroImage/HybridImageSpec.hpp>
23
27
  #include <NitroModules/Promise.hpp>
24
28
  #include <NitroModules/JPromise.hpp>
25
29
  #include <NitroImage/JHybridImageSpec.hpp>
30
+ #include <NitroImage/HybridImageLoaderSpec.hpp>
31
+ #include <NitroImage/JHybridImageLoaderSpec.hpp>
26
32
  #include <NitroModules/JUnit.hpp>
27
33
  #include <string>
28
34
  #include "Options.hpp"
@@ -36,6 +42,8 @@ namespace margelo::nitro::nitroimagepipeline { struct ResizeOptions; }
36
42
  #include "JCornerRadii.hpp"
37
43
  #include "ResizeOptions.hpp"
38
44
  #include "JResizeOptions.hpp"
45
+ #include "ViewOptions.hpp"
46
+ #include "JViewOptions.hpp"
39
47
  #include <vector>
40
48
 
41
49
  namespace margelo::nitro::nitroimagepipeline {
@@ -87,6 +95,11 @@ namespace margelo::nitro::nitroimagepipeline {
87
95
  return __promise;
88
96
  }();
89
97
  }
98
+ std::shared_ptr<margelo::nitro::image::HybridImageLoaderSpec> JHybridNitroImagePipelineSpec::createImageLoader(const std::string& url, const std::optional<ViewOptions>& options) {
99
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<margelo::nitro::image::JHybridImageLoaderSpec::JavaPart>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<JViewOptions> /* options */)>("createImageLoader");
100
+ auto __result = method(_javaPart, jni::make_jstring(url), options.has_value() ? JViewOptions::fromCpp(options.value()) : nullptr);
101
+ return __result->getJHybridImageLoaderSpec();
102
+ }
90
103
  std::shared_ptr<Promise<void>> JHybridNitroImagePipelineSpec::preLoadImage(const std::string& url) {
91
104
  static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */)>("preLoadImage");
92
105
  auto __result = method(_javaPart, jni::make_jstring(url));
@@ -55,6 +55,7 @@ namespace margelo::nitro::nitroimagepipeline {
55
55
  public:
56
56
  // Methods
57
57
  std::shared_ptr<Promise<std::shared_ptr<margelo::nitro::image::HybridImageSpec>>> loadImage(const std::string& url, const std::optional<Options>& options) override;
58
+ std::shared_ptr<margelo::nitro::image::HybridImageLoaderSpec> createImageLoader(const std::string& url, const std::optional<ViewOptions>& options) override;
58
59
  std::shared_ptr<Promise<void>> preLoadImage(const std::string& url) override;
59
60
  std::shared_ptr<Promise<void>> preLoadImages(const std::vector<std::string>& urls) override;
60
61
  std::shared_ptr<Promise<std::shared_ptr<margelo::nitro::image::HybridImageSpec>>> gaussianBlur(const std::shared_ptr<margelo::nitro::image::HybridImageSpec>& image, double radius) override;
@@ -0,0 +1,77 @@
1
+ ///
2
+ /// JViewOptions.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "ViewOptions.hpp"
12
+
13
+ #include "CacheOption.hpp"
14
+ #include "CornerRadii.hpp"
15
+ #include "JCacheOption.hpp"
16
+ #include "JCornerRadii.hpp"
17
+ #include "JResizeOptions.hpp"
18
+ #include "JVariant_Double_CornerRadii.hpp"
19
+ #include "ResizeOptions.hpp"
20
+ #include <optional>
21
+ #include <variant>
22
+
23
+ namespace margelo::nitro::nitroimagepipeline {
24
+
25
+ using namespace facebook;
26
+
27
+ /**
28
+ * The C++ JNI bridge between the C++ struct "ViewOptions" and the Kotlin data class "ViewOptions".
29
+ */
30
+ struct JViewOptions final: public jni::JavaClass<JViewOptions> {
31
+ public:
32
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroimagepipeline/ViewOptions;";
33
+
34
+ public:
35
+ /**
36
+ * Convert this Java/Kotlin-based struct to the C++ struct ViewOptions by copying all values to C++.
37
+ */
38
+ [[maybe_unused]]
39
+ [[nodiscard]]
40
+ ViewOptions toCpp() const {
41
+ static const auto clazz = javaClassStatic();
42
+ static const auto fieldBlur = clazz->getField<jni::JDouble>("blur");
43
+ jni::local_ref<jni::JDouble> blur = this->getFieldValue(fieldBlur);
44
+ static const auto fieldCache = clazz->getField<JCacheOption>("cache");
45
+ jni::local_ref<JCacheOption> cache = this->getFieldValue(fieldCache);
46
+ static const auto fieldCornerRadius = clazz->getField<JVariant_Double_CornerRadii>("cornerRadius");
47
+ jni::local_ref<JVariant_Double_CornerRadii> cornerRadius = this->getFieldValue(fieldCornerRadius);
48
+ static const auto fieldResize = clazz->getField<JResizeOptions>("resize");
49
+ jni::local_ref<JResizeOptions> resize = this->getFieldValue(fieldResize);
50
+ return ViewOptions(
51
+ blur != nullptr ? std::make_optional(blur->value()) : std::nullopt,
52
+ cache != nullptr ? std::make_optional(cache->toCpp()) : std::nullopt,
53
+ cornerRadius != nullptr ? std::make_optional(cornerRadius->toCpp()) : std::nullopt,
54
+ resize != nullptr ? std::make_optional(resize->toCpp()) : std::nullopt
55
+ );
56
+ }
57
+
58
+ public:
59
+ /**
60
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
61
+ */
62
+ [[maybe_unused]]
63
+ static jni::local_ref<JViewOptions::javaobject> fromCpp(const ViewOptions& value) {
64
+ using JSignature = JViewOptions(jni::alias_ref<jni::JDouble>, jni::alias_ref<JCacheOption>, jni::alias_ref<JVariant_Double_CornerRadii>, jni::alias_ref<JResizeOptions>);
65
+ static const auto clazz = javaClassStatic();
66
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
67
+ return create(
68
+ clazz,
69
+ value.blur.has_value() ? jni::JDouble::valueOf(value.blur.value()) : nullptr,
70
+ value.cache.has_value() ? JCacheOption::fromCpp(value.cache.value()) : nullptr,
71
+ value.cornerRadius.has_value() ? JVariant_Double_CornerRadii::fromCpp(value.cornerRadius.value()) : nullptr,
72
+ value.resize.has_value() ? JResizeOptions::fromCpp(value.resize.value()) : nullptr
73
+ );
74
+ }
75
+ };
76
+
77
+ } // namespace margelo::nitro::nitroimagepipeline
@@ -13,6 +13,7 @@ import com.facebook.proguard.annotations.DoNotStrip
13
13
  import dalvik.annotation.optimization.FastNative
14
14
  import com.margelo.nitro.image.HybridImageSpec
15
15
  import com.margelo.nitro.core.Promise
16
+ import com.margelo.nitro.image.HybridImageLoaderSpec
16
17
  import com.margelo.nitro.core.HybridObject
17
18
 
18
19
  /**
@@ -35,6 +36,10 @@ abstract class HybridNitroImagePipelineSpec: HybridObject() {
35
36
  @Keep
36
37
  abstract fun loadImage(url: String, options: Options?): Promise<com.margelo.nitro.image.HybridImageSpec>
37
38
 
39
+ @DoNotStrip
40
+ @Keep
41
+ abstract fun createImageLoader(url: String, options: ViewOptions?): com.margelo.nitro.image.HybridImageLoaderSpec
42
+
38
43
  @DoNotStrip
39
44
  @Keep
40
45
  abstract fun preLoadImage(url: String): Promise<Unit>
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// ViewOptions.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.nitroimagepipeline
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "ViewOptions".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class ViewOptions(
21
+ @DoNotStrip
22
+ @Keep
23
+ val blur: Double?,
24
+ @DoNotStrip
25
+ @Keep
26
+ val cache: CacheOption?,
27
+ @DoNotStrip
28
+ @Keep
29
+ val cornerRadius: Variant_Double_CornerRadii?,
30
+ @DoNotStrip
31
+ @Keep
32
+ val resize: ResizeOptions?
33
+ ) {
34
+ /* primary constructor */
35
+
36
+ override fun equals(other: Any?): Boolean {
37
+ if (this === other) return true
38
+ if (other !is ViewOptions) return false
39
+ return Objects.deepEquals(this.blur, other.blur)
40
+ && Objects.deepEquals(this.cache, other.cache)
41
+ && Objects.deepEquals(this.cornerRadius, other.cornerRadius)
42
+ && Objects.deepEquals(this.resize, other.resize)
43
+ }
44
+
45
+ override fun hashCode(): Int {
46
+ return arrayOf<Any?>(
47
+ blur,
48
+ cache,
49
+ cornerRadius,
50
+ resize
51
+ ).contentDeepHashCode()
52
+ }
53
+
54
+ companion object {
55
+ /**
56
+ * Constructor called from C++
57
+ */
58
+ @DoNotStrip
59
+ @Keep
60
+ @Suppress("unused")
61
+ @JvmStatic
62
+ private fun fromCpp(blur: Double?, cache: CacheOption?, cornerRadius: Variant_Double_CornerRadii?, resize: ResizeOptions?): ViewOptions {
63
+ return ViewOptions(blur, cache, cornerRadius, resize)
64
+ }
65
+ }
66
+ }
@@ -41,6 +41,16 @@ namespace margelo::nitro::nitroimagepipeline::bridge::swift {
41
41
  };
42
42
  }
43
43
 
44
+ // pragma MARK: std::shared_ptr<margelo::nitro::image::HybridImageLoaderSpec>
45
+ std::shared_ptr<margelo::nitro::image::HybridImageLoaderSpec> create_std__shared_ptr_margelo__nitro__image__HybridImageLoaderSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
46
+ // Implemented in NitroImage
47
+ return margelo::nitro::image::bridge::swift::create_std__shared_ptr_HybridImageLoaderSpec_(swiftUnsafePointer);
48
+ }
49
+ void* NON_NULL get_std__shared_ptr_margelo__nitro__image__HybridImageLoaderSpec_(std__shared_ptr_margelo__nitro__image__HybridImageLoaderSpec_ cppType) {
50
+ // Implemented in NitroImage
51
+ return margelo::nitro::image::bridge::swift::get_std__shared_ptr_HybridImageLoaderSpec_(cppType);
52
+ }
53
+
44
54
  // pragma MARK: std::function<void()>
45
55
  Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept {
46
56
  auto swiftClosure = NitroImagePipeline::Func_void::fromUnsafe(swiftClosureWrapper);