react-native-nitro-image-pipeline 1.6.0 → 1.7.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.
- package/README.md +88 -13
- package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/HybridNitroImagePipeline.kt +51 -20
- package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/PipelineImageLoader.kt +47 -8
- package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/transform/FitGeometry.kt +104 -0
- package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/transform/PipelineRoundedCornersTransformation.kt +103 -0
- package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/transform/ResizeTransformation.kt +69 -16
- package/ios/FitResizeProcessor.swift +127 -0
- package/ios/HybridNitroImagePipeline.swift +41 -15
- package/ios/PipelineImageLoader.swift +107 -17
- package/lib/commonjs/NativePipelineImage.js +18 -3
- package/lib/commonjs/NativePipelineImage.js.map +1 -1
- package/lib/commonjs/PipelineImage.js +13 -1
- package/lib/commonjs/PipelineImage.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/resizeForStyle.js +3 -1
- package/lib/commonjs/resizeForStyle.js.map +1 -1
- package/lib/commonjs/useImage.js +6 -2
- package/lib/commonjs/useImage.js.map +1 -1
- package/lib/commonjs/usePipelineImageLoader.js +107 -9
- package/lib/commonjs/usePipelineImageLoader.js.map +1 -1
- package/lib/module/NativePipelineImage.js +18 -3
- package/lib/module/NativePipelineImage.js.map +1 -1
- package/lib/module/PipelineImage.js +13 -1
- package/lib/module/PipelineImage.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/resizeForStyle.js +3 -1
- package/lib/module/resizeForStyle.js.map +1 -1
- package/lib/module/useImage.js +6 -2
- package/lib/module/useImage.js.map +1 -1
- package/lib/module/usePipelineImageLoader.js +108 -10
- package/lib/module/usePipelineImageLoader.js.map +1 -1
- package/lib/typescript/src/NativePipelineImage.d.ts +44 -3
- package/lib/typescript/src/NativePipelineImage.d.ts.map +1 -1
- package/lib/typescript/src/PipelineImage.d.ts +28 -1
- package/lib/typescript/src/PipelineImage.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/resizeForStyle.d.ts +3 -1
- package/lib/typescript/src/resizeForStyle.d.ts.map +1 -1
- package/lib/typescript/src/specs/nitro-image-toolkit.nitro.d.ts +83 -8
- package/lib/typescript/src/specs/nitro-image-toolkit.nitro.d.ts.map +1 -1
- package/lib/typescript/src/useImage.d.ts +3 -2
- package/lib/typescript/src/useImage.d.ts.map +1 -1
- package/lib/typescript/src/usePipelineImageLoader.d.ts +3 -1
- package/lib/typescript/src/usePipelineImageLoader.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroImagePipelineOnLoad.cpp +4 -0
- package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridNitroImagePipelineSpec.cpp +8 -0
- package/nitrogen/generated/android/c++/JOptions.hpp +2 -0
- package/nitrogen/generated/android/c++/JResizeFit.hpp +64 -0
- package/nitrogen/generated/android/c++/JResizeOptions.hpp +14 -4
- package/nitrogen/generated/android/c++/JViewOptions.hpp +42 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/Func_void_double_double.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/Func_void_std__string.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/ResizeFit.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/ResizeOptions.kt +14 -4
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/ViewOptions.kt +29 -5
- package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Bridge.cpp +16 -0
- package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Bridge.hpp +107 -0
- package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Umbrella.hpp +4 -0
- package/nitrogen/generated/ios/c++/HybridNitroImagePipelineSpecSwift.hpp +4 -0
- package/nitrogen/generated/ios/swift/Func_void_double_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/ResizeFit.swift +48 -0
- package/nitrogen/generated/ios/swift/ResizeOptions.swift +31 -2
- package/nitrogen/generated/ios/swift/ViewOptions.swift +82 -1
- package/nitrogen/generated/shared/c++/ResizeFit.hpp +84 -0
- package/nitrogen/generated/shared/c++/ResizeOptions.hpp +14 -4
- package/nitrogen/generated/shared/c++/ViewOptions.hpp +24 -3
- package/package.json +1 -1
- package/src/NativePipelineImage.tsx +67 -3
- package/src/PipelineImage.tsx +39 -1
- package/src/index.ts +1 -0
- package/src/resizeForStyle.ts +3 -1
- package/src/specs/nitro-image-toolkit.nitro.ts +84 -8
- package/src/useImage.ts +13 -3
- package/src/usePipelineImageLoader.ts +115 -8
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { useMemo } from 'react';
|
|
3
|
+
import { useLayoutEffect, useMemo, useRef } from 'react';
|
|
4
4
|
import { NitroImagePipeline } from './NitroImagePipeline';
|
|
5
5
|
import { resolveImageUrlOrFallback } from './resolveImageSource';
|
|
6
|
+
// Identifies a loader in the callbacks below without them capturing it. A
|
|
7
|
+
// callback the native loader owns that captured the loader back would be a
|
|
8
|
+
// cycle across the language boundary — neither side collectable, and the JS
|
|
9
|
+
// runtime left to take it apart at teardown.
|
|
10
|
+
let nextLoaderToken = 0;
|
|
11
|
+
/**
|
|
12
|
+
* The callbacks handed to a native loader. Built out here, where the scope
|
|
13
|
+
* holds nothing but the token and the two refs, so the loader can't end up
|
|
14
|
+
* captured by a callback it owns.
|
|
15
|
+
*/
|
|
16
|
+
function makeReporters(token, activeToken, callbacks) {
|
|
17
|
+
return {
|
|
18
|
+
onLoad: (width, height) => {
|
|
19
|
+
if (activeToken.current === token) {
|
|
20
|
+
callbacks.current.onLoad?.(width, height);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
onError: message => {
|
|
24
|
+
if (activeToken.current === token) {
|
|
25
|
+
callbacks.current.onError?.(message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
6
31
|
/**
|
|
7
32
|
* Creates (and memoizes) an {@linkcode ImageLoader} for `source` — a URL
|
|
8
33
|
* string or a `require()`d asset, see {@linkcode ImageSource} — to pass to
|
|
@@ -13,7 +38,9 @@ import { resolveImageUrlOrFallback } from './resolveImageSource';
|
|
|
13
38
|
*
|
|
14
39
|
* `blur`/`cornerRadius` are in **points** (unlike `useImage`, where they are
|
|
15
40
|
* bitmap pixels); the screen scale is applied natively. Inline object
|
|
16
|
-
* literals are fine — options are compared by value, not identity
|
|
41
|
+
* literals are fine — options are compared by value, not identity, and the
|
|
42
|
+
* `onLoad`/`onError` callbacks are read through a ref, so inline arrows don't
|
|
43
|
+
* recreate the loader either.
|
|
17
44
|
*/
|
|
18
45
|
export function usePipelineImageLoader(source, options) {
|
|
19
46
|
// Split the options into primitives (like useImage does) so an inline
|
|
@@ -33,7 +60,42 @@ export function usePipelineImageLoader(source, options) {
|
|
|
33
60
|
} = isUniformRadius || cornerRadius === undefined ? {} : cornerRadius;
|
|
34
61
|
const resizeWidth = options?.resize?.width;
|
|
35
62
|
const resizeHeight = options?.resize?.height;
|
|
36
|
-
|
|
63
|
+
const resizeFit = options?.resize?.fit;
|
|
64
|
+
const resizeAllowUpscale = options?.resize?.allowUpscale;
|
|
65
|
+
const fit = options?.fit;
|
|
66
|
+
const allowUpscale = options?.allowUpscale;
|
|
67
|
+
const onLoad = options?.onLoad;
|
|
68
|
+
const onError = options?.onError;
|
|
69
|
+
// Only *whether* a callback is set can change the loader: what the native
|
|
70
|
+
// side gets is a wrapper that reads the latest callbacks from a ref (like
|
|
71
|
+
// PipelineImage does). So an inline arrow — a new identity every render —
|
|
72
|
+
// doesn't recreate the loader and re-trigger the native load.
|
|
73
|
+
const hasOnLoad = onLoad !== undefined;
|
|
74
|
+
const hasOnError = onError !== undefined;
|
|
75
|
+
const callbacks = useRef({
|
|
76
|
+
onLoad,
|
|
77
|
+
onError
|
|
78
|
+
});
|
|
79
|
+
// A layout effect, not a passive one: passive effects are flushed in a later
|
|
80
|
+
// task, so a load reported between the commit and that flush would read the
|
|
81
|
+
// previous render's callbacks — a callback added alongside a new loader
|
|
82
|
+
// could miss its only event. This runs in the same task as the commit, and
|
|
83
|
+
// the view can't reach the loader before the commit installs it, so the ref
|
|
84
|
+
// is always current by the time native calls back. (Assigning it during
|
|
85
|
+
// render instead would mutate on renders React throws away.)
|
|
86
|
+
useLayoutEffect(() => {
|
|
87
|
+
callbacks.current = {
|
|
88
|
+
onLoad,
|
|
89
|
+
onError
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
// The token of the loader the view is currently on. Swapping loaders (a
|
|
93
|
+
// changed url or options) never drops the old one — the view just stops
|
|
94
|
+
// referring to it — so a load it already had in flight can still report.
|
|
95
|
+
// Without this check the wrappers, which read the latest callbacks, would
|
|
96
|
+
// hand the previous image's size to the current `onLoad`.
|
|
97
|
+
const activeToken = useRef(-1);
|
|
98
|
+
const memoized = useMemo(() => {
|
|
37
99
|
// Runs during render, so an unregistered `require()` id must not throw:
|
|
38
100
|
// it becomes a URL the native loader fails on at load time instead.
|
|
39
101
|
const url = resolveImageUrlOrFallback(source);
|
|
@@ -43,28 +105,64 @@ export function usePipelineImageLoader(source, options) {
|
|
|
43
105
|
bottomLeft,
|
|
44
106
|
bottomRight
|
|
45
107
|
} : undefined;
|
|
108
|
+
// What is loaded — the callbacks are deliberately not part of it, so two
|
|
109
|
+
// loaders that differ only in them are the same image.
|
|
46
110
|
const stableOptions = {
|
|
47
111
|
blur,
|
|
48
112
|
cache,
|
|
49
113
|
cornerRadius: cornerRadiusOption,
|
|
50
114
|
resize: resizeWidth !== undefined && resizeHeight !== undefined ? {
|
|
51
115
|
width: resizeWidth,
|
|
52
|
-
height: resizeHeight
|
|
53
|
-
|
|
116
|
+
height: resizeHeight,
|
|
117
|
+
fit: resizeFit,
|
|
118
|
+
allowUpscale: resizeAllowUpscale
|
|
119
|
+
} : undefined,
|
|
120
|
+
fit,
|
|
121
|
+
allowUpscale
|
|
54
122
|
};
|
|
55
|
-
const
|
|
123
|
+
const token = nextLoaderToken++;
|
|
124
|
+
// The reporters read the refs, but only when the native side calls them —
|
|
125
|
+
// the rule can't see that they aren't called here.
|
|
126
|
+
// oxlint-disable-next-line react/refs
|
|
127
|
+
const reporters = makeReporters(token, activeToken, callbacks);
|
|
128
|
+
const loader = NitroImagePipeline.createImageLoader(url, {
|
|
129
|
+
...stableOptions,
|
|
130
|
+
// Passed only when the caller wants them: without a callback nothing
|
|
131
|
+
// ever crosses into JS, which is the point of the native path.
|
|
132
|
+
onLoad: hasOnLoad ? reporters.onLoad : undefined,
|
|
133
|
+
onError: hasOnError ? reporters.onError : undefined
|
|
134
|
+
});
|
|
56
135
|
// `NativeNitroImage` needs a way to tell two loader instances apart when
|
|
57
136
|
// diffing its `image` prop; tag the loader with what it will load (the
|
|
58
|
-
// same convention react-native-nitro-image's own loaders use).
|
|
137
|
+
// same convention react-native-nitro-image's own loaders use). Toggling a
|
|
138
|
+
// callback on or off makes a different loader, so the tag has to say so —
|
|
139
|
+
// otherwise the view keeps the old one installed. Their identities stay
|
|
140
|
+
// out of it: those don't change what is loaded, or which loader this is.
|
|
59
141
|
Object.defineProperty(loader, '__source', {
|
|
60
142
|
enumerable: true,
|
|
61
143
|
configurable: true,
|
|
62
144
|
value: {
|
|
63
145
|
url,
|
|
64
|
-
options: stableOptions
|
|
146
|
+
options: stableOptions,
|
|
147
|
+
callbacks: {
|
|
148
|
+
onLoad: hasOnLoad,
|
|
149
|
+
onError: hasOnError
|
|
150
|
+
}
|
|
65
151
|
}
|
|
66
152
|
});
|
|
67
|
-
return
|
|
68
|
-
|
|
153
|
+
return {
|
|
154
|
+
loader,
|
|
155
|
+
token
|
|
156
|
+
};
|
|
157
|
+
}, [source, blur, cache, isUniformRadius, uniformRadius, hasCornerObject, topLeft, topRight, bottomLeft, bottomRight, resizeWidth, resizeHeight, resizeFit, resizeAllowUpscale, fit, allowUpscale, hasOnLoad, hasOnError,
|
|
158
|
+
// Stable ref objects; listed to satisfy the exhaustive-deps rules.
|
|
159
|
+
activeToken, callbacks]);
|
|
160
|
+
|
|
161
|
+
// Same reasoning as the callbacks ref: a layout effect is current before the
|
|
162
|
+
// view — which the commit has only just handed this loader — can report.
|
|
163
|
+
useLayoutEffect(() => {
|
|
164
|
+
activeToken.current = memoized.token;
|
|
165
|
+
}, [memoized, activeToken]);
|
|
166
|
+
return memoized.loader;
|
|
69
167
|
}
|
|
70
168
|
//# sourceMappingURL=usePipelineImageLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","NitroImagePipeline","resolveImageUrlOrFallback","usePipelineImageLoader","source","options","blur","cache","cornerRadius","isUniformRadius","uniformRadius","hasCornerObject","undefined","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","resize","
|
|
1
|
+
{"version":3,"names":["useLayoutEffect","useMemo","useRef","NitroImagePipeline","resolveImageUrlOrFallback","nextLoaderToken","makeReporters","token","activeToken","callbacks","onLoad","width","height","current","onError","message","usePipelineImageLoader","source","options","blur","cache","cornerRadius","isUniformRadius","uniformRadius","hasCornerObject","undefined","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","resize","resizeHeight","resizeFit","fit","resizeAllowUpscale","allowUpscale","hasOnLoad","hasOnError","memoized","url","cornerRadiusOption","stableOptions","reporters","loader","createImageLoader","Object","defineProperty","enumerable","configurable","value"],"sourceRoot":"../../src","sources":["usePipelineImageLoader.ts"],"mappings":";;AAAA,SAAyBA,eAA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CAAC;;EAEF;EACA;EACAT,eAAe,CAAC,MAAM;IACpBQ,WAAW,CAACK,OAAO,GAAG0B,QAAQ,CAAChC,KAAK;EACtC,CAAC,EAAE,CAACgC,QAAQ,EAAE/B,WAAW,CAAC,CAAC;EAE3B,OAAO+B,QAAQ,CAACK,MAAM;AACxB","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import { type ComponentRef } from 'react';
|
|
|
2
2
|
import type { HostComponent } from 'react-native';
|
|
3
3
|
import { NativeNitroImage } from 'react-native-nitro-image';
|
|
4
4
|
import { type ImageSource } from './resolveImageSource';
|
|
5
|
-
import type { CacheOption, CornerRadii, ResizeOptions } from './specs/nitro-image-toolkit.nitro';
|
|
5
|
+
import type { CacheOption, CornerRadii, ResizeFit, ResizeOptions } from './specs/nitro-image-toolkit.nitro';
|
|
6
6
|
type ReactProps<T> = T extends HostComponent<infer P> ? P : never;
|
|
7
7
|
type NativeImageProps = ReactProps<typeof NativeNitroImage>;
|
|
8
8
|
/**
|
|
@@ -38,6 +38,46 @@ export interface NativePipelineImageProps extends Omit<NativeImageProps, 'image'
|
|
|
38
38
|
* @default undefined (measure the view natively)
|
|
39
39
|
*/
|
|
40
40
|
resize?: ResizeOptions;
|
|
41
|
+
/**
|
|
42
|
+
* How the source is fitted into the measured view size when the bitmap is
|
|
43
|
+
* produced — see {@linkcode ResizeFit}. When omitted it follows
|
|
44
|
+
* `resizeMode`, like `PipelineImage`. Set this to decouple the two.
|
|
45
|
+
* @default undefined (derived from `resizeMode`, or `'cover'` if unset)
|
|
46
|
+
*/
|
|
47
|
+
fit?: ResizeFit;
|
|
48
|
+
/**
|
|
49
|
+
* `false` never enlarges a source smaller than the view when the
|
|
50
|
+
* **bitmap** is produced — see {@linkcode ResizeOptions.allowUpscale}: it
|
|
51
|
+
* stays at its own pixel size, so nothing is decoded or blurred larger
|
|
52
|
+
* than the source. The **view** still displays that bitmap per
|
|
53
|
+
* `resizeMode`, so `cover`/`contain`/`stretch` scale it up on screen (and
|
|
54
|
+
* a baked `blur`/`cornerRadius` with it); `resizeMode="center"` shows it
|
|
55
|
+
* pixel for pixel instead, on both platforms.
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
allowUpscale?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Called when the view has displayed the image, with the size of the bitmap
|
|
61
|
+
* it displays in **pixels**.
|
|
62
|
+
*
|
|
63
|
+
* Unlike `PipelineImage`'s `onLoad` this doesn't hand you the `Image` — the
|
|
64
|
+
* bitmap stays native, which is the point of this component — and it means
|
|
65
|
+
* "the view is now showing this image" rather than firing exactly once: a
|
|
66
|
+
* recycled cell re-attaching calls it again, and a single view may call it
|
|
67
|
+
* more than once for the same image. Make it idempotent.
|
|
68
|
+
*
|
|
69
|
+
* Setting it means there is per-image JS work again; leave it unset and the
|
|
70
|
+
* component stays free of JS round trips.
|
|
71
|
+
*/
|
|
72
|
+
onLoad?: (width: number, height: number) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Called when loading fails, with the underlying error's message. A load
|
|
75
|
+
* cancelled by the view detaching is not a failure and doesn't call this.
|
|
76
|
+
*
|
|
77
|
+
* Without it, failures on this component are silent — there is no `Image`
|
|
78
|
+
* and no promise to surface them.
|
|
79
|
+
*/
|
|
80
|
+
onError?: (message: string) => void;
|
|
41
81
|
}
|
|
42
82
|
/**
|
|
43
83
|
* The fully native-driven variant of `PipelineImage`: after the first render
|
|
@@ -48,8 +88,9 @@ export interface NativePipelineImageProps extends Omit<NativeImageProps, 'image'
|
|
|
48
88
|
* the same pipeline and caches as `useImage`/`preLoadImage`.
|
|
49
89
|
*
|
|
50
90
|
* Compared to `PipelineImage`:
|
|
51
|
-
* -
|
|
52
|
-
* JS
|
|
91
|
+
* - `onLoad` reports the bitmap's pixel size rather than the `Image` itself,
|
|
92
|
+
* which never crosses into JS, and can fire more than once for a view. Use
|
|
93
|
+
* `PipelineImage` (or `useImage`) when you need the `Image`.
|
|
53
94
|
* - The bitmap is loaded once at the size the view first has; if the view is
|
|
54
95
|
* resized later, the bitmap scales with it instead of reloading.
|
|
55
96
|
* @example
|
|
@@ -1 +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;
|
|
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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
|
|
|
2
2
|
import { type HostComponent } from 'react-native';
|
|
3
3
|
import { type Image, NativeNitroImage } from 'react-native-nitro-image';
|
|
4
4
|
import type { ImageSource } from './resolveImageSource';
|
|
5
|
-
import type { CacheOption, CornerRadii } from './specs/nitro-image-toolkit.nitro';
|
|
5
|
+
import type { CacheOption, CornerRadii, ResizeFit } from './specs/nitro-image-toolkit.nitro';
|
|
6
6
|
type ReactProps<T> = T extends HostComponent<infer P> ? P : never;
|
|
7
7
|
type NativeImageProps = ReactProps<typeof NativeNitroImage>;
|
|
8
8
|
/**
|
|
@@ -38,6 +38,33 @@ export interface PipelineImageProps extends Omit<NativeImageProps, 'image'> {
|
|
|
38
38
|
*/
|
|
39
39
|
cornerRadius?: number | CornerRadii;
|
|
40
40
|
cache?: CacheOption;
|
|
41
|
+
/**
|
|
42
|
+
* How the source is fitted into the display size when the bitmap is
|
|
43
|
+
* produced — see {@linkcode ResizeFit}. When omitted it follows
|
|
44
|
+
* `resizeMode`, so `resizeMode="contain"` decodes an aspect-fitted bitmap
|
|
45
|
+
* (no crop, no padding) instead of a center-cropped one the view then
|
|
46
|
+
* letterboxes. Set this to decouple the two.
|
|
47
|
+
*
|
|
48
|
+
* One iOS caveat, inherited from nitro-image's `Image`: an `Image` handed
|
|
49
|
+
* to the view is a scale-1 image, which `resizeMode="center"` — the one
|
|
50
|
+
* mode that draws an image at its own size — shows at 1 pt per pixel,
|
|
51
|
+
* i.e. `PixelRatio.get()`× larger than Android draws it. The bitmap is
|
|
52
|
+
* right; the display is not. `NativePipelineImage` draws `center` pixel
|
|
53
|
+
* for pixel on both platforms; use it when you need that mode.
|
|
54
|
+
* @default undefined (derived from `resizeMode`, or `'cover'` if unset)
|
|
55
|
+
*/
|
|
56
|
+
fit?: ResizeFit;
|
|
57
|
+
/**
|
|
58
|
+
* `false` never enlarges a source smaller than the display size when the
|
|
59
|
+
* **bitmap** is produced — see {@linkcode ResizeOptions.allowUpscale}: it
|
|
60
|
+
* stays at its own pixel size, so nothing is decoded or blurred larger
|
|
61
|
+
* than the source. The **view** still displays that bitmap per
|
|
62
|
+
* `resizeMode`, so `cover`/`contain`/`stretch` scale it up on screen (and
|
|
63
|
+
* a baked `blur`/`cornerRadius` with it); `resizeMode="center"` shows it
|
|
64
|
+
* at its natural size instead.
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
allowUpscale?: boolean;
|
|
41
68
|
/** Called with the processed `Image` each time a new variant resolves. */
|
|
42
69
|
onLoad?: (image: Image) => void;
|
|
43
70
|
/** Called when loading fails. */
|
|
@@ -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,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EACV,WAAW,EACX,WAAW,
|
|
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,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,SAAS,EAEV,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,WAAW,kBAAmB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC;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;;;;;;;;;;;;;;OAcG;IACH,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,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;;;;;4FA+EzB,CAAC"}
|
|
@@ -3,7 +3,7 @@ export { NitroImagePipeline } from './NitroImagePipeline';
|
|
|
3
3
|
export { PipelineImage, type PipelineImageProps, type PipelineImageRef, } from './PipelineImage';
|
|
4
4
|
export { type ImageSource, resolveImageUrl, UNREGISTERED_ASSET_URL, } from './resolveImageSource';
|
|
5
5
|
export { cornerRadiusForStyle, resizeForLayout, resizeForStyle, } from './resizeForStyle';
|
|
6
|
-
export type { CacheOption, CornerRadii, Options, ResizeOptions, ViewOptions, } from './specs/nitro-image-toolkit.nitro';
|
|
6
|
+
export type { CacheOption, CornerRadii, Options, ResizeFit, ResizeOptions, ViewOptions, } from './specs/nitro-image-toolkit.nitro';
|
|
7
7
|
export { useImage } from './useImage';
|
|
8
8
|
export { usePipelineImageLoader } from './usePipelineImageLoader';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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"}
|
|
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,SAAS,EACT,aAAa,EACb,WAAW,GACZ,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -3,7 +3,9 @@ import type { CornerRadii, ResizeOptions } from './specs/nitro-image-toolkit.nit
|
|
|
3
3
|
/**
|
|
4
4
|
* Converts a layout size in points (dp) to the pipeline's `resize` option in
|
|
5
5
|
* whole bitmap pixels using `PixelRatio.getPixelSizeForLayoutSize`. Returns
|
|
6
|
-
* `undefined` unless both values are positive numbers.
|
|
6
|
+
* `undefined` unless both values are positive numbers. Spread a `fit` into
|
|
7
|
+
* the result for the other resize modes — under `contain` and `center` the
|
|
8
|
+
* size is the box the bitmap fits in, not necessarily its final size.
|
|
7
9
|
*/
|
|
8
10
|
export declare function resizeForLayout(width: unknown, height: unknown): ResizeOptions | undefined;
|
|
9
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resizeForStyle.d.ts","sourceRoot":"","sources":["../../../src/resizeForStyle.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACd,MAAM,mCAAmC,CAAC;AAE3C
|
|
1
|
+
{"version":3,"file":"resizeForStyle.d.ts","sourceRoot":"","sources":["../../../src/resizeForStyle.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACd,MAAM,mCAAmC,CAAC;AAE3C;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,OAAO,GACd,aAAa,GAAG,SAAS,CAS3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,GAC1B,aAAa,GAAG,SAAS,CAG3B;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,GAC1B,MAAM,GAAG,WAAW,GAAG,SAAS,CAoClC"}
|
|
@@ -12,13 +12,45 @@ export interface CornerRadii {
|
|
|
12
12
|
bottomRight?: number;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* How the source is fitted into the {@linkcode ResizeOptions} box. Mirrors
|
|
16
|
+
* `NativeNitroImage`'s `resizeMode`, so a view's `resizeMode` and the bitmap
|
|
17
|
+
* it displays can be derived from one value. With a `w` × `h` source and a
|
|
18
|
+
* `W` × `H` box, the produced bitmap is:
|
|
19
|
+
*
|
|
20
|
+
* - `cover`: scale by `max(W/w, H/h)`, center-crop → exactly `W` × `H`
|
|
21
|
+
* (CSS `object-fit: cover`).
|
|
22
|
+
* - `contain`: scale by `min(W/w, H/h)` → `round(w·s)` × `round(h·s)`, the
|
|
23
|
+
* largest size with the source's aspect ratio that fits the box. The
|
|
24
|
+
* bitmap is *not* padded to the box.
|
|
25
|
+
* - `stretch`: scale each axis independently → exactly `W` × `H`, aspect
|
|
26
|
+
* ratio ignored.
|
|
27
|
+
* - `center`: no scaling; center-crop to `min(w, W)` × `min(h, H)`. A source
|
|
28
|
+
* smaller than the box is left untouched.
|
|
29
|
+
*/
|
|
30
|
+
export type ResizeFit = 'cover' | 'contain' | 'stretch' | 'center';
|
|
31
|
+
/**
|
|
32
|
+
* Target bitmap size in pixels. By default the image is scaled to fill this
|
|
33
|
+
* size and center-cropped (like CSS `object-fit: cover`), upscaling if
|
|
34
|
+
* needed, so the result is exactly `width` × `height` pixels; {@linkcode fit}
|
|
35
|
+
* selects the other resize modes.
|
|
18
36
|
*/
|
|
19
37
|
export interface ResizeOptions {
|
|
20
38
|
width: number;
|
|
21
39
|
height: number;
|
|
40
|
+
/**
|
|
41
|
+
* How the source is fitted into `width` × `height` — see
|
|
42
|
+
* {@linkcode ResizeFit} for the size each mode produces.
|
|
43
|
+
* @default 'cover'
|
|
44
|
+
*/
|
|
45
|
+
fit?: ResizeFit;
|
|
46
|
+
/**
|
|
47
|
+
* `false` never enlarges the source: the scale is clamped to at most 1 for
|
|
48
|
+
* `cover`, `contain` and `stretch`, so a source smaller than the box keeps
|
|
49
|
+
* its own size (and, under `cover`, is only cropped to the box). No effect
|
|
50
|
+
* on `center`, which never scales.
|
|
51
|
+
* @default true
|
|
52
|
+
*/
|
|
53
|
+
allowUpscale?: boolean;
|
|
22
54
|
}
|
|
23
55
|
export type Options = {
|
|
24
56
|
/**
|
|
@@ -51,10 +83,11 @@ export type Options = {
|
|
|
51
83
|
*/
|
|
52
84
|
cornerRadius?: number | CornerRadii;
|
|
53
85
|
/**
|
|
54
|
-
* Resize the image
|
|
55
|
-
*
|
|
56
|
-
* `cornerRadius`
|
|
57
|
-
* full-resolution bitmaps you only
|
|
86
|
+
* Resize the image into this box in pixels — aspect-fill + center-crop by
|
|
87
|
+
* default, or another {@linkcode ResizeFit} — before `blur` and
|
|
88
|
+
* `cornerRadius` are applied. Besides making `cornerRadius` predictable,
|
|
89
|
+
* this avoids decoding and processing full-resolution bitmaps you only
|
|
90
|
+
* display small.
|
|
58
91
|
*
|
|
59
92
|
* @default undefined (keep the source size)
|
|
60
93
|
*/
|
|
@@ -85,10 +118,52 @@ export type ViewOptions = {
|
|
|
85
118
|
/**
|
|
86
119
|
* Target bitmap size in **pixels**, overriding the size measured from the
|
|
87
120
|
* 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.
|
|
121
|
+
* laid-out size × screen scale, which is what you want in a UI. Its own
|
|
122
|
+
* `fit`/`allowUpscale`, when set, win over the top-level ones below.
|
|
89
123
|
* @default undefined (measure the view)
|
|
90
124
|
*/
|
|
91
125
|
resize?: ResizeOptions;
|
|
126
|
+
/**
|
|
127
|
+
* How the source is fitted into the box the loader resizes to (the view's
|
|
128
|
+
* size, or {@linkcode resize}) — see {@linkcode ResizeFit}. Pass the view's
|
|
129
|
+
* `resizeMode` so the bitmap matches how the view displays it.
|
|
130
|
+
* @default 'cover'
|
|
131
|
+
*/
|
|
132
|
+
fit?: ResizeFit;
|
|
133
|
+
/**
|
|
134
|
+
* `false` never enlarges the source — see
|
|
135
|
+
* {@linkcode ResizeOptions.allowUpscale}.
|
|
136
|
+
* @default true
|
|
137
|
+
*/
|
|
138
|
+
allowUpscale?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Called when a view finishes displaying the image, with the size of the
|
|
141
|
+
* bitmap it displays in **pixels**.
|
|
142
|
+
*
|
|
143
|
+
* The bitmap itself deliberately stays native — passing the `Image` into JS
|
|
144
|
+
* would keep it alive there and defeat the point of the native path. Use
|
|
145
|
+
* `useImage`/`loadImage` when you need the `Image` object.
|
|
146
|
+
*
|
|
147
|
+
* This reports "the view is now showing this image", not a one-shot event:
|
|
148
|
+
* a loader is per URL + options, not per view, so every view using it
|
|
149
|
+
* reports, a recycled cell reports again when it re-attaches, and a single
|
|
150
|
+
* view can report more than once (it requests the image both when its
|
|
151
|
+
* `image` prop is set and when it becomes visible). Memory-cache hits, which
|
|
152
|
+
* resolve synchronously, report too. It does not fire for imperative loads
|
|
153
|
+
* through `ImageLoader.loadImage()` — those resolve through their promise.
|
|
154
|
+
*
|
|
155
|
+
* Setting it means there *is* per-image JS work; leave it unset and the
|
|
156
|
+
* native path stays free of JS round trips entirely.
|
|
157
|
+
* @default undefined (nothing crosses into JS)
|
|
158
|
+
*/
|
|
159
|
+
onLoad?: (width: number, height: number) => void;
|
|
160
|
+
/**
|
|
161
|
+
* Called when a view fails to load the image, with the underlying error's
|
|
162
|
+
* message. Cancelling a load (the view detaching before it finishes) is not
|
|
163
|
+
* a failure and does not call this.
|
|
164
|
+
* @default undefined (failures are silent)
|
|
165
|
+
*/
|
|
166
|
+
onError?: (message: string) => void;
|
|
92
167
|
};
|
|
93
168
|
export interface NitroImagePipeline extends HybridObject<{
|
|
94
169
|
ios: 'swift';
|
|
@@ -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,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACnE,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,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED
|
|
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,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACnE,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,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;GAeG;AAC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AC;IACA;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,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"}
|
|
@@ -40,8 +40,9 @@ export declare function useImage({ url, blur, cornerRadius, resize, cache, enabl
|
|
|
40
40
|
*/
|
|
41
41
|
cornerRadius?: number | CornerRadii;
|
|
42
42
|
/**
|
|
43
|
-
* Resize the bitmap
|
|
44
|
-
* center-crop
|
|
43
|
+
* Resize the bitmap into this box in pixels before blur/rounding —
|
|
44
|
+
* aspect-fill + center-crop by default, or another `fit` (see
|
|
45
|
+
* {@linkcode ResizeOptions}). Typically your display size in points
|
|
45
46
|
* multiplied by `PixelRatio.get()`. Inline object literals are fine.
|
|
46
47
|
*/
|
|
47
48
|
resize?: ResizeOptions;
|
|
@@ -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,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
|
|
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;;;;;OAKG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,MAAM,CA0FT"}
|
|
@@ -11,7 +11,9 @@ import type { ViewOptions } from './specs/nitro-image-toolkit.nitro';
|
|
|
11
11
|
*
|
|
12
12
|
* `blur`/`cornerRadius` are in **points** (unlike `useImage`, where they are
|
|
13
13
|
* bitmap pixels); the screen scale is applied natively. Inline object
|
|
14
|
-
* literals are fine — options are compared by value, not identity
|
|
14
|
+
* literals are fine — options are compared by value, not identity, and the
|
|
15
|
+
* `onLoad`/`onError` callbacks are read through a ref, so inline arrows don't
|
|
16
|
+
* recreate the loader either.
|
|
15
17
|
*/
|
|
16
18
|
export declare function usePipelineImageLoader(source: ImageSource, options?: ViewOptions): ImageLoader;
|
|
17
19
|
//# sourceMappingURL=usePipelineImageLoader.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAkC3C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,WAAW,GACpB,WAAW,CAsIb"}
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
17
|
|
|
18
18
|
#include "JHybridNitroImagePipelineSpec.hpp"
|
|
19
|
+
#include "JFunc_void_double_double.hpp"
|
|
20
|
+
#include "JFunc_void_std__string.hpp"
|
|
19
21
|
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
20
22
|
|
|
21
23
|
namespace margelo::nitro::nitroimagepipeline {
|
|
@@ -41,6 +43,8 @@ void registerAllNatives() {
|
|
|
41
43
|
|
|
42
44
|
// Register native JNI methods
|
|
43
45
|
margelo::nitro::nitroimagepipeline::JHybridNitroImagePipelineSpec::CxxPart::registerNatives();
|
|
46
|
+
margelo::nitro::nitroimagepipeline::JFunc_void_double_double_cxx::registerNatives();
|
|
47
|
+
margelo::nitro::nitroimagepipeline::JFunc_void_std__string_cxx::registerNatives();
|
|
44
48
|
|
|
45
49
|
// Register Nitro Hybrid Objects
|
|
46
50
|
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void_double_double.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 <functional>
|
|
12
|
+
|
|
13
|
+
#include <functional>
|
|
14
|
+
#include <NitroModules/JNICallable.hpp>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::nitroimagepipeline {
|
|
17
|
+
|
|
18
|
+
using namespace facebook;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents the Java/Kotlin callback `(width: Double, height: Double) -> Unit`.
|
|
22
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
23
|
+
*/
|
|
24
|
+
struct JFunc_void_double_double: public jni::JavaClass<JFunc_void_double_double> {
|
|
25
|
+
public:
|
|
26
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroimagepipeline/Func_void_double_double;";
|
|
27
|
+
|
|
28
|
+
public:
|
|
29
|
+
/**
|
|
30
|
+
* Invokes the function this `JFunc_void_double_double` instance holds through JNI.
|
|
31
|
+
*/
|
|
32
|
+
void invoke(double width, double height) const {
|
|
33
|
+
static const auto method = javaClassStatic()->getMethod<void(double /* width */, double /* height */)>("invoke");
|
|
34
|
+
method(self(), width, height);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* An implementation of Func_void_double_double that is backed by a C++ implementation (using `std::function<...>`)
|
|
40
|
+
*/
|
|
41
|
+
class JFunc_void_double_double_cxx final: public jni::HybridClass<JFunc_void_double_double_cxx, JFunc_void_double_double> {
|
|
42
|
+
public:
|
|
43
|
+
static jni::local_ref<JFunc_void_double_double::javaobject> fromCpp(const std::function<void(double /* width */, double /* height */)>& func) {
|
|
44
|
+
return JFunc_void_double_double_cxx::newObjectCxxArgs(func);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
/**
|
|
49
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_double_double_cxx` instance holds.
|
|
50
|
+
*/
|
|
51
|
+
void invoke_cxx(double width, double height) {
|
|
52
|
+
_func(width, height);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
[[nodiscard]]
|
|
57
|
+
inline const std::function<void(double /* width */, double /* height */)>& getFunction() const {
|
|
58
|
+
return _func;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public:
|
|
62
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroimagepipeline/Func_void_double_double_cxx;";
|
|
63
|
+
static void registerNatives() {
|
|
64
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_double_double_cxx::invoke_cxx)});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private:
|
|
68
|
+
explicit JFunc_void_double_double_cxx(const std::function<void(double /* width */, double /* height */)>& func): _func(func) { }
|
|
69
|
+
|
|
70
|
+
private:
|
|
71
|
+
friend HybridBase;
|
|
72
|
+
std::function<void(double /* width */, double /* height */)> _func;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace margelo::nitro::nitroimagepipeline
|