@onekeyfe/react-native-qr-scanner 0.0.0-stage → 6.8.0-27
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/LICENSE +21 -0
- package/QrScanner.podspec +42 -0
- package/README.md +78 -2
- package/android/CMakeLists.txt +23 -0
- package/android/build.gradle +147 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/cpp/cpp-adapter.cpp +8 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/HybridQrCameraList.kt +101 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/HybridQrImageDecoder.kt +66 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrCameraCatalog.kt +26 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrCameraPermission.kt +66 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrCameraZoom.kt +15 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrEngines.kt +53 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrFrameTextGate.kt +45 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrImageDecodingPipeline.kt +190 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrScanner.kt +492 -0
- package/android/src/main/java/com/margelo/nitro/qrscanner/QrScannerPackage.kt +31 -0
- package/android/src/test/java/com/margelo/nitro/qrscanner/QrCameraCatalogTest.kt +37 -0
- package/android/src/test/java/com/margelo/nitro/qrscanner/QrCameraPermissionTest.kt +82 -0
- package/android/src/test/java/com/margelo/nitro/qrscanner/QrCameraZoomTest.kt +24 -0
- package/android/src/test/java/com/margelo/nitro/qrscanner/QrFrameTextGateTest.kt +69 -0
- package/android/src/test/java/com/margelo/nitro/qrscanner/QrImageDecodingPipelineTest.kt +97 -0
- package/ios/HybridQrCameraList.swift +54 -0
- package/ios/HybridQrImageDecoder.swift +58 -0
- package/ios/QrCameraControl.swift +99 -0
- package/ios/QrFrameTextGate.swift +67 -0
- package/ios/QrImageDecodingPipeline.swift +171 -0
- package/ios/QrScanner.swift +484 -0
- package/ios/QrZXingReader.h +15 -0
- package/ios/QrZXingReader.mm +46 -0
- package/lib/module/QrCameraList.nitro.js +4 -0
- package/lib/module/QrCameraList.nitro.js.map +1 -0
- package/lib/module/QrImageDecoder.nitro.js +4 -0
- package/lib/module/QrImageDecoder.nitro.js.map +1 -0
- package/lib/module/QrScanner.js +102 -0
- package/lib/module/QrScanner.js.map +1 -0
- package/lib/module/QrScanner.nitro.js +4 -0
- package/lib/module/QrScanner.nitro.js.map +1 -0
- package/lib/module/cameras.js +34 -0
- package/lib/module/cameras.js.map +1 -0
- package/lib/module/decodeQrImage.constants.js +5 -0
- package/lib/module/decodeQrImage.constants.js.map +1 -0
- package/lib/module/decodeQrImage.js +27 -0
- package/lib/module/decodeQrImage.js.map +1 -0
- package/lib/module/errors.js +31 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/ur/assembler.js +130 -0
- package/lib/module/ur/assembler.js.map +1 -0
- package/lib/module/ur/fountain.js +139 -0
- package/lib/module/ur/fountain.js.map +1 -0
- package/lib/module/ur/index.js +6 -0
- package/lib/module/ur/index.js.map +1 -0
- package/lib/module/ur/limits.js +219 -0
- package/lib/module/ur/limits.js.map +1 -0
- package/lib/module/ur/session.js +74 -0
- package/lib/module/ur/session.js.map +1 -0
- package/lib/module/ur/types.js +2 -0
- package/lib/module/ur/types.js.map +1 -0
- package/lib/module/web/cameras.js +34 -0
- package/lib/module/web/cameras.js.map +1 -0
- package/lib/module/web/decodeQrImage.js +115 -0
- package/lib/module/web/decodeQrImage.js.map +1 -0
- package/lib/module/web/engines.js +189 -0
- package/lib/module/web/engines.js.map +1 -0
- package/lib/module/web/imageDimensions.js +176 -0
- package/lib/module/web/imageDimensions.js.map +1 -0
- package/lib/module/web/imageOps.js +112 -0
- package/lib/module/web/imageOps.js.map +1 -0
- package/lib/module/web/index.js +12 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/scanner.js +374 -0
- package/lib/module/web/scanner.js.map +1 -0
- package/lib/module/web/zxing.worker.js +11 -0
- package/lib/module/web/zxing.worker.js.map +1 -0
- package/lib/module/web/zxingWorkerProtocol.js +63 -0
- package/lib/module/web/zxingWorkerProtocol.js.map +1 -0
- package/lib/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/lib/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
- package/lib/nitrogen/generated/android/c++/JFunc_void_std__string_double.hpp +76 -0
- package/lib/nitrogen/generated/android/c++/JFunc_void_std__string_std__string_double.hpp +76 -0
- package/lib/nitrogen/generated/android/c++/JHybridQrCameraListSpec.cpp +91 -0
- package/lib/nitrogen/generated/android/c++/JHybridQrCameraListSpec.hpp +64 -0
- package/lib/nitrogen/generated/android/c++/JHybridQrImageDecoderSpec.cpp +78 -0
- package/lib/nitrogen/generated/android/c++/JHybridQrImageDecoderSpec.hpp +63 -0
- package/lib/nitrogen/generated/android/c++/JHybridQrScannerSpec.cpp +123 -0
- package/lib/nitrogen/generated/android/c++/JHybridQrScannerSpec.hpp +72 -0
- package/lib/nitrogen/generated/android/c++/JQrCameraInfo.hpp +67 -0
- package/lib/nitrogen/generated/android/c++/JQrCameraPosition.hpp +61 -0
- package/lib/nitrogen/generated/android/c++/JQrDecodeEngine.hpp +61 -0
- package/lib/nitrogen/generated/android/c++/JQrDecodePass.hpp +64 -0
- package/lib/nitrogen/generated/android/c++/JQrImageDecodeResult.hpp +70 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridQrScannerStateUpdater.cpp +94 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridQrScannerStateUpdater.hpp +54 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void.kt +78 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_double.kt +78 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_std__string_double.kt +78 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_std__string_std__string_double.kt +78 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrCameraListSpec.kt +66 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrImageDecoderSpec.kt +57 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrScannerSpec.kt +107 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrCameraInfo.kt +61 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrCameraPosition.kt +24 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrDecodeEngine.kt +24 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrDecodePass.kt +25 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrImageDecodeResult.kt +61 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/qrscannerOnLoad.kt +35 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/views/HybridQrScannerManager.kt +96 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/views/HybridQrScannerStateUpdater.kt +23 -0
- package/lib/nitrogen/generated/android/qrscanner+autolinking.cmake +87 -0
- package/lib/nitrogen/generated/android/qrscanner+autolinking.gradle +27 -0
- package/lib/nitrogen/generated/android/qrscannerOnLoad.cpp +96 -0
- package/lib/nitrogen/generated/android/qrscannerOnLoad.hpp +34 -0
- package/lib/nitrogen/generated/ios/QrScanner+autolinking.rb +62 -0
- package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.cpp +123 -0
- package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.hpp +418 -0
- package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Umbrella.hpp +73 -0
- package/lib/nitrogen/generated/ios/QrScannerAutolinking.mm +49 -0
- package/lib/nitrogen/generated/ios/QrScannerAutolinking.swift +50 -0
- package/lib/nitrogen/generated/ios/c++/HybridQrCameraListSpecSwift.cpp +11 -0
- package/lib/nitrogen/generated/ios/c++/HybridQrCameraListSpecSwift.hpp +97 -0
- package/lib/nitrogen/generated/ios/c++/HybridQrImageDecoderSpecSwift.cpp +11 -0
- package/lib/nitrogen/generated/ios/c++/HybridQrImageDecoderSpecSwift.hpp +92 -0
- package/lib/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.cpp +11 -0
- package/lib/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.hpp +110 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridQrScannerComponent.mm +168 -0
- package/lib/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_QrImageDecodeResult.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_std__string_double.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_std__string_std__string_double.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_std__vector_QrCameraInfo_.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/HybridQrCameraListSpec.swift +56 -0
- package/lib/nitrogen/generated/ios/swift/HybridQrCameraListSpec_cxx.swift +174 -0
- package/lib/nitrogen/generated/ios/swift/HybridQrImageDecoderSpec.swift +55 -0
- package/lib/nitrogen/generated/ios/swift/HybridQrImageDecoderSpec_cxx.swift +145 -0
- package/lib/nitrogen/generated/ios/swift/HybridQrScannerSpec.swift +59 -0
- package/lib/nitrogen/generated/ios/swift/HybridQrScannerSpec_cxx.swift +276 -0
- package/lib/nitrogen/generated/ios/swift/QrCameraInfo.swift +39 -0
- package/lib/nitrogen/generated/ios/swift/QrCameraPosition.swift +44 -0
- package/lib/nitrogen/generated/ios/swift/QrDecodeEngine.swift +44 -0
- package/lib/nitrogen/generated/ios/swift/QrDecodePass.swift +48 -0
- package/lib/nitrogen/generated/ios/swift/QrImageDecodeResult.swift +64 -0
- package/lib/nitrogen/generated/shared/c++/HybridQrCameraListSpec.cpp +22 -0
- package/lib/nitrogen/generated/shared/c++/HybridQrCameraListSpec.hpp +68 -0
- package/lib/nitrogen/generated/shared/c++/HybridQrImageDecoderSpec.cpp +21 -0
- package/lib/nitrogen/generated/shared/c++/HybridQrImageDecoderSpec.hpp +65 -0
- package/lib/nitrogen/generated/shared/c++/HybridQrScannerSpec.cpp +30 -0
- package/lib/nitrogen/generated/shared/c++/HybridQrScannerSpec.hpp +73 -0
- package/lib/nitrogen/generated/shared/c++/QrCameraInfo.hpp +93 -0
- package/lib/nitrogen/generated/shared/c++/QrCameraPosition.hpp +80 -0
- package/lib/nitrogen/generated/shared/c++/QrDecodeEngine.hpp +80 -0
- package/lib/nitrogen/generated/shared/c++/QrDecodePass.hpp +84 -0
- package/lib/nitrogen/generated/shared/c++/QrImageDecodeResult.hpp +97 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.cpp +42 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.hpp +97 -0
- package/lib/nitrogen/generated/shared/json/QrScannerConfig.json +14 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/QrCameraList.nitro.d.ts +24 -0
- package/lib/typescript/src/QrCameraList.nitro.d.ts.map +1 -0
- package/lib/typescript/src/QrImageDecoder.nitro.d.ts +26 -0
- package/lib/typescript/src/QrImageDecoder.nitro.d.ts.map +1 -0
- package/lib/typescript/src/QrScanner.d.ts +36 -0
- package/lib/typescript/src/QrScanner.d.ts.map +1 -0
- package/lib/typescript/src/QrScanner.nitro.d.ts +35 -0
- package/lib/typescript/src/QrScanner.nitro.d.ts.map +1 -0
- package/lib/typescript/src/cameras.d.ts +11 -0
- package/lib/typescript/src/cameras.d.ts.map +1 -0
- package/lib/typescript/src/decodeQrImage.constants.d.ts +3 -0
- package/lib/typescript/src/decodeQrImage.constants.d.ts.map +1 -0
- package/lib/typescript/src/decodeQrImage.d.ts +13 -0
- package/lib/typescript/src/decodeQrImage.d.ts.map +1 -0
- package/lib/typescript/src/errors.d.ts +13 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/ur/assembler.d.ts +5 -0
- package/lib/typescript/src/ur/assembler.d.ts.map +1 -0
- package/lib/typescript/src/ur/fountain.d.ts +17 -0
- package/lib/typescript/src/ur/fountain.d.ts.map +1 -0
- package/lib/typescript/src/ur/index.d.ts +5 -0
- package/lib/typescript/src/ur/index.d.ts.map +1 -0
- package/lib/typescript/src/ur/limits.d.ts +43 -0
- package/lib/typescript/src/ur/limits.d.ts.map +1 -0
- package/lib/typescript/src/ur/session.d.ts +11 -0
- package/lib/typescript/src/ur/session.d.ts.map +1 -0
- package/lib/typescript/src/ur/types.d.ts +61 -0
- package/lib/typescript/src/ur/types.d.ts.map +1 -0
- package/lib/typescript/src/web/cameras.d.ts +12 -0
- package/lib/typescript/src/web/cameras.d.ts.map +1 -0
- package/lib/typescript/src/web/decodeQrImage.d.ts +8 -0
- package/lib/typescript/src/web/decodeQrImage.d.ts.map +1 -0
- package/lib/typescript/src/web/engines.d.ts +31 -0
- package/lib/typescript/src/web/engines.d.ts.map +1 -0
- package/lib/typescript/src/web/imageDimensions.d.ts +10 -0
- package/lib/typescript/src/web/imageDimensions.d.ts.map +1 -0
- package/lib/typescript/src/web/imageOps.d.ts +37 -0
- package/lib/typescript/src/web/imageOps.d.ts.map +1 -0
- package/lib/typescript/src/web/index.d.ts +13 -0
- package/lib/typescript/src/web/index.d.ts.map +1 -0
- package/lib/typescript/src/web/scanner.d.ts +50 -0
- package/lib/typescript/src/web/scanner.d.ts.map +1 -0
- package/lib/typescript/src/web/zxing.worker.d.ts +2 -0
- package/lib/typescript/src/web/zxing.worker.d.ts.map +1 -0
- package/lib/typescript/src/web/zxingWorkerProtocol.d.ts +36 -0
- package/lib/typescript/src/web/zxingWorkerProtocol.d.ts.map +1 -0
- package/nitro.json +31 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_double.hpp +76 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__string_double.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridQrCameraListSpec.cpp +91 -0
- package/nitrogen/generated/android/c++/JHybridQrCameraListSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridQrImageDecoderSpec.cpp +78 -0
- package/nitrogen/generated/android/c++/JHybridQrImageDecoderSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/JHybridQrScannerSpec.cpp +123 -0
- package/nitrogen/generated/android/c++/JHybridQrScannerSpec.hpp +72 -0
- package/nitrogen/generated/android/c++/JQrCameraInfo.hpp +67 -0
- package/nitrogen/generated/android/c++/JQrCameraPosition.hpp +61 -0
- package/nitrogen/generated/android/c++/JQrDecodeEngine.hpp +61 -0
- package/nitrogen/generated/android/c++/JQrDecodePass.hpp +64 -0
- package/nitrogen/generated/android/c++/JQrImageDecodeResult.hpp +70 -0
- package/nitrogen/generated/android/c++/views/JHybridQrScannerStateUpdater.cpp +94 -0
- package/nitrogen/generated/android/c++/views/JHybridQrScannerStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_double.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_std__string_double.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_std__string_std__string_double.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrCameraListSpec.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrImageDecoderSpec.kt +57 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrScannerSpec.kt +107 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrCameraInfo.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrCameraPosition.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrDecodeEngine.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrDecodePass.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrImageDecodeResult.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/qrscannerOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/views/HybridQrScannerManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/views/HybridQrScannerStateUpdater.kt +23 -0
- package/nitrogen/generated/android/qrscanner+autolinking.cmake +87 -0
- package/nitrogen/generated/android/qrscanner+autolinking.gradle +27 -0
- package/nitrogen/generated/android/qrscannerOnLoad.cpp +96 -0
- package/nitrogen/generated/android/qrscannerOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/QrScanner+autolinking.rb +62 -0
- package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.cpp +123 -0
- package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.hpp +418 -0
- package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Umbrella.hpp +73 -0
- package/nitrogen/generated/ios/QrScannerAutolinking.mm +49 -0
- package/nitrogen/generated/ios/QrScannerAutolinking.swift +50 -0
- package/nitrogen/generated/ios/c++/HybridQrCameraListSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridQrCameraListSpecSwift.hpp +97 -0
- package/nitrogen/generated/ios/c++/HybridQrImageDecoderSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridQrImageDecoderSpecSwift.hpp +92 -0
- package/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.hpp +110 -0
- package/nitrogen/generated/ios/c++/views/HybridQrScannerComponent.mm +168 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_QrImageDecodeResult.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_std__string_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_QrCameraInfo_.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridQrCameraListSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridQrCameraListSpec_cxx.swift +174 -0
- package/nitrogen/generated/ios/swift/HybridQrImageDecoderSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridQrImageDecoderSpec_cxx.swift +145 -0
- package/nitrogen/generated/ios/swift/HybridQrScannerSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridQrScannerSpec_cxx.swift +276 -0
- package/nitrogen/generated/ios/swift/QrCameraInfo.swift +39 -0
- package/nitrogen/generated/ios/swift/QrCameraPosition.swift +44 -0
- package/nitrogen/generated/ios/swift/QrDecodeEngine.swift +44 -0
- package/nitrogen/generated/ios/swift/QrDecodePass.swift +48 -0
- package/nitrogen/generated/ios/swift/QrImageDecodeResult.swift +64 -0
- package/nitrogen/generated/shared/c++/HybridQrCameraListSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridQrCameraListSpec.hpp +68 -0
- package/nitrogen/generated/shared/c++/HybridQrImageDecoderSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridQrImageDecoderSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/HybridQrScannerSpec.cpp +30 -0
- package/nitrogen/generated/shared/c++/HybridQrScannerSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/QrCameraInfo.hpp +93 -0
- package/nitrogen/generated/shared/c++/QrCameraPosition.hpp +80 -0
- package/nitrogen/generated/shared/c++/QrDecodeEngine.hpp +80 -0
- package/nitrogen/generated/shared/c++/QrDecodePass.hpp +84 -0
- package/nitrogen/generated/shared/c++/QrImageDecodeResult.hpp +97 -0
- package/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.cpp +42 -0
- package/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.hpp +97 -0
- package/nitrogen/generated/shared/json/QrScannerConfig.json +14 -0
- package/package.json +191 -4
- package/src/QrCameraList.nitro.ts +24 -0
- package/src/QrImageDecoder.nitro.ts +27 -0
- package/src/QrScanner.nitro.ts +40 -0
- package/src/QrScanner.tsx +129 -0
- package/src/cameras.ts +37 -0
- package/src/decodeQrImage.constants.ts +2 -0
- package/src/decodeQrImage.ts +39 -0
- package/src/errors.ts +52 -0
- package/src/index.tsx +17 -0
- package/src/ur/assembler.ts +131 -0
- package/src/ur/fountain.ts +152 -0
- package/src/ur/index.ts +15 -0
- package/src/ur/limits.ts +222 -0
- package/src/ur/session.ts +57 -0
- package/src/ur/types.ts +64 -0
- package/src/web/cameras.ts +37 -0
- package/src/web/decodeQrImage.ts +107 -0
- package/src/web/engines.ts +234 -0
- package/src/web/imageDimensions.ts +157 -0
- package/src/web/imageOps.ts +128 -0
- package/src/web/index.ts +18 -0
- package/src/web/scanner.ts +421 -0
- package/src/web/zxing.worker.ts +17 -0
- package/src/web/zxingWorkerProtocol.ts +73 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
package com.margelo.nitro.qrscanner
|
|
2
|
+
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.content.pm.PackageManager
|
|
5
|
+
import android.annotation.SuppressLint
|
|
6
|
+
import android.graphics.Color
|
|
7
|
+
import android.graphics.drawable.GradientDrawable
|
|
8
|
+
import android.os.Handler
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import android.os.SystemClock
|
|
11
|
+
import android.util.Size
|
|
12
|
+
import android.view.GestureDetector
|
|
13
|
+
import android.view.MotionEvent
|
|
14
|
+
import android.view.ScaleGestureDetector
|
|
15
|
+
import android.view.View
|
|
16
|
+
import android.widget.FrameLayout
|
|
17
|
+
import androidx.annotation.OptIn
|
|
18
|
+
import androidx.camera.core.Camera
|
|
19
|
+
import androidx.camera.core.CameraSelector
|
|
20
|
+
import androidx.camera.core.CameraState
|
|
21
|
+
import androidx.camera.core.FocusMeteringAction
|
|
22
|
+
import androidx.camera.core.ExperimentalGetImage
|
|
23
|
+
import androidx.camera.core.ImageAnalysis
|
|
24
|
+
import androidx.camera.core.ImageProxy
|
|
25
|
+
import androidx.camera.core.Preview
|
|
26
|
+
import androidx.camera.core.resolutionselector.ResolutionSelector
|
|
27
|
+
import androidx.camera.core.resolutionselector.ResolutionStrategy
|
|
28
|
+
import androidx.camera.lifecycle.ProcessCameraProvider
|
|
29
|
+
import androidx.camera.view.PreviewView
|
|
30
|
+
import androidx.core.content.ContextCompat
|
|
31
|
+
import androidx.lifecycle.Lifecycle
|
|
32
|
+
import androidx.lifecycle.LifecycleEventObserver
|
|
33
|
+
import androidx.lifecycle.LifecycleOwner
|
|
34
|
+
import androidx.lifecycle.LifecycleRegistry
|
|
35
|
+
import androidx.lifecycle.Observer
|
|
36
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
37
|
+
import com.facebook.react.modules.core.PermissionAwareActivity
|
|
38
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
39
|
+
import com.google.mlkit.vision.barcode.BarcodeScannerOptions
|
|
40
|
+
import com.google.mlkit.vision.barcode.BarcodeScanning
|
|
41
|
+
import com.google.mlkit.vision.barcode.common.Barcode
|
|
42
|
+
import com.google.mlkit.vision.common.InputImage
|
|
43
|
+
import java.util.concurrent.Executors
|
|
44
|
+
import java.util.concurrent.TimeUnit
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* CameraX preview plus ML Kit QR detection. Native code reports raw text only;
|
|
48
|
+
* mode handling and BC-UR assembly run in JS through `./ur`.
|
|
49
|
+
*/
|
|
50
|
+
@DoNotStrip
|
|
51
|
+
class HybridQrScanner(val context: ThemedReactContext) : HybridQrScannerSpec(), LifecycleOwner {
|
|
52
|
+
private companion object {
|
|
53
|
+
const val DECODE_ERROR_INTERVAL_MS = 1_000L
|
|
54
|
+
const val FOCUS_INDICATOR_DP = 72
|
|
55
|
+
// A tapped focus point is held this long, then CameraX returns to
|
|
56
|
+
// continuous focus over the whole frame.
|
|
57
|
+
const val FOCUS_HOLD_SECONDS = 5L
|
|
58
|
+
|
|
59
|
+
// Shared and never shut down: ML Kit completion listeners may still be
|
|
60
|
+
// queued on it after a view is dropped.
|
|
61
|
+
val analysisExecutor = Executors.newSingleThreadExecutor { runnable ->
|
|
62
|
+
Thread(runnable, "QrScannerAnalysis").apply { isDaemon = true }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private fun newPreviewView() = PreviewView(context).apply {
|
|
67
|
+
implementationMode = PreviewView.ImplementationMode.COMPATIBLE
|
|
68
|
+
scaleType = PreviewView.ScaleType.FILL_CENTER
|
|
69
|
+
setBackgroundColor(Color.BLACK)
|
|
70
|
+
}
|
|
71
|
+
private var previewView = newPreviewView()
|
|
72
|
+
private val density = context.resources.displayMetrics.density
|
|
73
|
+
private val focusIndicator = View(context).apply {
|
|
74
|
+
val size = (FOCUS_INDICATOR_DP * density).toInt()
|
|
75
|
+
layoutParams = FrameLayout.LayoutParams(size, size)
|
|
76
|
+
background = GradientDrawable().apply {
|
|
77
|
+
setStroke((1.5f * density).toInt().coerceAtLeast(1), Color.WHITE)
|
|
78
|
+
cornerRadius = 8 * density
|
|
79
|
+
}
|
|
80
|
+
alpha = 0f
|
|
81
|
+
isClickable = false
|
|
82
|
+
}
|
|
83
|
+
private val container = FrameLayout(context).apply {
|
|
84
|
+
addView(previewView, FrameLayout.LayoutParams(
|
|
85
|
+
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT,
|
|
86
|
+
))
|
|
87
|
+
addView(focusIndicator)
|
|
88
|
+
}
|
|
89
|
+
override val view: View
|
|
90
|
+
get() = container
|
|
91
|
+
|
|
92
|
+
// Props
|
|
93
|
+
override var active: Boolean = false
|
|
94
|
+
override var cameraId: String? = null
|
|
95
|
+
override var onReady: ((generation: Double) -> Unit)? = null
|
|
96
|
+
override var onFrameText: ((text: String, generation: Double) -> Unit)? = null
|
|
97
|
+
override var onError: ((code: String, message: String, generation: Double) -> Unit)? = null
|
|
98
|
+
|
|
99
|
+
private data class CaptureCallbacks(
|
|
100
|
+
val ready: ((Double) -> Unit)? = null,
|
|
101
|
+
val frame: ((String, Double) -> Unit)? = null,
|
|
102
|
+
val error: ((String, String, Double) -> Unit)? = null,
|
|
103
|
+
)
|
|
104
|
+
@Volatile private var callbacks = CaptureCallbacks()
|
|
105
|
+
|
|
106
|
+
// The camera follows this lifecycle: RESUMED only while capturing and the
|
|
107
|
+
// host activity is resumed. Touched on the main thread only.
|
|
108
|
+
private val lifecycleRegistry = LifecycleRegistry(this)
|
|
109
|
+
override val lifecycle: Lifecycle
|
|
110
|
+
get() = lifecycleRegistry
|
|
111
|
+
|
|
112
|
+
private val main = Handler(Looper.getMainLooper())
|
|
113
|
+
private val gate = QrFrameTextGate(repeatIntervalMs = 1_000)
|
|
114
|
+
private val scanner = BarcodeScanning.getClient(
|
|
115
|
+
BarcodeScannerOptions.Builder().setBarcodeFormats(Barcode.FORMAT_QR_CODE).build(),
|
|
116
|
+
)
|
|
117
|
+
private var cameraProvider: ProcessCameraProvider? = null
|
|
118
|
+
/** The bound camera while running. Main thread only. */
|
|
119
|
+
private var camera: Camera? = null
|
|
120
|
+
/** Last `cameraId` prop value, and the id actually bound. Main thread only. */
|
|
121
|
+
private var requestedCameraId: String? = null
|
|
122
|
+
private var boundCameraId: String? = null
|
|
123
|
+
private var previewUseCase: Preview? = null
|
|
124
|
+
private var analysisUseCase: ImageAnalysis? = null
|
|
125
|
+
private var streamObserver: Observer<PreviewView.StreamState>? = null
|
|
126
|
+
private var cameraObserver: Observer<CameraState>? = null
|
|
127
|
+
private var pinchRatio = 1f
|
|
128
|
+
private var pinchGeneration: Int? = null
|
|
129
|
+
private var shouldRun = false
|
|
130
|
+
private var starting = false
|
|
131
|
+
private class PermissionWait(var cancel: (() -> Unit)? = null)
|
|
132
|
+
private var permissionWait: PermissionWait? = null
|
|
133
|
+
private var permissionDenied = false
|
|
134
|
+
private var lastDecodeFailureAt: Long? = null
|
|
135
|
+
private var hostLifecycle: Lifecycle? = null
|
|
136
|
+
private var running = false
|
|
137
|
+
private var hostResumed = true
|
|
138
|
+
private var dropped = false
|
|
139
|
+
private val hostObserver = LifecycleEventObserver { _, event ->
|
|
140
|
+
when (event) {
|
|
141
|
+
Lifecycle.Event.ON_RESUME -> { hostResumed = true; start() }
|
|
142
|
+
Lifecycle.Event.ON_PAUSE -> { hostResumed = false; stop() }
|
|
143
|
+
Lifecycle.Event.ON_DESTROY -> dispose()
|
|
144
|
+
else -> Unit
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
init {
|
|
149
|
+
main.post {
|
|
150
|
+
lifecycleRegistry.currentState = Lifecycle.State.CREATED
|
|
151
|
+
hostLifecycle = (context.currentActivity as? LifecycleOwner)?.lifecycle
|
|
152
|
+
hostResumed = hostLifecycle?.currentState?.isAtLeast(Lifecycle.State.RESUMED) ?: true
|
|
153
|
+
hostLifecycle?.addObserver(hostObserver)
|
|
154
|
+
}
|
|
155
|
+
installGestures()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@SuppressLint("ClickableViewAccessibility")
|
|
159
|
+
private fun installGestures() {
|
|
160
|
+
val scaleDetector = ScaleGestureDetector(context, object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
|
161
|
+
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
|
162
|
+
val zoom = camera?.cameraInfo?.zoomState?.value ?: return false
|
|
163
|
+
pinchGeneration = gate.currentGeneration
|
|
164
|
+
pinchRatio = zoom.zoomRatio
|
|
165
|
+
return true
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
override fun onScale(detector: ScaleGestureDetector): Boolean {
|
|
169
|
+
if (pinchGeneration != gate.currentGeneration) return false
|
|
170
|
+
val camera = camera ?: return false
|
|
171
|
+
val zoom = camera.cameraInfo.zoomState.value ?: return false
|
|
172
|
+
pinchRatio *= detector.scaleFactor
|
|
173
|
+
pinchRatio = QrCameraZoom.clampRatio(pinchRatio, zoom.minZoomRatio, zoom.maxZoomRatio)
|
|
174
|
+
camera.cameraControl.setZoomRatio(pinchRatio)
|
|
175
|
+
return true
|
|
176
|
+
}
|
|
177
|
+
}).apply { isQuickScaleEnabled = false; isStylusScaleEnabled = false }
|
|
178
|
+
val tapDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
|
|
179
|
+
override fun onDown(event: MotionEvent): Boolean = true
|
|
180
|
+
|
|
181
|
+
override fun onSingleTapUp(event: MotionEvent): Boolean {
|
|
182
|
+
focusAt(event.x, event.y)
|
|
183
|
+
return true
|
|
184
|
+
}
|
|
185
|
+
}).apply { setOnDoubleTapListener(null) }
|
|
186
|
+
var multiTouch = false
|
|
187
|
+
container.setOnTouchListener { _, event ->
|
|
188
|
+
when (event.actionMasked) {
|
|
189
|
+
MotionEvent.ACTION_DOWN -> {
|
|
190
|
+
multiTouch = false
|
|
191
|
+
container.parent?.requestDisallowInterceptTouchEvent(true)
|
|
192
|
+
}
|
|
193
|
+
MotionEvent.ACTION_POINTER_DOWN -> {
|
|
194
|
+
multiTouch = true
|
|
195
|
+
val cancel = MotionEvent.obtain(event)
|
|
196
|
+
cancel.action = MotionEvent.ACTION_CANCEL
|
|
197
|
+
tapDetector.onTouchEvent(cancel)
|
|
198
|
+
cancel.recycle()
|
|
199
|
+
}
|
|
200
|
+
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL ->
|
|
201
|
+
container.parent?.requestDisallowInterceptTouchEvent(false)
|
|
202
|
+
}
|
|
203
|
+
scaleDetector.onTouchEvent(event)
|
|
204
|
+
if (!multiTouch) tapDetector.onTouchEvent(event)
|
|
205
|
+
true
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private fun focusAt(x: Float, y: Float) {
|
|
210
|
+
val camera = camera ?: return
|
|
211
|
+
showFocusIndicator(x, y)
|
|
212
|
+
val point = previewView.meteringPointFactory.createPoint(x, y)
|
|
213
|
+
val action = FocusMeteringAction.Builder(point, FocusMeteringAction.FLAG_AF or FocusMeteringAction.FLAG_AE)
|
|
214
|
+
.setAutoCancelDuration(FOCUS_HOLD_SECONDS, TimeUnit.SECONDS)
|
|
215
|
+
.build()
|
|
216
|
+
// Rejected when the camera cannot meter that point; scanning goes on.
|
|
217
|
+
camera.cameraControl.startFocusAndMetering(action)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private fun showFocusIndicator(x: Float, y: Float) {
|
|
221
|
+
focusIndicator.animate().cancel()
|
|
222
|
+
focusIndicator.x = x - focusIndicator.width / 2f
|
|
223
|
+
focusIndicator.y = y - focusIndicator.height / 2f
|
|
224
|
+
focusIndicator.alpha = 1f
|
|
225
|
+
focusIndicator.scaleX = 1.25f
|
|
226
|
+
focusIndicator.scaleY = 1.25f
|
|
227
|
+
focusIndicator.animate().scaleX(1f).scaleY(1f).setDuration(200).withEndAction {
|
|
228
|
+
focusIndicator.animate().alpha(0f).setStartDelay(800).setDuration(300)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
override fun afterUpdate() {
|
|
233
|
+
val shouldRun = active
|
|
234
|
+
val requested = cameraId
|
|
235
|
+
val nextCallbacks = CaptureCallbacks(onReady, onFrameText, onError)
|
|
236
|
+
main.post {
|
|
237
|
+
if (dropped) return@post
|
|
238
|
+
callbacks = nextCallbacks
|
|
239
|
+
val changed = requested != requestedCameraId || shouldRun != this.shouldRun
|
|
240
|
+
requestedCameraId = requested
|
|
241
|
+
this.shouldRun = shouldRun
|
|
242
|
+
when {
|
|
243
|
+
!shouldRun -> {
|
|
244
|
+
cancelPermissionWait()
|
|
245
|
+
permissionDenied = false
|
|
246
|
+
stop()
|
|
247
|
+
}
|
|
248
|
+
running -> switchCameraIfNeeded()
|
|
249
|
+
changed -> start()
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Rebinds to a changed `cameraId` in a new capture generation. */
|
|
255
|
+
private fun switchCameraIfNeeded() {
|
|
256
|
+
val provider = cameraProvider ?: return
|
|
257
|
+
val target = selectorFor(provider) ?: return
|
|
258
|
+
if (target.second == boundCameraId) return
|
|
259
|
+
bind(provider, gate.nextGeneration())
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The requested camera when connected, else back, else front. */
|
|
263
|
+
private fun selectorFor(provider: ProcessCameraProvider): Pair<CameraSelector, String>? {
|
|
264
|
+
val infos = provider.availableCameraInfos
|
|
265
|
+
val requested = requestedCameraId?.let { id -> infos.firstOrNull { HybridQrCameraList.cameraId(it) == id } }
|
|
266
|
+
val info = requested
|
|
267
|
+
?: infos.firstOrNull { it.lensFacing == CameraSelector.LENS_FACING_BACK }
|
|
268
|
+
?: infos.firstOrNull { it.lensFacing == CameraSelector.LENS_FACING_FRONT }
|
|
269
|
+
?: infos.firstOrNull()
|
|
270
|
+
?: return null
|
|
271
|
+
val id = HybridQrCameraList.cameraId(info)
|
|
272
|
+
val selector = CameraSelector.Builder()
|
|
273
|
+
.addCameraFilter { candidates -> candidates.filter { HybridQrCameraList.cameraId(it) == id } }
|
|
274
|
+
.build()
|
|
275
|
+
return selector to id
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
override fun onDropView() = dispose()
|
|
279
|
+
|
|
280
|
+
override fun dispose() {
|
|
281
|
+
main.post {
|
|
282
|
+
if (dropped) return@post
|
|
283
|
+
dropped = true
|
|
284
|
+
callbacks = CaptureCallbacks()
|
|
285
|
+
cancelPermissionWait()
|
|
286
|
+
stop()
|
|
287
|
+
hostLifecycle?.removeObserver(hostObserver)
|
|
288
|
+
hostLifecycle = null
|
|
289
|
+
lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
|
|
290
|
+
scanner.close()
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private fun syncLifecycle() {
|
|
295
|
+
if (lifecycleRegistry.currentState == Lifecycle.State.DESTROYED) return
|
|
296
|
+
lifecycleRegistry.currentState =
|
|
297
|
+
if (running && hostResumed) Lifecycle.State.RESUMED else Lifecycle.State.CREATED
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
private fun emitError(code: String, message: String, generation: Int) {
|
|
301
|
+
callbacks.error?.invoke(code, message, generation.toDouble())
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private fun cancelPermissionWait() {
|
|
305
|
+
permissionWait?.cancel?.invoke()
|
|
306
|
+
permissionWait = null
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
private fun start() {
|
|
310
|
+
if (running || dropped || !shouldRun || !hostResumed || starting || permissionWait != null) return
|
|
311
|
+
val generation = gate.nextGeneration()
|
|
312
|
+
// Check for hardware first: a device without a camera must not prompt.
|
|
313
|
+
if (!context.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
|
|
314
|
+
emitError("no-camera", "No camera is available", generation)
|
|
315
|
+
return
|
|
316
|
+
}
|
|
317
|
+
if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) !=
|
|
318
|
+
PackageManager.PERMISSION_GRANTED
|
|
319
|
+
) {
|
|
320
|
+
val activity = context.currentActivity as? PermissionAwareActivity
|
|
321
|
+
if (activity == null) {
|
|
322
|
+
emitError("permission-denied", "Camera access is not allowed", generation)
|
|
323
|
+
return
|
|
324
|
+
}
|
|
325
|
+
if (permissionDenied) return
|
|
326
|
+
val wait = PermissionWait()
|
|
327
|
+
permissionWait = wait
|
|
328
|
+
wait.cancel = QrCameraPermission.request(activity) { granted ->
|
|
329
|
+
main.post {
|
|
330
|
+
if (permissionWait !== wait) return@post
|
|
331
|
+
permissionWait = null
|
|
332
|
+
if (!shouldRun || dropped) return@post
|
|
333
|
+
if (granted) {
|
|
334
|
+
start()
|
|
335
|
+
} else {
|
|
336
|
+
permissionDenied = true
|
|
337
|
+
emitError("permission-denied", "Camera access was denied", gate.currentGeneration)
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return
|
|
342
|
+
}
|
|
343
|
+
starting = true
|
|
344
|
+
val future = ProcessCameraProvider.getInstance(context)
|
|
345
|
+
future.addListener({
|
|
346
|
+
if (gate.currentGeneration != generation || !shouldRun || dropped) return@addListener
|
|
347
|
+
starting = false
|
|
348
|
+
val provider = try {
|
|
349
|
+
future.get()
|
|
350
|
+
} catch (error: Exception) {
|
|
351
|
+
emitError("camera-busy", error.message ?: "The camera could not start", generation)
|
|
352
|
+
return@addListener
|
|
353
|
+
}
|
|
354
|
+
cameraProvider = provider
|
|
355
|
+
bind(provider, generation)
|
|
356
|
+
}, ContextCompat.getMainExecutor(context))
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
private fun bind(provider: ProcessCameraProvider, generation: Int) {
|
|
360
|
+
val (selector, selectedId) = selectorFor(provider) ?: run {
|
|
361
|
+
emitError("no-camera", "No camera is available", generation)
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
unbind()
|
|
365
|
+
val oldPreview = previewView
|
|
366
|
+
previewView = newPreviewView()
|
|
367
|
+
container.removeView(oldPreview)
|
|
368
|
+
container.addView(previewView, 0, FrameLayout.LayoutParams(
|
|
369
|
+
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT,
|
|
370
|
+
))
|
|
371
|
+
val preview = Preview.Builder().build().also { it.surfaceProvider = previewView.surfaceProvider }
|
|
372
|
+
val analysis = ImageAnalysis.Builder()
|
|
373
|
+
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
|
374
|
+
.setResolutionSelector(
|
|
375
|
+
ResolutionSelector.Builder()
|
|
376
|
+
.setResolutionStrategy(
|
|
377
|
+
ResolutionStrategy(Size(1280, 720), ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER),
|
|
378
|
+
)
|
|
379
|
+
.build(),
|
|
380
|
+
)
|
|
381
|
+
.build()
|
|
382
|
+
analysis.setAnalyzer(analysisExecutor) { proxy -> analyze(proxy, generation) }
|
|
383
|
+
lastDecodeFailureAt = null
|
|
384
|
+
val bound = try {
|
|
385
|
+
provider.bindToLifecycle(this, selector, preview, analysis)
|
|
386
|
+
} catch (error: Exception) {
|
|
387
|
+
analysis.clearAnalyzer()
|
|
388
|
+
provider.unbind(preview, analysis)
|
|
389
|
+
emitError("camera-busy", error.message ?: "The camera could not start", generation)
|
|
390
|
+
return
|
|
391
|
+
}
|
|
392
|
+
previewUseCase = preview
|
|
393
|
+
analysisUseCase = analysis
|
|
394
|
+
camera = bound
|
|
395
|
+
boundCameraId = selectedId
|
|
396
|
+
running = true
|
|
397
|
+
var ready = false
|
|
398
|
+
var lastErrorCode: Int? = null
|
|
399
|
+
val previewStateObserver = Observer<PreviewView.StreamState> { state ->
|
|
400
|
+
if (state == PreviewView.StreamState.STREAMING &&
|
|
401
|
+
gate.currentGeneration == generation && !ready
|
|
402
|
+
) {
|
|
403
|
+
ready = true
|
|
404
|
+
gate.setCapturing(true)
|
|
405
|
+
callbacks.ready?.invoke(generation.toDouble())
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
val cameraStateObserver = Observer<CameraState> { state ->
|
|
409
|
+
if (gate.currentGeneration == generation) {
|
|
410
|
+
val error = state.error
|
|
411
|
+
if (error != null && error.code != lastErrorCode) {
|
|
412
|
+
emitError("camera-busy", error.cause?.message ?: "The camera is unavailable", generation)
|
|
413
|
+
}
|
|
414
|
+
lastErrorCode = error?.code
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
streamObserver = previewStateObserver
|
|
418
|
+
cameraObserver = cameraStateObserver
|
|
419
|
+
previewView.previewStreamState.observeForever(previewStateObserver)
|
|
420
|
+
bound.cameraInfo.cameraState.observeForever(cameraStateObserver)
|
|
421
|
+
syncLifecycle()
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
private fun stop() {
|
|
425
|
+
// A new generation makes late detections from the old one stale.
|
|
426
|
+
gate.nextGeneration()
|
|
427
|
+
starting = false
|
|
428
|
+
unbind()
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
private fun unbind() {
|
|
432
|
+
gate.setCapturing(false)
|
|
433
|
+
pinchGeneration = null
|
|
434
|
+
streamObserver?.let { previewView.previewStreamState.removeObserver(it) }
|
|
435
|
+
cameraObserver?.let { camera?.cameraInfo?.cameraState?.removeObserver(it) }
|
|
436
|
+
streamObserver = null
|
|
437
|
+
cameraObserver = null
|
|
438
|
+
val useCases = listOfNotNull(previewUseCase, analysisUseCase)
|
|
439
|
+
analysisUseCase?.clearAnalyzer()
|
|
440
|
+
previewUseCase = null
|
|
441
|
+
analysisUseCase = null
|
|
442
|
+
camera = null
|
|
443
|
+
boundCameraId = null
|
|
444
|
+
running = false
|
|
445
|
+
syncLifecycle()
|
|
446
|
+
if (useCases.isNotEmpty()) cameraProvider?.unbind(*useCases.toTypedArray())
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
private fun reportDecodeFailure(generation: Int) {
|
|
450
|
+
main.post {
|
|
451
|
+
if (!running || gate.currentGeneration != generation) return@post
|
|
452
|
+
val now = SystemClock.elapsedRealtime()
|
|
453
|
+
val last = lastDecodeFailureAt
|
|
454
|
+
if (last != null && now - last < DECODE_ERROR_INTERVAL_MS) return@post
|
|
455
|
+
lastDecodeFailureAt = now
|
|
456
|
+
emitError("decoder-unavailable", "The camera QR decoder could not read a frame", generation)
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** Runs on the analysis executor; KEEP_ONLY_LATEST keeps one frame in flight. */
|
|
461
|
+
@OptIn(ExperimentalGetImage::class)
|
|
462
|
+
private fun analyze(proxy: ImageProxy, generation: Int) {
|
|
463
|
+
val mediaImage = proxy.image
|
|
464
|
+
if (mediaImage == null) {
|
|
465
|
+
proxy.close()
|
|
466
|
+
return
|
|
467
|
+
}
|
|
468
|
+
val frameCallback = callbacks.frame
|
|
469
|
+
val task = try {
|
|
470
|
+
val input = InputImage.fromMediaImage(mediaImage, proxy.imageInfo.rotationDegrees)
|
|
471
|
+
scanner.process(input)
|
|
472
|
+
} catch (_: RuntimeException) {
|
|
473
|
+
proxy.close()
|
|
474
|
+
reportDecodeFailure(generation)
|
|
475
|
+
return
|
|
476
|
+
}
|
|
477
|
+
task
|
|
478
|
+
.addOnSuccessListener(analysisExecutor) { barcodes ->
|
|
479
|
+
val texts = barcodes.mapNotNull { it.rawValue }
|
|
480
|
+
if (texts.isEmpty()) return@addOnSuccessListener
|
|
481
|
+
val reports = gate.filter(texts, SystemClock.elapsedRealtime(), generation)
|
|
482
|
+
if (reports.isNotEmpty()) main.post {
|
|
483
|
+
if (gate.currentGeneration != generation) return@post
|
|
484
|
+
for (report in reports) frameCallback?.invoke(report.text, report.generation.toDouble())
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
.addOnCompleteListener(analysisExecutor) { result ->
|
|
488
|
+
proxy.close()
|
|
489
|
+
if (!result.isSuccessful && !result.isCanceled) reportDecodeFailure(generation)
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.margelo.nitro.qrscanner
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager
|
|
8
|
+
|
|
9
|
+
import com.margelo.nitro.qrscanner.views.HybridQrScannerManager
|
|
10
|
+
|
|
11
|
+
// The template registered no view manager, so the view never mounted on
|
|
12
|
+
// Android; this follows the other Nitro views in the repository.
|
|
13
|
+
class QrScannerPackage : BaseReactPackage() {
|
|
14
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
19
|
+
return ReactModuleInfoProvider { HashMap() }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
23
|
+
return listOf(HybridQrScannerManager())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
companion object {
|
|
27
|
+
init {
|
|
28
|
+
System.loadLibrary("qrscanner")
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
package com.margelo.nitro.qrscanner
|
|
2
|
+
|
|
3
|
+
import com.margelo.nitro.qrscanner.QrCameraCatalog.Candidate
|
|
4
|
+
import org.junit.Assert.assertEquals
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class QrCameraCatalogTest {
|
|
8
|
+
@Test
|
|
9
|
+
fun offersOneBackOneFrontThenExternalCameras() {
|
|
10
|
+
val picked = QrCameraCatalog.pick(
|
|
11
|
+
listOf(
|
|
12
|
+
Candidate("2", QrCameraPosition.BACK),
|
|
13
|
+
Candidate("1", QrCameraPosition.FRONT),
|
|
14
|
+
Candidate("0", QrCameraPosition.BACK),
|
|
15
|
+
Candidate("10", QrCameraPosition.EXTERNAL),
|
|
16
|
+
Candidate("11", QrCameraPosition.EXTERNAL),
|
|
17
|
+
),
|
|
18
|
+
)
|
|
19
|
+
assertEquals(listOf("2", "1", "10", "11"), picked.map { it.id })
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Test
|
|
23
|
+
fun dropsRepeatedIdsAndHandlesMissingPositions() {
|
|
24
|
+
val picked = QrCameraCatalog.pick(
|
|
25
|
+
listOf(Candidate("5", QrCameraPosition.EXTERNAL), Candidate("5", QrCameraPosition.EXTERNAL)),
|
|
26
|
+
)
|
|
27
|
+
assertEquals(listOf("5"), picked.map { it.id })
|
|
28
|
+
assertEquals(emptyList<Candidate>(), QrCameraCatalog.pick(emptyList()))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Test
|
|
32
|
+
fun labelsExternalCamerasInOrder() {
|
|
33
|
+
assertEquals("Back camera", QrCameraCatalog.label(QrCameraPosition.BACK, 0))
|
|
34
|
+
assertEquals("External camera", QrCameraCatalog.label(QrCameraPosition.EXTERNAL, 0))
|
|
35
|
+
assertEquals("External camera 2", QrCameraCatalog.label(QrCameraPosition.EXTERNAL, 1))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
package com.margelo.nitro.qrscanner
|
|
2
|
+
|
|
3
|
+
import android.content.pm.PackageManager
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import com.facebook.react.modules.core.PermissionAwareActivity
|
|
6
|
+
import com.facebook.react.modules.core.PermissionListener
|
|
7
|
+
import org.junit.Assert.assertEquals
|
|
8
|
+
import org.junit.Assert.assertFalse
|
|
9
|
+
import org.junit.Test
|
|
10
|
+
import org.junit.runner.RunWith
|
|
11
|
+
import org.robolectric.RobolectricTestRunner
|
|
12
|
+
import org.robolectric.Shadows.shadowOf
|
|
13
|
+
import org.robolectric.annotation.Config
|
|
14
|
+
import java.util.concurrent.TimeUnit
|
|
15
|
+
|
|
16
|
+
@RunWith(RobolectricTestRunner::class)
|
|
17
|
+
@Config(sdk = [34])
|
|
18
|
+
class QrCameraPermissionTest {
|
|
19
|
+
private class Activity : PermissionAwareActivity {
|
|
20
|
+
var prompts = 0
|
|
21
|
+
private var reply: PermissionListener? = null
|
|
22
|
+
var code = 0
|
|
23
|
+
private set
|
|
24
|
+
var currentGrant = PackageManager.PERMISSION_DENIED
|
|
25
|
+
override fun checkPermission(permission: String, pid: Int, uid: Int) = PackageManager.PERMISSION_DENIED
|
|
26
|
+
override fun checkSelfPermission(permission: String) = currentGrant
|
|
27
|
+
override fun shouldShowRequestPermissionRationale(permission: String) = false
|
|
28
|
+
|
|
29
|
+
override fun requestPermissions(permissions: Array<String>, requestCode: Int, listener: PermissionListener?) {
|
|
30
|
+
prompts++
|
|
31
|
+
reply = listener
|
|
32
|
+
code = requestCode
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fun answer(granted: Boolean, requestCode: Int = code): Boolean {
|
|
36
|
+
val result = if (granted) PackageManager.PERMISSION_GRANTED else PackageManager.PERMISSION_DENIED
|
|
37
|
+
return reply?.onRequestPermissionsResult(requestCode, emptyArray(), intArrayOf(result)) ?: false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Test fun sharesThePromptAndFansOutToActiveViews() {
|
|
42
|
+
val activity = Activity()
|
|
43
|
+
val results = mutableListOf<Pair<Int, Boolean>>()
|
|
44
|
+
val cancel = QrCameraPermission.request(activity) { results += 1 to it }
|
|
45
|
+
QrCameraPermission.request(activity) { results += 2 to it }
|
|
46
|
+
QrCameraPermission.request(activity) { results += 3 to it }
|
|
47
|
+
cancel()
|
|
48
|
+
assertEquals(1, activity.prompts)
|
|
49
|
+
activity.answer(true)
|
|
50
|
+
assertEquals(listOf(2 to true, 3 to true), results)
|
|
51
|
+
|
|
52
|
+
QrCameraPermission.request(activity) { results += 4 to it }
|
|
53
|
+
assertEquals(2, activity.prompts)
|
|
54
|
+
activity.answer(false)
|
|
55
|
+
assertEquals(4 to false, results.last())
|
|
56
|
+
}
|
|
57
|
+
@Test fun expiresALostCallbackAndDoesNotSettleTheNewRequestWithAnOldResult() {
|
|
58
|
+
val activity = Activity()
|
|
59
|
+
val results = mutableListOf<Boolean>()
|
|
60
|
+
QrCameraPermission.request(activity) { results += it }
|
|
61
|
+
val expiredCode = activity.code
|
|
62
|
+
|
|
63
|
+
shadowOf(Looper.getMainLooper()).idleFor(60, TimeUnit.SECONDS)
|
|
64
|
+
assertEquals(listOf(false), results)
|
|
65
|
+
QrCameraPermission.request(activity) { results += it }
|
|
66
|
+
assertEquals(2, activity.prompts)
|
|
67
|
+
assertFalse(activity.answer(false, expiredCode))
|
|
68
|
+
activity.answer(true)
|
|
69
|
+
assertEquals(listOf(false, true), results)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Test fun readsTheCurrentGrantAfterAMissingCallback() {
|
|
73
|
+
val activity = Activity()
|
|
74
|
+
val results = mutableListOf<Boolean>()
|
|
75
|
+
QrCameraPermission.request(activity) { results += it }
|
|
76
|
+
activity.currentGrant = PackageManager.PERMISSION_GRANTED
|
|
77
|
+
|
|
78
|
+
shadowOf(Looper.getMainLooper()).idleFor(60, TimeUnit.SECONDS)
|
|
79
|
+
assertEquals(listOf(true), results)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.margelo.nitro.qrscanner
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Test
|
|
5
|
+
|
|
6
|
+
class QrCameraZoomTest {
|
|
7
|
+
@Test
|
|
8
|
+
fun capsZoomAtEightTimes() {
|
|
9
|
+
assertEquals(8f, QrCameraZoom.clampRatio(30f, 1f, 10f), 0f)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@Test
|
|
13
|
+
fun keepsTheDeviceRange() {
|
|
14
|
+
// Logical cameras with an ultra-wide lens allow ratios below 1.
|
|
15
|
+
assertEquals(0.6f, QrCameraZoom.clampRatio(0.2f, 0.6f, 10f), 0f)
|
|
16
|
+
assertEquals(4f, QrCameraZoom.clampRatio(6f, 1f, 4f), 0f)
|
|
17
|
+
assertEquals(2.5f, QrCameraZoom.clampRatio(2.5f, 1f, 10f), 0f)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Test
|
|
21
|
+
fun aFixedFocalLengthCameraStaysAtOne() {
|
|
22
|
+
assertEquals(1f, QrCameraZoom.clampRatio(3f, 1f, 1f), 0f)
|
|
23
|
+
}
|
|
24
|
+
}
|