-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from ugahacks/feature/scanner-additions
fuck
- Loading branch information
Showing
3 changed files
with
68 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,59 +1,63 @@ | ||
// Html5QrcodePlugin.jsx | ||
|
||
import { Html5QrcodeScanner } from "html5-qrcode"; | ||
import React from 'react'; | ||
import React from "react"; | ||
|
||
const qrcodeRegionId = "html5qr-code-full-region"; | ||
|
||
class Html5QrcodePlugin extends React.Component<any> { | ||
html5QrcodeScanner: Html5QrcodeScanner | undefined = undefined; | ||
|
||
render() { | ||
return <div id={qrcodeRegionId} />; | ||
html5QrcodeScanner: Html5QrcodeScanner | undefined = undefined; | ||
|
||
render() { | ||
return <div id={qrcodeRegionId} />; | ||
} | ||
|
||
componentWillUnmount() { | ||
// TODO(mebjas): See if there is a better way to handle | ||
// promise in `componentWillUnmount`. | ||
if (this.html5QrcodeScanner == undefined) return; | ||
this.html5QrcodeScanner.clear().catch((error) => { | ||
console.error("Failed to clear html5QrcodeScanner. ", error); | ||
}); | ||
} | ||
|
||
componentDidMount() { | ||
// Creates the configuration object for Html5QrcodeScanner. | ||
function createConfig(props: any) { | ||
var config: any = {}; | ||
if (props.fps) { | ||
config.fps = props.fps; | ||
} | ||
if (props.qrbox) { | ||
config.qrbox = props.qrbox; | ||
} | ||
if (props.aspectRatio) { | ||
config.aspectRatio = props.aspectRatio; | ||
} | ||
if (props.disableFlip !== undefined) { | ||
config.disableFlip = props.disableFlip; | ||
} | ||
return config; | ||
} | ||
|
||
componentWillUnmount() { | ||
// TODO(mebjas): See if there is a better way to handle | ||
// promise in `componentWillUnmount`. | ||
if (this.html5QrcodeScanner == undefined) return; | ||
this.html5QrcodeScanner.clear().catch(error => { | ||
console.error("Failed to clear html5QrcodeScanner. ", error); | ||
}); | ||
} | ||
var config = createConfig(this.props); | ||
var verbose = this.props.verbose === true; | ||
|
||
componentDidMount() { | ||
// Creates the configuration object for Html5QrcodeScanner. | ||
function createConfig(props: any) { | ||
var config: any = {}; | ||
if (props.fps) { | ||
config.fps = props.fps; | ||
} | ||
if (props.qrbox) { | ||
config.qrbox = props.qrbox; | ||
} | ||
if (props.aspectRatio) { | ||
config.aspectRatio = props.aspectRatio; | ||
} | ||
if (props.disableFlip !== undefined) { | ||
config.disableFlip = props.disableFlip; | ||
} | ||
return config; | ||
} | ||
|
||
var config = createConfig(this.props); | ||
var verbose = this.props.verbose === true; | ||
|
||
// Suceess callback is required. | ||
if (!(this.props.qrCodeSuccessCallback )) { | ||
throw "qrCodeSuccessCallback is required callback."; | ||
} | ||
|
||
this.html5QrcodeScanner = new Html5QrcodeScanner( | ||
qrcodeRegionId, config, verbose); | ||
this.html5QrcodeScanner.render( | ||
this.props.qrCodeSuccessCallback, | ||
this.props.qrCodeErrorCallback); | ||
// Suceess callback is required. | ||
if (!this.props.qrCodeSuccessCallback) { | ||
throw "qrCodeSuccessCallback is required callback."; | ||
} | ||
}; | ||
|
||
export default Html5QrcodePlugin; | ||
this.html5QrcodeScanner = new Html5QrcodeScanner( | ||
qrcodeRegionId, | ||
config, | ||
verbose | ||
); | ||
this.html5QrcodeScanner.render( | ||
this.props.qrCodeSuccessCallback, | ||
this.props.qrCodeErrorCallback | ||
); | ||
} | ||
} | ||
|
||
export default Html5QrcodePlugin; |
This file contains 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 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