File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -33,13 +33,29 @@ export default class extends Controller {
33
33
connect ( ) {
34
34
console . log ( 'Init Scanner' ) ;
35
35
36
+ //This function ensures, that the qrbox is 70% of the total viewport
37
+ let qrboxFunction = function ( viewfinderWidth , viewfinderHeight ) {
38
+ let minEdgePercentage = 0.7 ; // 70%
39
+ let minEdgeSize = Math . min ( viewfinderWidth , viewfinderHeight ) ;
40
+ let qrboxSize = Math . floor ( minEdgeSize * minEdgePercentage ) ;
41
+ return {
42
+ width : qrboxSize ,
43
+ height : qrboxSize
44
+ } ;
45
+ }
46
+
36
47
//Try to get the number of cameras. If the number is 0, then the promise will fail, and we show the warning dialog
37
48
Html5Qrcode . getCameras ( ) . catch ( ( devices ) => {
38
49
document . getElementById ( 'scanner-warning' ) . classList . remove ( 'd-none' ) ;
39
50
} ) ;
40
51
41
52
this . _scanner = new Html5QrcodeScanner ( this . element . id , {
42
53
fps : 10 ,
54
+ qrbox : qrboxFunction ,
55
+ experimentalFeatures : {
56
+ //This option improves reading quality on android chrome
57
+ useBarCodeDetectorIfSupported : true
58
+ }
43
59
} , false ) ;
44
60
45
61
this . _scanner . render ( this . onScanSuccess . bind ( this ) ) ;
You can’t perform that action at this time.
0 commit comments