@onekeyfe/react-native-qr-scanner 6.8.0-30 → 6.8.0-32

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 (50) hide show
  1. package/android/build.gradle +1 -0
  2. package/android/src/main/java/com/margelo/nitro/qrscanner/QrCameraPermission.kt +164 -32
  3. package/android/src/main/java/com/margelo/nitro/qrscanner/QrScanner.kt +15 -11
  4. package/android/src/test/java/com/margelo/nitro/qrscanner/QrCameraPermissionTest.kt +211 -8
  5. package/ios/QrScanner.swift +5 -5
  6. package/lib/module/QrScanner.js +23 -17
  7. package/lib/module/QrScanner.js.map +1 -1
  8. package/lib/module/web/scanner.js +52 -15
  9. package/lib/module/web/scanner.js.map +1 -1
  10. package/lib/nitrogen/generated/android/c++/JFunc_void_double_std__string.hpp +76 -0
  11. package/lib/nitrogen/generated/android/c++/JHybridQrScannerSpec.cpp +10 -10
  12. package/lib/nitrogen/generated/android/c++/JHybridQrScannerSpec.hpp +2 -2
  13. package/{nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_double.kt → lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_double_std__string.kt} +14 -14
  14. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrScannerSpec.kt +3 -3
  15. package/lib/nitrogen/generated/android/qrscannerOnLoad.cpp +2 -2
  16. package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.cpp +5 -5
  17. package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.hpp +19 -19
  18. package/lib/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.hpp +2 -2
  19. package/lib/nitrogen/generated/ios/swift/{Func_void_double.swift → Func_void_double_std__string.swift} +11 -11
  20. package/lib/nitrogen/generated/ios/swift/HybridQrScannerSpec.swift +1 -1
  21. package/lib/nitrogen/generated/ios/swift/HybridQrScannerSpec_cxx.swift +12 -12
  22. package/lib/nitrogen/generated/shared/c++/HybridQrScannerSpec.hpp +2 -2
  23. package/lib/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.cpp +1 -1
  24. package/lib/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.hpp +1 -1
  25. package/lib/typescript/src/QrScanner.d.ts +1 -1
  26. package/lib/typescript/src/QrScanner.d.ts.map +1 -1
  27. package/lib/typescript/src/QrScanner.nitro.d.ts +2 -2
  28. package/lib/typescript/src/QrScanner.nitro.d.ts.map +1 -1
  29. package/lib/typescript/src/web/scanner.d.ts.map +1 -1
  30. package/nitrogen/generated/android/c++/JFunc_void_double_std__string.hpp +76 -0
  31. package/nitrogen/generated/android/c++/JHybridQrScannerSpec.cpp +10 -10
  32. package/nitrogen/generated/android/c++/JHybridQrScannerSpec.hpp +2 -2
  33. package/{lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_double.kt → nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_double_std__string.kt} +14 -14
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrScannerSpec.kt +3 -3
  35. package/nitrogen/generated/android/qrscannerOnLoad.cpp +2 -2
  36. package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.cpp +5 -5
  37. package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.hpp +19 -19
  38. package/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.hpp +2 -2
  39. package/nitrogen/generated/ios/swift/{Func_void_double.swift → Func_void_double_std__string.swift} +11 -11
  40. package/nitrogen/generated/ios/swift/HybridQrScannerSpec.swift +1 -1
  41. package/nitrogen/generated/ios/swift/HybridQrScannerSpec_cxx.swift +12 -12
  42. package/nitrogen/generated/shared/c++/HybridQrScannerSpec.hpp +2 -2
  43. package/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.cpp +1 -1
  44. package/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.hpp +1 -1
  45. package/package.json +1 -1
  46. package/src/QrScanner.nitro.ts +2 -2
  47. package/src/QrScanner.tsx +32 -19
  48. package/src/web/scanner.ts +52 -16
  49. package/lib/nitrogen/generated/android/c++/JFunc_void_double.hpp +0 -75
  50. package/nitrogen/generated/android/c++/JFunc_void_double.hpp +0 -75
@@ -156,14 +156,14 @@ open class HybridQrScannerSpec_cxx {
156
156
  }
157
157
  }
158
158
 
159
- public final var onReady: bridge.std__optional_std__function_void_double____generation______ {
159
+ public final var onReady: bridge.std__optional_std__function_void_double____generation_____const_std__string_____cameraId______ {
160
160
  @inline(__always)
161
161
  get {
162
- return { () -> bridge.std__optional_std__function_void_double____generation______ in
162
+ return { () -> bridge.std__optional_std__function_void_double____generation_____const_std__string_____cameraId______ in
163
163
  if let __unwrappedValue = self.__implementation.onReady {
164
- return bridge.create_std__optional_std__function_void_double____generation______({ () -> bridge.Func_void_double in
165
- let __closureWrapper = Func_void_double(__unwrappedValue)
166
- return bridge.create_Func_void_double(__closureWrapper.toUnsafe())
164
+ return bridge.create_std__optional_std__function_void_double____generation_____const_std__string_____cameraId______({ () -> bridge.Func_void_double_std__string in
165
+ let __closureWrapper = Func_void_double_std__string(__unwrappedValue)
166
+ return bridge.create_Func_void_double_std__string(__closureWrapper.toUnsafe())
167
167
  }())
168
168
  } else {
169
169
  return .init()
@@ -172,13 +172,13 @@ open class HybridQrScannerSpec_cxx {
172
172
  }
173
173
  @inline(__always)
174
174
  set {
175
- self.__implementation.onReady = { () -> ((_ generation: Double) -> Void)? in
176
- if bridge.has_value_std__optional_std__function_void_double____generation______(newValue) {
177
- let __unwrapped = bridge.get_std__optional_std__function_void_double____generation______(newValue)
178
- return { () -> (Double) -> Void in
179
- let __wrappedFunction = bridge.wrap_Func_void_double(__unwrapped)
180
- return { (__generation: Double) -> Void in
181
- __wrappedFunction.call(__generation)
175
+ self.__implementation.onReady = { () -> ((_ generation: Double, _ cameraId: String) -> Void)? in
176
+ if bridge.has_value_std__optional_std__function_void_double____generation_____const_std__string_____cameraId______(newValue) {
177
+ let __unwrapped = bridge.get_std__optional_std__function_void_double____generation_____const_std__string_____cameraId______(newValue)
178
+ return { () -> (Double, String) -> Void in
179
+ let __wrappedFunction = bridge.wrap_Func_void_double_std__string(__unwrapped)
180
+ return { (__generation: Double, __cameraId: String) -> Void in
181
+ __wrappedFunction.call(__generation, std.string(__cameraId))
182
182
  }
183
183
  }()
184
184
  } else {
@@ -50,8 +50,8 @@ namespace margelo::nitro::qrscanner {
50
50
  virtual void setActive(bool active) = 0;
51
51
  virtual std::optional<std::string> getCameraId() = 0;
52
52
  virtual void setCameraId(const std::optional<std::string>& cameraId) = 0;
53
- virtual std::optional<std::function<void(double /* generation */)>> getOnReady() = 0;
54
- virtual void setOnReady(const std::optional<std::function<void(double /* generation */)>>& onReady) = 0;
53
+ virtual std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>> getOnReady() = 0;
54
+ virtual void setOnReady(const std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>& onReady) = 0;
55
55
  virtual std::optional<std::function<void(const std::string& /* text */, double /* generation */)>> getOnFrameText() = 0;
56
56
  virtual void setOnFrameText(const std::optional<std::function<void(const std::string& /* text */, double /* generation */)>>& onFrameText) = 0;
57
57
  virtual std::optional<std::function<void(const std::string& /* code */, const std::string& /* message */, double /* generation */)>> getOnError() = 0;
@@ -22,7 +22,7 @@ namespace margelo::nitro::qrscanner::views {
22
22
  react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
23
23
  active(nitro::ReactProp<bool>::fromRawValue("QrScanner", "active", rawProps, sourceProps.active)),
24
24
  cameraId(nitro::ReactProp<std::optional<std::string>>::fromRawValue("QrScanner", "cameraId", rawProps, sourceProps.cameraId)),
25
- onReady(nitro::ReactProp<std::optional<std::function<void(double /* generation */)>>>::fromRawValue("QrScanner", "onReady", rawProps, sourceProps.onReady)),
25
+ onReady(nitro::ReactProp<std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>>::fromRawValue("QrScanner", "onReady", rawProps, sourceProps.onReady)),
26
26
  onFrameText(nitro::ReactProp<std::optional<std::function<void(const std::string& /* text */, double /* generation */)>>>::fromRawValue("QrScanner", "onFrameText", rawProps, sourceProps.onFrameText)),
27
27
  onError(nitro::ReactProp<std::optional<std::function<void(const std::string& /* code */, const std::string& /* message */, double /* generation */)>>>::fromRawValue("QrScanner", "onError", rawProps, sourceProps.onError)),
28
28
  hybridRef(nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridQrScannerSpec>& /* ref */)>>>::fromRawValue("QrScanner", "hybridRef", rawProps, sourceProps.hybridRef)) { }
@@ -45,7 +45,7 @@ namespace margelo::nitro::qrscanner::views {
45
45
  public:
46
46
  nitro::ReactProp<bool> active;
47
47
  nitro::ReactProp<std::optional<std::string>> cameraId;
48
- nitro::ReactProp<std::optional<std::function<void(double /* generation */)>>> onReady;
48
+ nitro::ReactProp<std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>> onReady;
49
49
  nitro::ReactProp<std::optional<std::function<void(const std::string& /* text */, double /* generation */)>>> onFrameText;
50
50
  nitro::ReactProp<std::optional<std::function<void(const std::string& /* code */, const std::string& /* message */, double /* generation */)>>> onError;
51
51
  nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridQrScannerSpec>& /* ref */)>>> hybridRef;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-qr-scanner",
3
- "version": "6.8.0-30",
3
+ "version": "6.8.0-32",
4
4
  "description": "react-native-qr-scanner",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -21,8 +21,8 @@ export interface QrScannerProps extends HybridViewProps {
21
21
  * switches cameras in a new capture generation.
22
22
  */
23
23
  cameraId?: string;
24
- /** The first frame of a capture generation reached the preview. */
25
- onReady?: (generation: number) => void;
24
+ /** The capture is ready. The ID identifies the device actually opened. */
25
+ onReady?: (generation: number, cameraId: string) => void;
26
26
  /**
27
27
  * Text of each QR symbol seen. Repeats of the same text within one
28
28
  * generation may be suppressed natively; JS dedupes anyway.
package/src/QrScanner.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useLayoutEffect, useMemo, useRef } from 'react';
1
+ import { useCallback, useLayoutEffect, useMemo, useRef } from 'react';
2
2
 
3
3
  import { callback, getHostComponent } from 'react-native-nitro-modules';
4
4
 
@@ -34,7 +34,7 @@ export interface QrScannerComponentProps {
34
34
  */
35
35
  sessionKey?: string | number;
36
36
  style?: StyleProp<ViewStyle>;
37
- onReady?: () => void;
37
+ onReady?: (cameraId: string) => void;
38
38
  /** UR assembly progress, 0..1 (below 1 until complete). */
39
39
  onProgress?: (progress: number) => void;
40
40
  /** Fired once per session. */
@@ -77,28 +77,35 @@ export function QrScanner({
77
77
  [mode, allowPlainText, sessionKey]
78
78
  );
79
79
 
80
- // Frames from an older capture generation arrive late; drop them. Native
80
+ // Events from an older capture generation arrive late; drop them. Native
81
81
  // generations only grow for the lifetime of the view, across sessions.
82
82
  const latestGeneration = useRef(0);
83
+ const acceptGeneration = useCallback((generation: number) => {
84
+ if (generation < latestGeneration.current) return false;
85
+ latestGeneration.current = generation;
86
+ return true;
87
+ }, []);
83
88
 
84
- const committed = useRef<object | undefined>(undefined);
85
- const identity = useMemo(() => ({}), [active, cameraId, session]);
89
+ const captureIdentity = useMemo(() => ({}), [active, cameraId]);
90
+ const sessionIdentity = useMemo(() => ({}), [captureIdentity, session]);
91
+ const committed = useRef<{ capture: object; session: object } | undefined>(undefined);
86
92
  useLayoutEffect(() => {
87
- committed.current = active ? identity : undefined;
93
+ committed.current = active ? { capture: captureIdentity, session: sessionIdentity } : undefined;
88
94
  return () => { committed.current = undefined; };
89
- }, [active, identity]);
95
+ }, [active, captureIdentity, sessionIdentity]);
90
96
 
91
- const nativeCallbacks = useMemo(() => {
92
- const accept = (generation: number) => {
93
- if (committed.current !== identity || generation < latestGeneration.current) return false;
94
- latestGeneration.current = generation;
95
- return true;
96
- };
97
+ const nativeOnReady = useMemo(
98
+ () => callback((generation: number, boundCameraId: string) => {
99
+ if (committed.current?.capture !== captureIdentity || !acceptGeneration(generation)) return;
100
+ handlers.current.onReady?.(boundCameraId);
101
+ }),
102
+ [acceptGeneration, captureIdentity]
103
+ );
104
+
105
+ const sessionCallbacks = useMemo(() => {
106
+ const accept = (generation: number) =>
107
+ committed.current?.session === sessionIdentity && acceptGeneration(generation);
97
108
  return {
98
- onReady: callback((generation: number) => {
99
- if (!accept(generation)) return;
100
- handlers.current.onReady?.();
101
- }),
102
109
  onFrameText: callback((text: string, generation: number) => {
103
110
  if (!accept(generation)) return;
104
111
  const outcome = session.receive(text);
@@ -121,9 +128,15 @@ export function QrScanner({
121
128
  );
122
129
  }),
123
130
  };
124
- }, [identity, session]);
131
+ }, [acceptGeneration, session, sessionIdentity]);
125
132
 
126
133
  return (
127
- <QrScannerView style={style} active={active} cameraId={cameraId} {...nativeCallbacks} />
134
+ <QrScannerView
135
+ style={style}
136
+ active={active}
137
+ cameraId={cameraId}
138
+ onReady={nativeOnReady}
139
+ {...sessionCallbacks}
140
+ />
128
141
  );
129
142
  }
@@ -82,9 +82,12 @@ export function createWebQrScanner(options: WebQrScannerOptions): WebQrScanner {
82
82
  let disposed = false;
83
83
  let active = false;
84
84
  let acquisition: { deviceId?: string; cancelPreview?: () => void } | undefined;
85
+ let mediaAcquisitions = 0;
86
+ let staleMediaSettlements = 0;
85
87
  const usesBuiltInSession = !handlers.onFrameText || !!handlers.onResult || !!handlers.onProgress;
86
88
  let stream: MediaStream | undefined;
87
- let interruptedStream: MediaStream | undefined;
89
+ type RecoveryTarget = { stream: MediaStream; deviceId?: string; blockedAt?: number };
90
+ let interruptedCamera: RecoveryTarget | undefined;
88
91
  let frameHandle: number | undefined;
89
92
  let timer: ReturnType<typeof setTimeout> | undefined;
90
93
  let analysing = false;
@@ -238,7 +241,14 @@ export function createWebQrScanner(options: WebQrScannerOptions): WebQrScanner {
238
241
  const hasLiveCamera = () =>
239
242
  stream?.getVideoTracks().some((track) => track.readyState === 'live') ?? false;
240
243
 
241
- async function acquireCamera(requestedId: string | undefined, allowDefault: boolean) {
244
+ async function acquireCamera(
245
+ requestedId: string | undefined,
246
+ allowDefault: boolean,
247
+ recovery?: RecoveryTarget
248
+ ) {
249
+ const settlementsAtRecoveryStart = recovery && mediaAcquisitions > 0
250
+ ? staleMediaSettlements
251
+ : undefined;
242
252
  invalidateAcquisition();
243
253
  const attempt: NonNullable<typeof acquisition> = { deviceId: requestedId };
244
254
  acquisition = attempt;
@@ -261,7 +271,10 @@ export function createWebQrScanner(options: WebQrScannerOptions): WebQrScanner {
261
271
  throw new QrScannerError('no-camera', 'getUserMedia is not available');
262
272
  }
263
273
  const open = (id?: string) => {
264
- requestedMedia = true;
274
+ if (!requestedMedia) {
275
+ requestedMedia = true;
276
+ mediaAcquisitions += 1;
277
+ }
265
278
  return navigator.mediaDevices.getUserMedia({
266
279
  audio: false,
267
280
  video: {
@@ -272,6 +285,11 @@ export function createWebQrScanner(options: WebQrScannerOptions): WebQrScanner {
272
285
  },
273
286
  });
274
287
  };
288
+ if (recovery && stream === recovery.stream) {
289
+ generation += 1;
290
+ cancelSchedule();
291
+ releaseCamera();
292
+ }
275
293
  const previous = stream;
276
294
  try {
277
295
  candidate = await open(requestedId);
@@ -281,7 +299,10 @@ export function createWebQrScanner(options: WebQrScannerOptions): WebQrScanner {
281
299
  return;
282
300
  }
283
301
  const code = cameraErrorCode(error);
284
- if (previous && stream === previous && hasLiveCamera() && code === 'camera-busy') {
302
+ if (previous && stream === previous && code === 'camera-busy') {
303
+ if (!recovery && !hasLiveCamera()) {
304
+ interruptedCamera = { stream: previous, deviceId: streamDeviceId };
305
+ }
285
306
  generation += 1;
286
307
  cancelSchedule();
287
308
  releaseCamera();
@@ -334,6 +355,7 @@ export function createWebQrScanner(options: WebQrScannerOptions): WebQrScanner {
334
355
  streamDeviceId = attempt.deviceId;
335
356
  candidate = undefined;
336
357
  acquisition = undefined;
358
+ interruptedCamera = undefined;
337
359
  superseded?.getTracks().forEach((track) => track.stop());
338
360
  if (preview !== video) {
339
361
  preview.srcObject = null;
@@ -350,21 +372,35 @@ export function createWebQrScanner(options: WebQrScannerOptions): WebQrScanner {
350
372
  return;
351
373
  }
352
374
  acquisition = undefined;
375
+ const failedToOpen = requestedMedia && !candidate;
353
376
  releaseCandidate();
354
- fail(error instanceof QrScannerError ? error.code : cameraErrorCode(error),
355
- error instanceof Error ? error.message : String(error));
377
+ const code = error instanceof QrScannerError ? error.code : cameraErrorCode(error);
378
+ if (
379
+ recovery && failedToOpen && code === 'camera-busy' && settlementsAtRecoveryStart !== undefined
380
+ ) {
381
+ interruptedCamera = { ...recovery, blockedAt: settlementsAtRecoveryStart };
382
+ return;
383
+ }
384
+ if (recovery && interruptedCamera === recovery) interruptedCamera = undefined;
385
+ fail(code, error instanceof Error ? error.message : String(error));
356
386
  } finally {
357
387
  releaseCandidate();
358
- // A stale request can preempt the working camera while the newest
359
- // request is still opening. Keep that recovery pending until it settles.
360
- if (reconcileAfterRelease && active && stream && !hasLiveCamera()) {
361
- interruptedStream = stream;
388
+ if (reconcileAfterRelease) {
389
+ staleMediaSettlements += 1;
390
+ if (active && stream && !hasLiveCamera() && interruptedCamera?.stream !== stream) {
391
+ interruptedCamera = { stream, deviceId: streamDeviceId };
392
+ }
362
393
  }
363
- if (active && !acquisition && interruptedStream) {
364
- const interrupted = interruptedStream;
365
- interruptedStream = undefined;
366
- if (stream === interrupted && !hasLiveCamera()) {
367
- await acquireCamera(streamDeviceId, true);
394
+ if (requestedMedia) mediaAcquisitions -= 1;
395
+ const interrupted = interruptedCamera;
396
+ // An unanswered permission prompt may never settle. Only park a
397
+ // restore after a busy result, and let each stale settlement wake it.
398
+ if (active && !acquisition && interrupted && interrupted.blockedAt !== staleMediaSettlements) {
399
+ if ((!stream || stream === interrupted.stream) && !hasLiveCamera()) {
400
+ // A newer switch can supersede this restore and still need its target.
401
+ await acquireCamera(interrupted.deviceId, true, interrupted);
402
+ } else {
403
+ interruptedCamera = undefined;
368
404
  }
369
405
  }
370
406
  }
@@ -401,7 +437,7 @@ export function createWebQrScanner(options: WebQrScannerOptions): WebQrScanner {
401
437
  },
402
438
  stop() {
403
439
  active = false;
404
- interruptedStream = undefined;
440
+ interruptedCamera = undefined;
405
441
  generation += 1;
406
442
  invalidateAcquisition();
407
443
  cancelSchedule();
@@ -1,75 +0,0 @@
1
- ///
2
- /// JFunc_void_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::qrscanner {
17
-
18
- using namespace facebook;
19
-
20
- /**
21
- * Represents the Java/Kotlin callback `(generation: Double) -> Unit`.
22
- * This can be passed around between C++ and Java/Kotlin.
23
- */
24
- struct JFunc_void_double: public jni::JavaClass<JFunc_void_double> {
25
- public:
26
- static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/qrscanner/Func_void_double;";
27
-
28
- public:
29
- /**
30
- * Invokes the function this `JFunc_void_double` instance holds through JNI.
31
- */
32
- void invoke(double generation) const {
33
- static const auto method = javaClassStatic()->getMethod<void(double /* generation */)>("invoke");
34
- method(self(), generation);
35
- }
36
- };
37
-
38
- /**
39
- * An implementation of Func_void_double that is backed by a C++ implementation (using `std::function<...>`)
40
- */
41
- class JFunc_void_double_cxx final: public jni::HybridClass<JFunc_void_double_cxx, JFunc_void_double> {
42
- public:
43
- static jni::local_ref<JFunc_void_double::javaobject> fromCpp(const std::function<void(double /* generation */)>& func) {
44
- return JFunc_void_double_cxx::newObjectCxxArgs(func);
45
- }
46
-
47
- public:
48
- /**
49
- * Invokes the C++ `std::function<...>` this `JFunc_void_double_cxx` instance holds.
50
- */
51
- void invoke_cxx(double generation) {
52
- _func(generation);
53
- }
54
-
55
- public:
56
- [[nodiscard]]
57
- inline const std::function<void(double /* generation */)>& getFunction() const {
58
- return _func;
59
- }
60
-
61
- public:
62
- static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/qrscanner/Func_void_double_cxx;";
63
- static void registerNatives() {
64
- registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_double_cxx::invoke_cxx)});
65
- }
66
-
67
- private:
68
- explicit JFunc_void_double_cxx(const std::function<void(double /* generation */)>& func): _func(func) { }
69
-
70
- private:
71
- friend HybridBase;
72
- std::function<void(double /* generation */)> _func;
73
- };
74
-
75
- } // namespace margelo::nitro::qrscanner
@@ -1,75 +0,0 @@
1
- ///
2
- /// JFunc_void_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::qrscanner {
17
-
18
- using namespace facebook;
19
-
20
- /**
21
- * Represents the Java/Kotlin callback `(generation: Double) -> Unit`.
22
- * This can be passed around between C++ and Java/Kotlin.
23
- */
24
- struct JFunc_void_double: public jni::JavaClass<JFunc_void_double> {
25
- public:
26
- static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/qrscanner/Func_void_double;";
27
-
28
- public:
29
- /**
30
- * Invokes the function this `JFunc_void_double` instance holds through JNI.
31
- */
32
- void invoke(double generation) const {
33
- static const auto method = javaClassStatic()->getMethod<void(double /* generation */)>("invoke");
34
- method(self(), generation);
35
- }
36
- };
37
-
38
- /**
39
- * An implementation of Func_void_double that is backed by a C++ implementation (using `std::function<...>`)
40
- */
41
- class JFunc_void_double_cxx final: public jni::HybridClass<JFunc_void_double_cxx, JFunc_void_double> {
42
- public:
43
- static jni::local_ref<JFunc_void_double::javaobject> fromCpp(const std::function<void(double /* generation */)>& func) {
44
- return JFunc_void_double_cxx::newObjectCxxArgs(func);
45
- }
46
-
47
- public:
48
- /**
49
- * Invokes the C++ `std::function<...>` this `JFunc_void_double_cxx` instance holds.
50
- */
51
- void invoke_cxx(double generation) {
52
- _func(generation);
53
- }
54
-
55
- public:
56
- [[nodiscard]]
57
- inline const std::function<void(double /* generation */)>& getFunction() const {
58
- return _func;
59
- }
60
-
61
- public:
62
- static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/qrscanner/Func_void_double_cxx;";
63
- static void registerNatives() {
64
- registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_double_cxx::invoke_cxx)});
65
- }
66
-
67
- private:
68
- explicit JFunc_void_double_cxx(const std::function<void(double /* generation */)>& func): _func(func) { }
69
-
70
- private:
71
- friend HybridBase;
72
- std::function<void(double /* generation */)> _func;
73
- };
74
-
75
- } // namespace margelo::nitro::qrscanner