From f725c3df73d516bb9c80a2ebe66752ee3f7b3570 Mon Sep 17 00:00:00 2001 From: Akshat Giri Date: Sat, 16 Jun 2018 17:40:28 -0700 Subject: [PATCH 1/3] Error Correction level exposed. Simply added an prop so the error correction level could be passed in. --- lib/QRCode.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/QRCode.js b/lib/QRCode.js index 7471f47..fbc3fd5 100644 --- a/lib/QRCode.js +++ b/lib/QRCode.js @@ -55,6 +55,13 @@ var QRCode = createReactClass({ fgColor: PropTypes.string, onLoad: PropTypes.func, onLoadEnd: PropTypes.func, + // possible values for error correction level + // same as qr.js + // L ( 7% ) : 1, + // M ( 15% ) : 0, + // Q ( 25% ) : 3, + // H ( 30% ) : 2 + errorCorrectLevel: PropTypes.number }, getDefaultProps: function() { @@ -65,6 +72,7 @@ var QRCode = createReactClass({ size: 128, onLoad: () => {}, onLoadEnd: () => {}, + errorCorrectLevel: 2 // high error correction ( same as qr.js default ) } }, @@ -99,7 +107,7 @@ var QRCode = createReactClass({ value: this.props.value, bgColor: this.props.bgColor, fgColor: this.props.fgColor, - cells: qr(value).modules, + cells: qr(value, { this.props.errorCorrectLevel }).modules, }} render={renderCanvas} onLoad={this.props.onLoad} From a40f45644f3622f87ac369e262b829053679ffe5 Mon Sep 17 00:00:00 2001 From: Akshat Giri Date: Sat, 16 Jun 2018 17:52:46 -0700 Subject: [PATCH 2/3] this.props fix. There was an error in the last commit. Fixed it by making errorCorrectLevel local variable. Code completely working now. --- lib/QRCode.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/QRCode.js b/lib/QRCode.js index fbc3fd5..d7fc0ba 100644 --- a/lib/QRCode.js +++ b/lib/QRCode.js @@ -99,6 +99,7 @@ var QRCode = createReactClass({ render: function() { var size = this.props.size; var value = this.utf16to8(this.props.value); + var errorCorrectLevel = this.props.errorCorrectLevel; return ( Date: Sun, 17 Jun 2018 06:42:07 -0700 Subject: [PATCH 3/3] Readme updated with errorCorrectLevel --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8c02c23..fc7e259 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,14 @@ module.exports = HelloWorld; ``` ## Available Props -prop | type | default value -----------|----------------------|-------------- -`value` | `string` | `http://facebook.github.io/react-native/` -`size` | `number` | `128` -`bgColor` | `string` (CSS color) | `"#000"` -`fgColor` | `string` (CSS color) | `"#FFF"` +prop | type | default value +--------------------|----------------------|-------------- +`value` | `string` | `http://facebook.github.io/react-native/` +`size` | `number` | `128` +`bgColor` | `string` (CSS color) | `"#000"` +`fgColor` | `string` (CSS color) | `"#FFF"` +`errorCorrectLevel` | `number` (1, 0, 3, 2)| `"2"` +