react-native-nitro-image-pipeline 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/HybridNitroImagePipeline.kt +15 -2
- package/ios/HybridNitroImagePipeline.swift +12 -2
- package/ios/RoundedCornersProcessor.swift +118 -0
- package/lib/commonjs/index.js +18 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +18 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +8 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/nitro-image-toolkit.nitro.d.ts +18 -1
- package/lib/typescript/src/specs/nitro-image-toolkit.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroImagePipeline+autolinking.cmake +1 -0
- package/nitrogen/generated/android/c++/JCornerRadii.hpp +69 -0
- package/nitrogen/generated/android/c++/JHybridNitroImagePipelineSpec.cpp +6 -0
- package/nitrogen/generated/android/c++/JOptions.hpp +9 -5
- package/nitrogen/generated/android/c++/JVariant_Double_CornerRadii.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_Double_CornerRadii.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/CornerRadii.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/Options.kt +2 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/Variant_Double_CornerRadii.kt +62 -0
- package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Bridge.hpp +48 -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/CornerRadii.swift +96 -0
- package/nitrogen/generated/ios/swift/Options.swift +27 -8
- package/nitrogen/generated/ios/swift/Variant_Double_CornerRadii.swift +30 -0
- package/nitrogen/generated/shared/c++/CornerRadii.hpp +95 -0
- package/nitrogen/generated/shared/c++/Options.hpp +9 -5
- package/package.json +1 -1
- package/src/index.ts +33 -4
- package/src/specs/nitro-image-toolkit.nitro.ts +20 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ A high-performance image loading, caching, and processing library for React Nati
|
|
|
10
10
|
|
|
11
11
|
- Load remote images with built-in memory and disk caching
|
|
12
12
|
- Prefetch single or multiple images in the background
|
|
13
|
-
- Apply Gaussian blur and rounded corners at load time
|
|
13
|
+
- Apply Gaussian blur and rounded corners (uniform or per-corner) at load time
|
|
14
14
|
- Apply Gaussian blur to already-loaded images
|
|
15
15
|
- Clear the image cache on demand
|
|
16
16
|
- `useImage` hook for declarative image loading in components
|
|
@@ -72,6 +72,12 @@ const image = await NitroImagePipeline.loadImage('https://example.com/photo.jpg'
|
|
|
72
72
|
cache: 'disk',
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
// Per-corner radii — e.g. a "ticket" shape with larger bottom corners.
|
|
76
|
+
// The rounding is baked into the bitmap, so no view-layer masking is needed.
|
|
77
|
+
const ticket = await NitroImagePipeline.loadImage('https://example.com/photo.jpg', {
|
|
78
|
+
cornerRadius: { topLeft: 24, topRight: 24, bottomLeft: 48, bottomRight: 48 },
|
|
79
|
+
});
|
|
80
|
+
|
|
75
81
|
// Prefetch a single image
|
|
76
82
|
await NitroImagePipeline.preLoadImage('https://example.com/photo.jpg');
|
|
77
83
|
|
|
@@ -97,7 +103,7 @@ Loads an image from a URL and returns a `Promise<Image>`.
|
|
|
97
103
|
| Option | Type | Default | Description |
|
|
98
104
|
|---|---|---|---|
|
|
99
105
|
| `blur` | `number` | `0` | Gaussian blur strength applied at load time — see [Blur units](#blur-units) |
|
|
100
|
-
| `cornerRadius` | `number` | `0` | Corner radius in points |
|
|
106
|
+
| `cornerRadius` | `number \| CornerRadii` | `0` | Corner radius in points — a single number for all four corners, or `{ topLeft?, topRight?, bottomLeft?, bottomRight? }` for independent per-corner radii (omitted corners stay square) |
|
|
101
107
|
| `cache` | `'memory' \| 'disk' \| 'none'` | platform default | Caching strategy |
|
|
102
108
|
|
|
103
109
|
### `preLoadImage(url)`
|
package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/HybridNitroImagePipeline.kt
CHANGED
|
@@ -40,10 +40,23 @@ class HybridNitroImagePipeline : HybridNitroImagePipelineSpec() {
|
|
|
40
40
|
|
|
41
41
|
override fun loadImage(url: String, options: Options?): Promise<HybridImageSpec> = Promise.async {
|
|
42
42
|
val blur = options?.blur?.toFloat() ?: 0f
|
|
43
|
-
val cornerRadius = options?.cornerRadius?.toFloat() ?: 0f
|
|
44
43
|
val transformations = buildList {
|
|
45
44
|
if (blur > 0f) add(BlurTransformation(context, blur))
|
|
46
|
-
|
|
45
|
+
options?.cornerRadius?.match(
|
|
46
|
+
first = { radius ->
|
|
47
|
+
if (radius > 0.0) add(RoundedCornersTransformation(radius.toFloat()))
|
|
48
|
+
},
|
|
49
|
+
second = { radii ->
|
|
50
|
+
// RoundedCornersTransformation rejects negative radii; treat them as square.
|
|
51
|
+
val topLeft = (radii.topLeft?.toFloat() ?: 0f).coerceAtLeast(0f)
|
|
52
|
+
val topRight = (radii.topRight?.toFloat() ?: 0f).coerceAtLeast(0f)
|
|
53
|
+
val bottomLeft = (radii.bottomLeft?.toFloat() ?: 0f).coerceAtLeast(0f)
|
|
54
|
+
val bottomRight = (radii.bottomRight?.toFloat() ?: 0f).coerceAtLeast(0f)
|
|
55
|
+
if (topLeft > 0f || topRight > 0f || bottomLeft > 0f || bottomRight > 0f) {
|
|
56
|
+
add(RoundedCornersTransformation(topLeft, topRight, bottomLeft, bottomRight))
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
)
|
|
47
60
|
}
|
|
48
61
|
val request =
|
|
49
62
|
ImageRequest.Builder(context)
|
|
@@ -120,8 +120,18 @@ class HybridNitroImagePipeline: HybridNitroImagePipelineSpec {
|
|
|
120
120
|
if let blur = options?.blur, blur > 0 {
|
|
121
121
|
processors.append(GaussianBlurProcessor(sigma: blur))
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
switch options?.cornerRadius {
|
|
124
|
+
case .first(let radius):
|
|
125
|
+
if radius > 0 {
|
|
126
|
+
processors.append(.roundedCorners(radius: radius))
|
|
127
|
+
}
|
|
128
|
+
case .second(let radii):
|
|
129
|
+
let roundedCorners = RoundedCornersProcessor(radii: radii)
|
|
130
|
+
if roundedCorners.hasRounding {
|
|
131
|
+
processors.append(roundedCorners)
|
|
132
|
+
}
|
|
133
|
+
case nil:
|
|
134
|
+
break
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
let imgRequest = ImageRequest(
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RoundedCornersProcessor.swift
|
|
3
|
+
// NitroImagePipeline
|
|
4
|
+
//
|
|
5
|
+
// Bakes independent per-corner radii into the bitmap. Nuke's built-in
|
|
6
|
+
// ImageProcessors.RoundedCorners only supports one uniform radius, so the
|
|
7
|
+
// asymmetric case clips through a hand-built CGPath instead.
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
import CoreGraphics
|
|
11
|
+
import Foundation
|
|
12
|
+
import Nuke
|
|
13
|
+
import UIKit
|
|
14
|
+
|
|
15
|
+
/// Nuke processor that rounds each corner with its own radius (in points,
|
|
16
|
+
/// like `ImageProcessors.RoundedCorners` with `unit: .points`).
|
|
17
|
+
struct RoundedCornersProcessor: ImageProcessing {
|
|
18
|
+
let topLeft: CGFloat
|
|
19
|
+
let topRight: CGFloat
|
|
20
|
+
let bottomLeft: CGFloat
|
|
21
|
+
let bottomRight: CGFloat
|
|
22
|
+
|
|
23
|
+
init(radii: CornerRadii) {
|
|
24
|
+
// Negative radii would make CGPath arcs undefined; treat them as square.
|
|
25
|
+
topLeft = CGFloat(max(radii.topLeft ?? 0, 0))
|
|
26
|
+
topRight = CGFloat(max(radii.topRight ?? 0, 0))
|
|
27
|
+
bottomLeft = CGFloat(max(radii.bottomLeft ?? 0, 0))
|
|
28
|
+
bottomRight = CGFloat(max(radii.bottomRight ?? 0, 0))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var hasRounding: Bool {
|
|
32
|
+
topLeft > 0 || topRight > 0 || bottomLeft > 0 || bottomRight > 0
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var identifier: String {
|
|
36
|
+
"com.nitroimagepipeline.roundedCorners?tl=\(topLeft),tr=\(topRight),bl=\(bottomLeft),br=\(bottomRight)"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var hashableIdentifier: AnyHashable { identifier }
|
|
40
|
+
|
|
41
|
+
func process(_ image: PlatformImage) -> PlatformImage? {
|
|
42
|
+
let size = image.size
|
|
43
|
+
guard size.width > 0, size.height > 0 else { return image }
|
|
44
|
+
|
|
45
|
+
let format = UIGraphicsImageRendererFormat()
|
|
46
|
+
format.scale = image.scale
|
|
47
|
+
format.opaque = false
|
|
48
|
+
|
|
49
|
+
let rect = CGRect(origin: .zero, size: size)
|
|
50
|
+
return UIGraphicsImageRenderer(size: size, format: format).image { context in
|
|
51
|
+
context.cgContext.addPath(Self.clipPath(
|
|
52
|
+
in: rect,
|
|
53
|
+
topLeft: topLeft,
|
|
54
|
+
topRight: topRight,
|
|
55
|
+
bottomLeft: bottomLeft,
|
|
56
|
+
bottomRight: bottomRight
|
|
57
|
+
))
|
|
58
|
+
context.cgContext.clip()
|
|
59
|
+
image.draw(in: rect)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// A rounded-rect outline with independent corner radii, clamped the way
|
|
64
|
+
/// CSS `border-radius` clamps: if two radii on one edge overlap, all four
|
|
65
|
+
/// scale down proportionally until they fit.
|
|
66
|
+
static func clipPath(
|
|
67
|
+
in rect: CGRect,
|
|
68
|
+
topLeft: CGFloat,
|
|
69
|
+
topRight: CGFloat,
|
|
70
|
+
bottomLeft: CGFloat,
|
|
71
|
+
bottomRight: CGFloat
|
|
72
|
+
) -> CGPath {
|
|
73
|
+
var scale: CGFloat = 1
|
|
74
|
+
for (edge, pair) in [
|
|
75
|
+
(rect.width, topLeft + topRight),
|
|
76
|
+
(rect.width, bottomLeft + bottomRight),
|
|
77
|
+
(rect.height, topLeft + bottomLeft),
|
|
78
|
+
(rect.height, topRight + bottomRight),
|
|
79
|
+
] where pair > edge {
|
|
80
|
+
scale = min(scale, edge / pair)
|
|
81
|
+
}
|
|
82
|
+
let topLeft = topLeft * scale
|
|
83
|
+
let topRight = topRight * scale
|
|
84
|
+
let bottomLeft = bottomLeft * scale
|
|
85
|
+
let bottomRight = bottomRight * scale
|
|
86
|
+
|
|
87
|
+
// addArc(tangent1End:tangent2End:radius: 0) degenerates to a line
|
|
88
|
+
// through the corner, so square corners need no special-casing.
|
|
89
|
+
let path = CGMutablePath()
|
|
90
|
+
path.move(to: CGPoint(x: rect.minX + topLeft, y: rect.minY))
|
|
91
|
+
path.addLine(to: CGPoint(x: rect.maxX - topRight, y: rect.minY))
|
|
92
|
+
path.addArc(
|
|
93
|
+
tangent1End: CGPoint(x: rect.maxX, y: rect.minY),
|
|
94
|
+
tangent2End: CGPoint(x: rect.maxX, y: rect.minY + topRight),
|
|
95
|
+
radius: topRight
|
|
96
|
+
)
|
|
97
|
+
path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY - bottomRight))
|
|
98
|
+
path.addArc(
|
|
99
|
+
tangent1End: CGPoint(x: rect.maxX, y: rect.maxY),
|
|
100
|
+
tangent2End: CGPoint(x: rect.maxX - bottomRight, y: rect.maxY),
|
|
101
|
+
radius: bottomRight
|
|
102
|
+
)
|
|
103
|
+
path.addLine(to: CGPoint(x: rect.minX + bottomLeft, y: rect.maxY))
|
|
104
|
+
path.addArc(
|
|
105
|
+
tangent1End: CGPoint(x: rect.minX, y: rect.maxY),
|
|
106
|
+
tangent2End: CGPoint(x: rect.minX, y: rect.maxY - bottomLeft),
|
|
107
|
+
radius: bottomLeft
|
|
108
|
+
)
|
|
109
|
+
path.addLine(to: CGPoint(x: rect.minX, y: rect.minY + topLeft))
|
|
110
|
+
path.addArc(
|
|
111
|
+
tangent1End: CGPoint(x: rect.minX, y: rect.minY),
|
|
112
|
+
tangent2End: CGPoint(x: rect.minX + topLeft, y: rect.minY),
|
|
113
|
+
radius: topLeft
|
|
114
|
+
)
|
|
115
|
+
path.closeSubpath()
|
|
116
|
+
return path
|
|
117
|
+
}
|
|
118
|
+
}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -27,6 +27,17 @@ function useImage({
|
|
|
27
27
|
error: undefined
|
|
28
28
|
});
|
|
29
29
|
const loadedUrlRef = (0, _react.useRef)(url);
|
|
30
|
+
|
|
31
|
+
// Split the option into primitives so an inline `{ topLeft: 24, ... }`
|
|
32
|
+
// literal (new identity every render) doesn't re-trigger the effect.
|
|
33
|
+
const isUniformRadius = typeof cornerRadius === 'number';
|
|
34
|
+
const uniformRadius = isUniformRadius ? cornerRadius : 0;
|
|
35
|
+
const {
|
|
36
|
+
topLeft = 0,
|
|
37
|
+
topRight = 0,
|
|
38
|
+
bottomLeft = 0,
|
|
39
|
+
bottomRight = 0
|
|
40
|
+
} = isUniformRadius ? {} : cornerRadius;
|
|
30
41
|
(0, _react.useEffect)(() => {
|
|
31
42
|
let cancelled = false;
|
|
32
43
|
// Only reset to the loading state when the URL changes; for same-URL
|
|
@@ -43,7 +54,12 @@ function useImage({
|
|
|
43
54
|
try {
|
|
44
55
|
const result = await NitroImagePipeline.loadImage(url, {
|
|
45
56
|
blur,
|
|
46
|
-
cornerRadius
|
|
57
|
+
cornerRadius: isUniformRadius ? uniformRadius : {
|
|
58
|
+
topLeft,
|
|
59
|
+
topRight,
|
|
60
|
+
bottomLeft,
|
|
61
|
+
bottomRight
|
|
62
|
+
},
|
|
47
63
|
cache
|
|
48
64
|
});
|
|
49
65
|
if (!cancelled) {
|
|
@@ -65,7 +81,7 @@ function useImage({
|
|
|
65
81
|
return () => {
|
|
66
82
|
cancelled = true;
|
|
67
83
|
};
|
|
68
|
-
}, [url, blur,
|
|
84
|
+
}, [url, blur, isUniformRadius, uniformRadius, topLeft, topRight, bottomLeft, bottomRight, cache]);
|
|
69
85
|
return image;
|
|
70
86
|
}
|
|
71
87
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNativeNitroModules","NitroImagePipeline","exports","NitroModules","createHybridObject","useImage","url","blur","cornerRadius","cache","image","setImage","useState","undefined","error","loadedUrlRef","useRef","useEffect","cancelled","current","result","loadImage","e","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,wBAAA,GAAAD,OAAA;
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNativeNitroModules","NitroImagePipeline","exports","NitroModules","createHybridObject","useImage","url","blur","cornerRadius","cache","image","setImage","useState","undefined","error","loadedUrlRef","useRef","isUniformRadius","uniformRadius","topLeft","topRight","bottomLeft","bottomRight","useEffect","cancelled","current","result","loadImage","e","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,wBAAA,GAAAD,OAAA;AAWO,MAAME,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAC7BE,qCAAY,CAACC,kBAAkB,CAAyB,oBAAoB,CAAC;AAmB/E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,QAAQA,CAAC;EACvBC,GAAG;EACHC,IAAI,GAAG,CAAC;EACRC,YAAY,GAAG,CAAC;EAChBC;AAgBF,CAAC,EAAU;EACT,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAS;IACzCF,KAAK,EAAEG,SAAS;IAChBC,KAAK,EAAED;EACT,CAAC,CAAC;EACF,MAAME,YAAY,GAAG,IAAAC,aAAM,EAACV,GAAG,CAAC;;EAEhC;EACA;EACA,MAAMW,eAAe,GAAG,OAAOT,YAAY,KAAK,QAAQ;EACxD,MAAMU,aAAa,GAAGD,eAAe,GAAGT,YAAY,GAAG,CAAC;EACxD,MAAM;IACJW,OAAO,GAAG,CAAC;IACXC,QAAQ,GAAG,CAAC;IACZC,UAAU,GAAG,CAAC;IACdC,WAAW,GAAG;EAChB,CAAC,GAAGL,eAAe,GAAG,CAAC,CAAC,GAAGT,YAAY;EAEvC,IAAAe,gBAAS,EAAC,MAAM;IACd,IAAIC,SAAS,GAAG,KAAK;IACrB;IACA;IACA;IACA,IAAIT,YAAY,CAACU,OAAO,KAAKnB,GAAG,EAAE;MAChCS,YAAY,CAACU,OAAO,GAAGnB,GAAG;MAC1BK,QAAQ,CAAC;QAAED,KAAK,EAAEG,SAAS;QAAEC,KAAK,EAAED;MAAU,CAAC,CAAC;IAClD;IAEA,CAAC,YAAY;MACX,IAAI;QACF,MAAMa,MAAM,GAAG,MAAMzB,kBAAkB,CAAC0B,SAAS,CAACrB,GAAG,EAAE;UACrDC,IAAI;UACJC,YAAY,EAAES,eAAe,GACzBC,aAAa,GACb;YAAEC,OAAO;YAAEC,QAAQ;YAAEC,UAAU;YAAEC;UAAY,CAAC;UAClDb;QACF,CAAC,CAAC;QAEF,IAAI,CAACe,SAAS,EAAE;UACdb,QAAQ,CAAC;YAAED,KAAK,EAAEgB,MAAM;YAAEZ,KAAK,EAAED;UAAU,CAAC,CAAC;QAC/C;MACF,CAAC,CAAC,OAAOe,CAAC,EAAE;QACV,MAAMd,KAAK,GAAGc,CAAC,YAAYC,KAAK,GAAGD,CAAC,GAAG,IAAIC,KAAK,CAAC,GAAGD,CAAC,EAAE,CAAC;QACxD,IAAI,CAACJ,SAAS,EAAE;UACdb,QAAQ,CAAC;YAAED,KAAK,EAAEG,SAAS;YAAEC,KAAK,EAAEA;UAAM,CAAC,CAAC;QAC9C;MACF;IACF,CAAC,EAAE,CAAC;IAEJ,OAAO,MAAM;MACXU,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CACDlB,GAAG,EACHC,IAAI,EACJU,eAAe,EACfC,aAAa,EACbC,OAAO,EACPC,QAAQ,EACRC,UAAU,EACVC,WAAW,EACXb,KAAK,CACN,CAAC;EAEF,OAAOC,KAAK;AACd","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -22,6 +22,17 @@ export function useImage({
|
|
|
22
22
|
error: undefined
|
|
23
23
|
});
|
|
24
24
|
const loadedUrlRef = useRef(url);
|
|
25
|
+
|
|
26
|
+
// Split the option into primitives so an inline `{ topLeft: 24, ... }`
|
|
27
|
+
// literal (new identity every render) doesn't re-trigger the effect.
|
|
28
|
+
const isUniformRadius = typeof cornerRadius === 'number';
|
|
29
|
+
const uniformRadius = isUniformRadius ? cornerRadius : 0;
|
|
30
|
+
const {
|
|
31
|
+
topLeft = 0,
|
|
32
|
+
topRight = 0,
|
|
33
|
+
bottomLeft = 0,
|
|
34
|
+
bottomRight = 0
|
|
35
|
+
} = isUniformRadius ? {} : cornerRadius;
|
|
25
36
|
useEffect(() => {
|
|
26
37
|
let cancelled = false;
|
|
27
38
|
// Only reset to the loading state when the URL changes; for same-URL
|
|
@@ -38,7 +49,12 @@ export function useImage({
|
|
|
38
49
|
try {
|
|
39
50
|
const result = await NitroImagePipeline.loadImage(url, {
|
|
40
51
|
blur,
|
|
41
|
-
cornerRadius
|
|
52
|
+
cornerRadius: isUniformRadius ? uniformRadius : {
|
|
53
|
+
topLeft,
|
|
54
|
+
topRight,
|
|
55
|
+
bottomLeft,
|
|
56
|
+
bottomRight
|
|
57
|
+
},
|
|
42
58
|
cache
|
|
43
59
|
});
|
|
44
60
|
if (!cancelled) {
|
|
@@ -60,7 +76,7 @@ export function useImage({
|
|
|
60
76
|
return () => {
|
|
61
77
|
cancelled = true;
|
|
62
78
|
};
|
|
63
|
-
}, [url, blur,
|
|
79
|
+
}, [url, blur, isUniformRadius, uniformRadius, topLeft, topRight, bottomLeft, bottomRight, cache]);
|
|
64
80
|
return image;
|
|
65
81
|
}
|
|
66
82
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","useState","NitroModules","NitroImagePipeline","createHybridObject","useImage","url","blur","cornerRadius","cache","image","setImage","undefined","error","loadedUrlRef","cancelled","current","result","loadImage","e","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEnD,SAASC,YAAY,QAAQ,4BAA4B;
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useState","NitroModules","NitroImagePipeline","createHybridObject","useImage","url","blur","cornerRadius","cache","image","setImage","undefined","error","loadedUrlRef","isUniformRadius","uniformRadius","topLeft","topRight","bottomLeft","bottomRight","cancelled","current","result","loadImage","e","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEnD,SAASC,YAAY,QAAQ,4BAA4B;AAWzD,OAAO,MAAMC,kBAAkB,GAC7BD,YAAY,CAACE,kBAAkB,CAAyB,oBAAoB,CAAC;AAmB/E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAC;EACvBC,GAAG;EACHC,IAAI,GAAG,CAAC;EACRC,YAAY,GAAG,CAAC;EAChBC;AAgBF,CAAC,EAAU;EACT,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGV,QAAQ,CAAS;IACzCS,KAAK,EAAEE,SAAS;IAChBC,KAAK,EAAED;EACT,CAAC,CAAC;EACF,MAAME,YAAY,GAAGd,MAAM,CAACM,GAAG,CAAC;;EAEhC;EACA;EACA,MAAMS,eAAe,GAAG,OAAOP,YAAY,KAAK,QAAQ;EACxD,MAAMQ,aAAa,GAAGD,eAAe,GAAGP,YAAY,GAAG,CAAC;EACxD,MAAM;IACJS,OAAO,GAAG,CAAC;IACXC,QAAQ,GAAG,CAAC;IACZC,UAAU,GAAG,CAAC;IACdC,WAAW,GAAG;EAChB,CAAC,GAAGL,eAAe,GAAG,CAAC,CAAC,GAAGP,YAAY;EAEvCT,SAAS,CAAC,MAAM;IACd,IAAIsB,SAAS,GAAG,KAAK;IACrB;IACA;IACA;IACA,IAAIP,YAAY,CAACQ,OAAO,KAAKhB,GAAG,EAAE;MAChCQ,YAAY,CAACQ,OAAO,GAAGhB,GAAG;MAC1BK,QAAQ,CAAC;QAAED,KAAK,EAAEE,SAAS;QAAEC,KAAK,EAAED;MAAU,CAAC,CAAC;IAClD;IAEA,CAAC,YAAY;MACX,IAAI;QACF,MAAMW,MAAM,GAAG,MAAMpB,kBAAkB,CAACqB,SAAS,CAAClB,GAAG,EAAE;UACrDC,IAAI;UACJC,YAAY,EAAEO,eAAe,GACzBC,aAAa,GACb;YAAEC,OAAO;YAAEC,QAAQ;YAAEC,UAAU;YAAEC;UAAY,CAAC;UAClDX;QACF,CAAC,CAAC;QAEF,IAAI,CAACY,SAAS,EAAE;UACdV,QAAQ,CAAC;YAAED,KAAK,EAAEa,MAAM;YAAEV,KAAK,EAAED;UAAU,CAAC,CAAC;QAC/C;MACF,CAAC,CAAC,OAAOa,CAAC,EAAE;QACV,MAAMZ,KAAK,GAAGY,CAAC,YAAYC,KAAK,GAAGD,CAAC,GAAG,IAAIC,KAAK,CAAC,GAAGD,CAAC,EAAE,CAAC;QACxD,IAAI,CAACJ,SAAS,EAAE;UACdV,QAAQ,CAAC;YAAED,KAAK,EAAEE,SAAS;YAAEC,KAAK,EAAEA;UAAM,CAAC,CAAC;QAC9C;MACF;IACF,CAAC,EAAE,CAAC;IAEJ,OAAO,MAAM;MACXQ,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CACDf,GAAG,EACHC,IAAI,EACJQ,eAAe,EACfC,aAAa,EACbC,OAAO,EACPC,QAAQ,EACRC,UAAU,EACVC,WAAW,EACXX,KAAK,CACN,CAAC;EAEF,OAAOC,KAAK;AACd","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Image } from 'react-native-nitro-image';
|
|
2
|
-
import type { CacheOption, NitroImagePipeline as NitroImagePipelineSpec, Options } from './specs/nitro-image-toolkit.nitro';
|
|
3
|
-
export type { CacheOption, Options };
|
|
2
|
+
import type { CacheOption, CornerRadii, NitroImagePipeline as NitroImagePipelineSpec, Options } from './specs/nitro-image-toolkit.nitro';
|
|
3
|
+
export type { CacheOption, CornerRadii, Options };
|
|
4
4
|
export declare const NitroImagePipeline: NitroImagePipelineSpec;
|
|
5
5
|
type Result = {
|
|
6
6
|
image: undefined;
|
|
@@ -28,7 +28,12 @@ export declare function useImage({ url, blur, cornerRadius, cache, }: {
|
|
|
28
28
|
* React Native's `blurRadius`.
|
|
29
29
|
*/
|
|
30
30
|
blur?: number;
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Corner radius in points, baked into the loaded bitmap. Pass a single
|
|
33
|
+
* number for uniform rounding, or per-corner radii (inline object literals
|
|
34
|
+
* are fine — the hook compares the radii by value, not identity).
|
|
35
|
+
*/
|
|
36
|
+
cornerRadius?: number | CornerRadii;
|
|
32
37
|
cache?: CacheOption;
|
|
33
38
|
}): Result;
|
|
34
39
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,IAAI,sBAAsB,EAC5C,OAAO,EACR,MAAM,mCAAmC,CAAC;AAE3C,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,kBAAkB,IAAI,sBAAsB,EAC5C,OAAO,EACR,MAAM,mCAAmC,CAAC;AAE3C,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;AAElD,eAAO,MAAM,kBAAkB,wBACgD,CAAC;AAEhF,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,KAAK,GACN,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACpC,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,MAAM,CAiET"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { Image } from 'react-native-nitro-image';
|
|
2
2
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
3
3
|
export type CacheOption = 'memory' | 'disk' | 'none';
|
|
4
|
+
/**
|
|
5
|
+
* Independent corner radii in points. Omitted corners stay square.
|
|
6
|
+
*/
|
|
7
|
+
export interface CornerRadii {
|
|
8
|
+
topLeft?: number;
|
|
9
|
+
topRight?: number;
|
|
10
|
+
bottomLeft?: number;
|
|
11
|
+
bottomRight?: number;
|
|
12
|
+
}
|
|
4
13
|
export type Options = {
|
|
5
14
|
/**
|
|
6
15
|
* Gaussian blur strength, given as the standard deviation (sigma) of the
|
|
@@ -13,7 +22,15 @@ export type Options = {
|
|
|
13
22
|
*/
|
|
14
23
|
blur?: number;
|
|
15
24
|
cache?: CacheOption;
|
|
16
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Corner radius in points, baked into the loaded bitmap. Pass a single
|
|
27
|
+
* number to round all four corners uniformly, or a {@linkcode CornerRadii}
|
|
28
|
+
* object to round each corner independently (e.g. a "ticket" shape with
|
|
29
|
+
* larger bottom corners).
|
|
30
|
+
*
|
|
31
|
+
* @default 0 (square corners)
|
|
32
|
+
*/
|
|
33
|
+
cornerRadius?: number | CornerRadii;
|
|
17
34
|
};
|
|
18
35
|
export interface NitroImagePipeline extends HybridObject<{
|
|
19
36
|
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,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;
|
|
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;;GAEG;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,MAAM,MAAM,OAAO,GAAG;IACpB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,kBAAmB,SAAQ,YAAY,CAAC;IACvD,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;IACA,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC1D,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,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B"}
|
|
@@ -36,6 +36,7 @@ target_sources(
|
|
|
36
36
|
../nitrogen/generated/shared/c++/HybridNitroImagePipelineSpec.cpp
|
|
37
37
|
# Android-specific Nitrogen C++ sources
|
|
38
38
|
../nitrogen/generated/android/c++/JHybridNitroImagePipelineSpec.cpp
|
|
39
|
+
../nitrogen/generated/android/c++/JVariant_Double_CornerRadii.cpp
|
|
39
40
|
)
|
|
40
41
|
|
|
41
42
|
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JCornerRadii.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 "CornerRadii.hpp"
|
|
12
|
+
|
|
13
|
+
#include <optional>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::nitroimagepipeline {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "CornerRadii" and the Kotlin data class "CornerRadii".
|
|
21
|
+
*/
|
|
22
|
+
struct JCornerRadii final: public jni::JavaClass<JCornerRadii> {
|
|
23
|
+
public:
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroimagepipeline/CornerRadii;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct CornerRadii by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
CornerRadii toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldTopLeft = clazz->getField<jni::JDouble>("topLeft");
|
|
35
|
+
jni::local_ref<jni::JDouble> topLeft = this->getFieldValue(fieldTopLeft);
|
|
36
|
+
static const auto fieldTopRight = clazz->getField<jni::JDouble>("topRight");
|
|
37
|
+
jni::local_ref<jni::JDouble> topRight = this->getFieldValue(fieldTopRight);
|
|
38
|
+
static const auto fieldBottomLeft = clazz->getField<jni::JDouble>("bottomLeft");
|
|
39
|
+
jni::local_ref<jni::JDouble> bottomLeft = this->getFieldValue(fieldBottomLeft);
|
|
40
|
+
static const auto fieldBottomRight = clazz->getField<jni::JDouble>("bottomRight");
|
|
41
|
+
jni::local_ref<jni::JDouble> bottomRight = this->getFieldValue(fieldBottomRight);
|
|
42
|
+
return CornerRadii(
|
|
43
|
+
topLeft != nullptr ? std::make_optional(topLeft->value()) : std::nullopt,
|
|
44
|
+
topRight != nullptr ? std::make_optional(topRight->value()) : std::nullopt,
|
|
45
|
+
bottomLeft != nullptr ? std::make_optional(bottomLeft->value()) : std::nullopt,
|
|
46
|
+
bottomRight != nullptr ? std::make_optional(bottomRight->value()) : std::nullopt
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
/**
|
|
52
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
53
|
+
*/
|
|
54
|
+
[[maybe_unused]]
|
|
55
|
+
static jni::local_ref<JCornerRadii::javaobject> fromCpp(const CornerRadii& value) {
|
|
56
|
+
using JSignature = JCornerRadii(jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
|
|
57
|
+
static const auto clazz = javaClassStatic();
|
|
58
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
59
|
+
return create(
|
|
60
|
+
clazz,
|
|
61
|
+
value.topLeft.has_value() ? jni::JDouble::valueOf(value.topLeft.value()) : nullptr,
|
|
62
|
+
value.topRight.has_value() ? jni::JDouble::valueOf(value.topRight.value()) : nullptr,
|
|
63
|
+
value.bottomLeft.has_value() ? jni::JDouble::valueOf(value.bottomLeft.value()) : nullptr,
|
|
64
|
+
value.bottomRight.has_value() ? jni::JDouble::valueOf(value.bottomRight.value()) : nullptr
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace margelo::nitro::nitroimagepipeline
|
|
@@ -13,6 +13,8 @@ namespace margelo::nitro::image { class HybridImageSpec; }
|
|
|
13
13
|
namespace margelo::nitro::nitroimagepipeline { struct Options; }
|
|
14
14
|
// Forward declaration of `CacheOption` to properly resolve imports.
|
|
15
15
|
namespace margelo::nitro::nitroimagepipeline { enum class CacheOption; }
|
|
16
|
+
// Forward declaration of `CornerRadii` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitroimagepipeline { struct CornerRadii; }
|
|
16
18
|
|
|
17
19
|
#include <memory>
|
|
18
20
|
#include <NitroImage/HybridImageSpec.hpp>
|
|
@@ -26,6 +28,10 @@ namespace margelo::nitro::nitroimagepipeline { enum class CacheOption; }
|
|
|
26
28
|
#include "JOptions.hpp"
|
|
27
29
|
#include "CacheOption.hpp"
|
|
28
30
|
#include "JCacheOption.hpp"
|
|
31
|
+
#include "CornerRadii.hpp"
|
|
32
|
+
#include <variant>
|
|
33
|
+
#include "JVariant_Double_CornerRadii.hpp"
|
|
34
|
+
#include "JCornerRadii.hpp"
|
|
29
35
|
#include <vector>
|
|
30
36
|
|
|
31
37
|
namespace margelo::nitro::nitroimagepipeline {
|
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
#include "Options.hpp"
|
|
12
12
|
|
|
13
13
|
#include "CacheOption.hpp"
|
|
14
|
+
#include "CornerRadii.hpp"
|
|
14
15
|
#include "JCacheOption.hpp"
|
|
16
|
+
#include "JCornerRadii.hpp"
|
|
17
|
+
#include "JVariant_Double_CornerRadii.hpp"
|
|
15
18
|
#include <optional>
|
|
19
|
+
#include <variant>
|
|
16
20
|
|
|
17
21
|
namespace margelo::nitro::nitroimagepipeline {
|
|
18
22
|
|
|
@@ -37,12 +41,12 @@ namespace margelo::nitro::nitroimagepipeline {
|
|
|
37
41
|
jni::local_ref<jni::JDouble> blur = this->getFieldValue(fieldBlur);
|
|
38
42
|
static const auto fieldCache = clazz->getField<JCacheOption>("cache");
|
|
39
43
|
jni::local_ref<JCacheOption> cache = this->getFieldValue(fieldCache);
|
|
40
|
-
static const auto fieldCornerRadius = clazz->getField<
|
|
41
|
-
jni::local_ref<
|
|
44
|
+
static const auto fieldCornerRadius = clazz->getField<JVariant_Double_CornerRadii>("cornerRadius");
|
|
45
|
+
jni::local_ref<JVariant_Double_CornerRadii> cornerRadius = this->getFieldValue(fieldCornerRadius);
|
|
42
46
|
return Options(
|
|
43
47
|
blur != nullptr ? std::make_optional(blur->value()) : std::nullopt,
|
|
44
48
|
cache != nullptr ? std::make_optional(cache->toCpp()) : std::nullopt,
|
|
45
|
-
cornerRadius != nullptr ? std::make_optional(cornerRadius->
|
|
49
|
+
cornerRadius != nullptr ? std::make_optional(cornerRadius->toCpp()) : std::nullopt
|
|
46
50
|
);
|
|
47
51
|
}
|
|
48
52
|
|
|
@@ -52,14 +56,14 @@ namespace margelo::nitro::nitroimagepipeline {
|
|
|
52
56
|
*/
|
|
53
57
|
[[maybe_unused]]
|
|
54
58
|
static jni::local_ref<JOptions::javaobject> fromCpp(const Options& value) {
|
|
55
|
-
using JSignature = JOptions(jni::alias_ref<jni::JDouble>, jni::alias_ref<JCacheOption>, jni::alias_ref<
|
|
59
|
+
using JSignature = JOptions(jni::alias_ref<jni::JDouble>, jni::alias_ref<JCacheOption>, jni::alias_ref<JVariant_Double_CornerRadii>);
|
|
56
60
|
static const auto clazz = javaClassStatic();
|
|
57
61
|
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
58
62
|
return create(
|
|
59
63
|
clazz,
|
|
60
64
|
value.blur.has_value() ? jni::JDouble::valueOf(value.blur.value()) : nullptr,
|
|
61
65
|
value.cache.has_value() ? JCacheOption::fromCpp(value.cache.value()) : nullptr,
|
|
62
|
-
value.cornerRadius.has_value() ?
|
|
66
|
+
value.cornerRadius.has_value() ? JVariant_Double_CornerRadii::fromCpp(value.cornerRadius.value()) : nullptr
|
|
63
67
|
);
|
|
64
68
|
}
|
|
65
69
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JVariant_Double_CornerRadii.cpp
|
|
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
|
+
#include "JVariant_Double_CornerRadii.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::nitroimagepipeline {
|
|
11
|
+
/**
|
|
12
|
+
* Converts JVariant_Double_CornerRadii to std::variant<double, CornerRadii>
|
|
13
|
+
*/
|
|
14
|
+
std::variant<double, CornerRadii> JVariant_Double_CornerRadii::toCpp() const {
|
|
15
|
+
if (isInstanceOf(JVariant_Double_CornerRadii_impl::First::javaClassStatic())) {
|
|
16
|
+
// It's a `double`
|
|
17
|
+
auto jniValue = static_cast<const JVariant_Double_CornerRadii_impl::First*>(this)->getValue();
|
|
18
|
+
return jniValue;
|
|
19
|
+
} else if (isInstanceOf(JVariant_Double_CornerRadii_impl::Second::javaClassStatic())) {
|
|
20
|
+
// It's a `CornerRadii`
|
|
21
|
+
auto jniValue = static_cast<const JVariant_Double_CornerRadii_impl::Second*>(this)->getValue();
|
|
22
|
+
return jniValue->toCpp();
|
|
23
|
+
}
|
|
24
|
+
throw std::invalid_argument("Variant is unknown Kotlin instance!");
|
|
25
|
+
}
|
|
26
|
+
} // namespace margelo::nitro::nitroimagepipeline
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JVariant_Double_CornerRadii.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 <variant>
|
|
12
|
+
|
|
13
|
+
#include "CornerRadii.hpp"
|
|
14
|
+
#include <variant>
|
|
15
|
+
#include "JCornerRadii.hpp"
|
|
16
|
+
#include <optional>
|
|
17
|
+
|
|
18
|
+
namespace margelo::nitro::nitroimagepipeline {
|
|
19
|
+
|
|
20
|
+
using namespace facebook;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The C++ JNI bridge between the C++ std::variant and the Java class "Variant_Double_CornerRadii".
|
|
24
|
+
*/
|
|
25
|
+
class JVariant_Double_CornerRadii: public jni::JavaClass<JVariant_Double_CornerRadii> {
|
|
26
|
+
public:
|
|
27
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroimagepipeline/Variant_Double_CornerRadii;";
|
|
28
|
+
|
|
29
|
+
static jni::local_ref<JVariant_Double_CornerRadii> create_0(double value) {
|
|
30
|
+
static const auto method = javaClassStatic()->getStaticMethod<JVariant_Double_CornerRadii(double)>("create");
|
|
31
|
+
return method(javaClassStatic(), value);
|
|
32
|
+
}
|
|
33
|
+
static jni::local_ref<JVariant_Double_CornerRadii> create_1(jni::alias_ref<JCornerRadii> value) {
|
|
34
|
+
static const auto method = javaClassStatic()->getStaticMethod<JVariant_Double_CornerRadii(jni::alias_ref<JCornerRadii>)>("create");
|
|
35
|
+
return method(javaClassStatic(), value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static jni::local_ref<JVariant_Double_CornerRadii> fromCpp(const std::variant<double, CornerRadii>& variant) {
|
|
39
|
+
switch (variant.index()) {
|
|
40
|
+
case 0: return create_0(std::get<0>(variant));
|
|
41
|
+
case 1: return create_1(JCornerRadii::fromCpp(std::get<1>(variant)));
|
|
42
|
+
default: throw std::invalid_argument("Variant holds unknown index! (" + std::to_string(variant.index()) + ")");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[[nodiscard]] std::variant<double, CornerRadii> toCpp() const;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
namespace JVariant_Double_CornerRadii_impl {
|
|
50
|
+
class First final: public jni::JavaClass<First, JVariant_Double_CornerRadii> {
|
|
51
|
+
public:
|
|
52
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroimagepipeline/Variant_Double_CornerRadii$First;";
|
|
53
|
+
|
|
54
|
+
[[nodiscard]] double getValue() const {
|
|
55
|
+
static const auto field = javaClassStatic()->getField<double>("value");
|
|
56
|
+
return getFieldValue(field);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
class Second final: public jni::JavaClass<Second, JVariant_Double_CornerRadii> {
|
|
61
|
+
public:
|
|
62
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroimagepipeline/Variant_Double_CornerRadii$Second;";
|
|
63
|
+
|
|
64
|
+
[[nodiscard]] jni::local_ref<JCornerRadii> getValue() const {
|
|
65
|
+
static const auto field = javaClassStatic()->getField<JCornerRadii>("value");
|
|
66
|
+
return getFieldValue(field);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
} // namespace JVariant_Double_CornerRadii_impl
|
|
70
|
+
} // namespace margelo::nitro::nitroimagepipeline
|