This repository was archived by the owner on Jun 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Feature: add qr scanner #357
Open
QuinsZouls
wants to merge
12
commits into
buttercup:master
Choose a base branch
from
QuinsZouls:feature/add-qr-scanner
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
73637e9
add react-native-webview dependency
QuinsZouls 3201cd5
link react-native-webview pod
QuinsZouls bbfbf5c
add CAMERA permission on android
QuinsZouls 7d640e1
setup resource folder
QuinsZouls c02c322
add HTML Scanner view
QuinsZouls 687dcc2
add webview modal for OTP fields
QuinsZouls 8e4e8a6
remove console.log
QuinsZouls 2577358
exclude html bundled files
QuinsZouls 0ff4037
add html build script
QuinsZouls 8e7259d
add instructions for building html file
QuinsZouls 944cbb7
Merge branch 'master' into feature/add-qr-scanner
perry-mitchell ad62c6d
improve import using require.resolve
QuinsZouls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,3 +80,5 @@ buck-out/ | |
|
|
||
| # General | ||
| .env | ||
|
|
||
| /resources/html/*.html | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>OTP Scanner</title> | ||
| <style> | ||
| * { | ||
| margin: 0; | ||
| padding: 0; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| main { | ||
| height: 100vh; | ||
| width: 100%; | ||
| border-radius: 15px; | ||
| } | ||
|
|
||
| #preview { | ||
| width: 100%; | ||
| height: 100%; | ||
| position: relative; | ||
| } | ||
|
|
||
| video { | ||
| width: 100%; | ||
| height: 100%; | ||
| object-fit: cover; | ||
|
|
||
| } | ||
| </style> | ||
| <script> | ||
| { { jsQRScript } } | ||
| </script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <main> | ||
| <div id="preview"> | ||
| <video id="video" autoplay muted loop playsinline></video> | ||
| <canvas id="canvas" hidden></canvas> | ||
| </div> | ||
| </main> | ||
| <script> | ||
| const video = document.getElementById('video'); | ||
| const canvas = document.getElementById('canvas'); | ||
| const context = canvas.getContext('2d'); | ||
| navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } }) | ||
| .then(function (stream) { | ||
| video.srcObject = stream; | ||
| video.play(); | ||
| requestAnimationFrame(tick); | ||
| }); | ||
| function tick() { | ||
| if (video.readyState === video.HAVE_ENOUGH_DATA) { | ||
| canvas.height = video.videoHeight; | ||
| canvas.width = video.videoWidth; | ||
|
|
||
| context.drawImage(video, 0, 0, canvas.width, canvas.height); | ||
|
|
||
| var imageData = context.getImageData(0, 0, canvas.width, canvas.height); | ||
| var code = jsQR(imageData.data, imageData.width, imageData.height, { | ||
| inversionAttempts: "dontInvert", | ||
| }); | ||
|
|
||
| if (code) { | ||
| console.log("Found QR code", code.data); | ||
| if (window.ReactNativeWebView) { | ||
| window.ReactNativeWebView.postMessage(code.data) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| requestAnimationFrame(tick); | ||
| } | ||
| </script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| const htmlPath = path.join(__dirname, "./QRScanner.template.html"); | ||
|
|
||
| const qrViewPath = path.join(__dirname, "../resources/html/OTPScanner.html"); | ||
|
|
||
| async function buildQrView() { | ||
| const jsqr = fs.readFileSync(require.resolve("jsqr/dist/jsQr.js")); | ||
| const html = fs.readFileSync(htmlPath, "utf8"); | ||
|
|
||
| const qrView = html.replace("{ { jsQRScript } }", jsqr); | ||
|
|
||
| fs.writeFileSync(qrViewPath, qrView); | ||
| } | ||
|
|
||
| buildQrView(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.