@onekeyfe/react-native-qr-scanner 6.8.0-31 → 6.8.0-33
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/android/build.gradle +1 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrCameraPermission.kt +164 -32
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrScanner.kt +53 -13
- package/android/src/test/java/com/margelo/nitro/qrscanner/QrCameraPermissionTest.kt +211 -8
- package/android/src/test/java/com/margelo/nitro/qrscanner/QrScannerContainerTest.kt +118 -0
- package/ios/QrScanner.swift +5 -5
- package/lib/module/QrScanner.js +23 -17
- package/lib/module/QrScanner.js.map +1 -1
- package/lib/module/web/scanner.js +52 -15
- package/lib/module/web/scanner.js.map +1 -1
- package/lib/nitrogen/generated/android/c++/JFunc_void_double_std__string.hpp +76 -0
- package/lib/nitrogen/generated/android/c++/JHybridQrScannerSpec.cpp +10 -10
- package/lib/nitrogen/generated/android/c++/JHybridQrScannerSpec.hpp +2 -2
- 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
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrScannerSpec.kt +3 -3
- package/lib/nitrogen/generated/android/qrscannerOnLoad.cpp +2 -2
- package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.cpp +5 -5
- package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.hpp +19 -19
- package/lib/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.hpp +2 -2
- package/lib/nitrogen/generated/ios/swift/{Func_void_double.swift → Func_void_double_std__string.swift} +11 -11
- package/lib/nitrogen/generated/ios/swift/HybridQrScannerSpec.swift +1 -1
- package/lib/nitrogen/generated/ios/swift/HybridQrScannerSpec_cxx.swift +12 -12
- package/lib/nitrogen/generated/shared/c++/HybridQrScannerSpec.hpp +2 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.cpp +1 -1
- package/lib/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.hpp +1 -1
- package/lib/typescript/src/QrScanner.d.ts +1 -1
- package/lib/typescript/src/QrScanner.d.ts.map +1 -1
- package/lib/typescript/src/QrScanner.nitro.d.ts +2 -2
- package/lib/typescript/src/QrScanner.nitro.d.ts.map +1 -1
- package/lib/typescript/src/web/scanner.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_double_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridQrScannerSpec.cpp +10 -10
- package/nitrogen/generated/android/c++/JHybridQrScannerSpec.hpp +2 -2
- 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
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrScannerSpec.kt +3 -3
- package/nitrogen/generated/android/qrscannerOnLoad.cpp +2 -2
- package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.cpp +5 -5
- package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.hpp +19 -19
- package/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.hpp +2 -2
- package/nitrogen/generated/ios/swift/{Func_void_double.swift → Func_void_double_std__string.swift} +11 -11
- package/nitrogen/generated/ios/swift/HybridQrScannerSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridQrScannerSpec_cxx.swift +12 -12
- package/nitrogen/generated/shared/c++/HybridQrScannerSpec.hpp +2 -2
- package/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.cpp +1 -1
- package/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.hpp +1 -1
- package/package.json +1 -1
- package/src/QrScanner.nitro.ts +2 -2
- package/src/QrScanner.tsx +32 -19
- package/src/web/scanner.ts +52 -16
- package/lib/nitrogen/generated/android/c++/JFunc_void_double.hpp +0 -75
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +0 -75
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
#include "JFunc_void.hpp"
|
|
20
20
|
#include "JHybridQrImageDecoderSpec.hpp"
|
|
21
21
|
#include "JHybridQrScannerSpec.hpp"
|
|
22
|
-
#include "
|
|
22
|
+
#include "JFunc_void_double_std__string.hpp"
|
|
23
23
|
#include "JFunc_void_std__string_double.hpp"
|
|
24
24
|
#include "JFunc_void_std__string_std__string_double.hpp"
|
|
25
25
|
#include "views/JHybridQrScannerStateUpdater.hpp"
|
|
@@ -67,7 +67,7 @@ void registerAllNatives() {
|
|
|
67
67
|
margelo::nitro::qrscanner::JFunc_void_cxx::registerNatives();
|
|
68
68
|
margelo::nitro::qrscanner::JHybridQrImageDecoderSpec::CxxPart::registerNatives();
|
|
69
69
|
margelo::nitro::qrscanner::JHybridQrScannerSpec::CxxPart::registerNatives();
|
|
70
|
-
margelo::nitro::qrscanner::
|
|
70
|
+
margelo::nitro::qrscanner::JFunc_void_double_std__string_cxx::registerNatives();
|
|
71
71
|
margelo::nitro::qrscanner::JFunc_void_std__string_double_cxx::registerNatives();
|
|
72
72
|
margelo::nitro::qrscanner::JFunc_void_std__string_std__string_double_cxx::registerNatives();
|
|
73
73
|
margelo::nitro::qrscanner::views::JHybridQrScannerStateUpdater::registerNatives();
|
|
@@ -80,11 +80,11 @@ namespace margelo::nitro::qrscanner::bridge::swift {
|
|
|
80
80
|
return swiftPart.toUnsafe();
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
// pragma MARK: std::function<void(double /* generation */)>
|
|
84
|
-
|
|
85
|
-
auto swiftClosure = QrScanner::
|
|
86
|
-
return [swiftClosure = std::move(swiftClosure)](double generation) mutable -> void {
|
|
87
|
-
swiftClosure.call(generation);
|
|
83
|
+
// pragma MARK: std::function<void(double /* generation */, const std::string& /* cameraId */)>
|
|
84
|
+
Func_void_double_std__string create_Func_void_double_std__string(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
85
|
+
auto swiftClosure = QrScanner::Func_void_double_std__string::fromUnsafe(swiftClosureWrapper);
|
|
86
|
+
return [swiftClosure = std::move(swiftClosure)](double generation, const std::string& cameraId) mutable -> void {
|
|
87
|
+
swiftClosure.call(generation, cameraId);
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -292,40 +292,40 @@ namespace margelo::nitro::qrscanner::bridge::swift {
|
|
|
292
292
|
return Result<std::shared_ptr<Promise<QrImageDecodeResult>>>::withError(error);
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
// pragma MARK: std::function<void(double /* generation */)>
|
|
295
|
+
// pragma MARK: std::function<void(double /* generation */, const std::string& /* cameraId */)>
|
|
296
296
|
/**
|
|
297
|
-
* Specialized version of `std::function<void(double)>`.
|
|
297
|
+
* Specialized version of `std::function<void(double, const std::string&)>`.
|
|
298
298
|
*/
|
|
299
|
-
using
|
|
299
|
+
using Func_void_double_std__string = std::function<void(double /* generation */, const std::string& /* cameraId */)>;
|
|
300
300
|
/**
|
|
301
|
-
* Wrapper class for a `std::function<void(double / * generation * /)>`, this can be used from Swift.
|
|
301
|
+
* Wrapper class for a `std::function<void(double / * generation * /, const std::string& / * cameraId * /)>`, this can be used from Swift.
|
|
302
302
|
*/
|
|
303
|
-
class
|
|
303
|
+
class Func_void_double_std__string_Wrapper final {
|
|
304
304
|
public:
|
|
305
|
-
explicit
|
|
306
|
-
inline void call(double generation) const noexcept {
|
|
307
|
-
_function->operator()(generation);
|
|
305
|
+
explicit Func_void_double_std__string_Wrapper(std::function<void(double /* generation */, const std::string& /* cameraId */)>&& func): _function(std::make_unique<std::function<void(double /* generation */, const std::string& /* cameraId */)>>(std::move(func))) {}
|
|
306
|
+
inline void call(double generation, std::string cameraId) const noexcept {
|
|
307
|
+
_function->operator()(generation, cameraId);
|
|
308
308
|
}
|
|
309
309
|
private:
|
|
310
|
-
std::unique_ptr<std::function<void(double /* generation */)>> _function;
|
|
310
|
+
std::unique_ptr<std::function<void(double /* generation */, const std::string& /* cameraId */)>> _function;
|
|
311
311
|
} SWIFT_NONCOPYABLE;
|
|
312
|
-
|
|
313
|
-
inline
|
|
314
|
-
return
|
|
312
|
+
Func_void_double_std__string create_Func_void_double_std__string(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
313
|
+
inline Func_void_double_std__string_Wrapper wrap_Func_void_double_std__string(Func_void_double_std__string value) noexcept {
|
|
314
|
+
return Func_void_double_std__string_Wrapper(std::move(value));
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
// pragma MARK: std::optional<std::function<void(double /* generation */)>>
|
|
317
|
+
// pragma MARK: std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>
|
|
318
318
|
/**
|
|
319
|
-
* Specialized version of `std::optional<std::function<void(double / * generation * /)>>`.
|
|
319
|
+
* Specialized version of `std::optional<std::function<void(double / * generation * /, const std::string& / * cameraId * /)>>`.
|
|
320
320
|
*/
|
|
321
|
-
using
|
|
322
|
-
inline std::optional<std::function<void(double /* generation */)>>
|
|
323
|
-
return std::optional<std::function<void(double /* generation */)>>(value);
|
|
321
|
+
using std__optional_std__function_void_double____generation_____const_std__string_____cameraId______ = std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>;
|
|
322
|
+
inline std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>> create_std__optional_std__function_void_double____generation_____const_std__string_____cameraId______(const std::function<void(double /* generation */, const std::string& /* cameraId */)>& value) noexcept {
|
|
323
|
+
return std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>(value);
|
|
324
324
|
}
|
|
325
|
-
inline bool
|
|
325
|
+
inline bool has_value_std__optional_std__function_void_double____generation_____const_std__string_____cameraId______(const std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>& optional) noexcept {
|
|
326
326
|
return optional.has_value();
|
|
327
327
|
}
|
|
328
|
-
inline std::function<void(double /* generation */)>
|
|
328
|
+
inline std::function<void(double /* generation */, const std::string& /* cameraId */)> get_std__optional_std__function_void_double____generation_____const_std__string_____cameraId______(const std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>& optional) noexcept {
|
|
329
329
|
return optional.value();
|
|
330
330
|
}
|
|
331
331
|
|
|
@@ -77,11 +77,11 @@ namespace margelo::nitro::qrscanner {
|
|
|
77
77
|
inline void setCameraId(const std::optional<std::string>& cameraId) noexcept override {
|
|
78
78
|
_swiftPart.setCameraId(cameraId);
|
|
79
79
|
}
|
|
80
|
-
inline std::optional<std::function<void(double /* generation */)>> getOnReady() noexcept override {
|
|
80
|
+
inline std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>> getOnReady() noexcept override {
|
|
81
81
|
auto __result = _swiftPart.getOnReady();
|
|
82
82
|
return __result;
|
|
83
83
|
}
|
|
84
|
-
inline void setOnReady(const std::optional<std::function<void(double /* generation */)>>& onReady) noexcept override {
|
|
84
|
+
inline void setOnReady(const std::optional<std::function<void(double /* generation */, const std::string& /* cameraId */)>>& onReady) noexcept override {
|
|
85
85
|
_swiftPart.setOnReady(onReady);
|
|
86
86
|
}
|
|
87
87
|
inline std::optional<std::function<void(const std::string& /* text */, double /* generation */)>> getOnFrameText() noexcept override {
|
package/nitrogen/generated/ios/swift/{Func_void_double.swift → Func_void_double_std__string.swift}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// Func_void_double_std__string.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © Marc Rousavy @ Margelo
|
|
@@ -8,21 +8,21 @@
|
|
|
8
8
|
import NitroModules
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Wraps a Swift `(_ generation: Double) -> Void` as a class.
|
|
11
|
+
* Wraps a Swift `(_ generation: Double, _ cameraId: String) -> Void` as a class.
|
|
12
12
|
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
13
|
*/
|
|
14
|
-
public final class
|
|
14
|
+
public final class Func_void_double_std__string {
|
|
15
15
|
public typealias bridge = margelo.nitro.qrscanner.bridge.swift
|
|
16
16
|
|
|
17
|
-
private let closure: (_ generation: Double) -> Void
|
|
17
|
+
private let closure: (_ generation: Double, _ cameraId: String) -> Void
|
|
18
18
|
|
|
19
|
-
public init(_ closure: @escaping (_ generation: Double) -> Void) {
|
|
19
|
+
public init(_ closure: @escaping (_ generation: Double, _ cameraId: String) -> Void) {
|
|
20
20
|
self.closure = closure
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
@inline(__always)
|
|
24
|
-
public func call(generation: Double) -> Void {
|
|
25
|
-
self.closure(generation)
|
|
24
|
+
public func call(generation: Double, cameraId: std.string) -> Void {
|
|
25
|
+
self.closure(generation, String(cameraId))
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -35,12 +35,12 @@ public final class Func_void_double {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* Casts an unsafe pointer to a `
|
|
39
|
-
* The pointer has to be a retained opaque `Unmanaged<
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_double_std__string`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_double_std__string>`.
|
|
40
40
|
* This removes one strong reference from the object!
|
|
41
41
|
*/
|
|
42
42
|
@inline(__always)
|
|
43
|
-
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) ->
|
|
44
|
-
return Unmanaged<
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_double_std__string {
|
|
44
|
+
return Unmanaged<Func_void_double_std__string>.fromOpaque(pointer).takeRetainedValue()
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -12,7 +12,7 @@ public protocol HybridQrScannerSpec_protocol: HybridObject, HybridView {
|
|
|
12
12
|
// Properties
|
|
13
13
|
var active: Bool { get set }
|
|
14
14
|
var cameraId: String? { get set }
|
|
15
|
-
var onReady: ((_ generation: Double) -> Void)? { get set }
|
|
15
|
+
var onReady: ((_ generation: Double, _ cameraId: String) -> Void)? { get set }
|
|
16
16
|
var onFrameText: ((_ text: String, _ generation: Double) -> Void)? { get set }
|
|
17
17
|
var onError: ((_ code: String, _ message: String, _ generation: Double) -> Void)? { get set }
|
|
18
18
|
|
|
@@ -156,14 +156,14 @@ open class HybridQrScannerSpec_cxx {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
public final var onReady: bridge.
|
|
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.
|
|
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.
|
|
165
|
-
let __closureWrapper =
|
|
166
|
-
return bridge.
|
|
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.
|
|
177
|
-
let __unwrapped = bridge.
|
|
178
|
-
return { () -> (Double) -> Void in
|
|
179
|
-
let __wrappedFunction = bridge.
|
|
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
package/src/QrScanner.nitro.ts
CHANGED
|
@@ -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
|
|
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
|
-
//
|
|
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
|
|
85
|
-
const
|
|
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 ?
|
|
93
|
+
committed.current = active ? { capture: captureIdentity, session: sessionIdentity } : undefined;
|
|
88
94
|
return () => { committed.current = undefined; };
|
|
89
|
-
}, [active,
|
|
95
|
+
}, [active, captureIdentity, sessionIdentity]);
|
|
90
96
|
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
if (committed.current !==
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
}, [
|
|
131
|
+
}, [acceptGeneration, session, sessionIdentity]);
|
|
125
132
|
|
|
126
133
|
return (
|
|
127
|
-
<QrScannerView
|
|
134
|
+
<QrScannerView
|
|
135
|
+
style={style}
|
|
136
|
+
active={active}
|
|
137
|
+
cameraId={cameraId}
|
|
138
|
+
onReady={nativeOnReady}
|
|
139
|
+
{...sessionCallbacks}
|
|
140
|
+
/>
|
|
128
141
|
);
|
|
129
142
|
}
|
package/src/web/scanner.ts
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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
|
|
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 &&
|
|
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
|
-
|
|
355
|
-
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
388
|
+
if (reconcileAfterRelease) {
|
|
389
|
+
staleMediaSettlements += 1;
|
|
390
|
+
if (active && stream && !hasLiveCamera() && interruptedCamera?.stream !== stream) {
|
|
391
|
+
interruptedCamera = { stream, deviceId: streamDeviceId };
|
|
392
|
+
}
|
|
362
393
|
}
|
|
363
|
-
if (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
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
|