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 {
3333 connect ( ) {
3434 console . log ( 'Init Scanner' ) ;
3535
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+
3647 //Try to get the number of cameras. If the number is 0, then the promise will fail, and we show the warning dialog
3748 Html5Qrcode . getCameras ( ) . catch ( ( devices ) => {
3849 document . getElementById ( 'scanner-warning' ) . classList . remove ( 'd-none' ) ;
3950 } ) ;
4051
4152 this . _scanner = new Html5QrcodeScanner ( this . element . id , {
4253 fps : 10 ,
54+ qrbox : qrboxFunction ,
55+ experimentalFeatures : {
56+ //This option improves reading quality on android chrome
57+ useBarCodeDetectorIfSupported : true
58+ }
4359 } , false ) ;
4460
4561 this . _scanner . render ( this . onScanSuccess . bind ( this ) ) ;
You can’t perform that action at this time.
0 commit comments