|
| 1 | +# 🔲 react-native-custom-qr-codes |
1 | 2 |
|
2 | | -# react-native-custom-qr-codes |
| 3 | +Fully customizable QR code component for React Native with TypeScript support and RTL layout compatibility. Style the code pieces, eye shapes, colors, gradients, logos, and background images however you need. |
3 | 4 |
|
4 | | -<p align="center"> |
5 | | - <img alt="example-qr-code-1" src="https://raw.githubusercontent.com/nating/react-native-custom-qr-codes/HEAD/assets/qr-code-1.png" width="250"> |
6 | | - <img alt="example-qr-code-1" src="https://raw.githubusercontent.com/nating/react-native-custom-qr-codes/HEAD/assets/qr-code-2.png" width="250"> |
7 | | - <img alt="example-qr-code-3" src="https://raw.githubusercontent.com/nating/react-native-custom-qr-codes/HEAD/assets/qr-code-3.png" width="250"> |
8 | | -</p> |
9 | | - |
10 | | -<p align="center"> |
11 | | -</p> |
| 5 | +[](https://www.npmjs.com/package/@oguzhnatly/react-native-custom-qr-codes) |
| 6 | +[](https://www.npmjs.com/package/@oguzhnatly/react-native-custom-qr-codes) |
| 7 | +[](LICENSE) |
| 8 | +[](https://github.com/oguzhnatly/react-native-custom-qr-codes) |
12 | 9 |
|
13 | 10 | <p align="center"> |
14 | | - Customisable QR Codes for React Native. |
| 11 | + <img alt="QR Code Example 1" src="https://raw.githubusercontent.com/oguzhnatly/react-native-custom-qr-codes/master/assets/qr-code-1.png" width="200"> |
| 12 | + <img alt="QR Code Example 2" src="https://raw.githubusercontent.com/oguzhnatly/react-native-custom-qr-codes/master/assets/qr-code-2.png" width="200"> |
| 13 | + <img alt="QR Code Example 3" src="https://raw.githubusercontent.com/oguzhnatly/react-native-custom-qr-codes/master/assets/qr-code-3.png" width="200"> |
15 | 14 | </p> |
16 | 15 |
|
| 16 | +--- |
| 17 | + |
| 18 | +## Features |
| 19 | + |
| 20 | +- ✅ Full TypeScript support with typed props |
| 21 | +- ✅ RTL layout support |
| 22 | +- ✅ Multiple code piece styles: square, circle, dot, diamond, sharp, ninja |
| 23 | +- ✅ Independent eye shape control (outer and inner separately) |
| 24 | +- ✅ Linear gradient foreground colors |
| 25 | +- ✅ Logo overlay in the center of the QR code |
| 26 | +- ✅ Background image fill for code pieces |
| 27 | +- ✅ Configurable error correction level |
| 28 | +- ✅ iOS and Android |
| 29 | + |
| 30 | +--- |
| 31 | + |
17 | 32 | ## Installation |
18 | 33 |
|
19 | | -`npm install react-native-custom-qr-codes` |
| 34 | +```sh |
| 35 | +npm install @oguzhnatly/react-native-custom-qr-codes |
| 36 | +``` |
| 37 | + |
| 38 | +```sh |
| 39 | +yarn add @oguzhnatly/react-native-custom-qr-codes |
| 40 | +``` |
20 | 41 |
|
21 | | -If you are not using Expo, you will also have to manually link the [react-native-svg library](https://github.com/react-native-community/react-native-svg). |
22 | | -Follow [the instructions here](https://github.com/react-native-community/react-native-svg#manual) to do this. |
| 42 | +This package depends on `react-native-svg`. If you are not using Expo, install and link it manually: |
23 | 43 |
|
24 | | -## Usage |
| 44 | +```sh |
| 45 | +npm install react-native-svg |
| 46 | +cd ios && pod install |
| 47 | +``` |
| 48 | + |
| 49 | +For manual linking instructions see the [react-native-svg documentation](https://github.com/software-mansion/react-native-svg#installation). |
| 50 | + |
| 51 | +--- |
25 | 52 |
|
| 53 | +## Usage |
26 | 54 |
|
27 | | -```jsx |
28 | | -import { QRCode } from 'react-native-custom-qr-codes'; |
| 55 | +```tsx |
| 56 | +import { QRCode } from '@oguzhnatly/react-native-custom-qr-codes'; |
29 | 57 |
|
30 | | -<QRCode content='https://reactnative.com'/> |
| 58 | +<QRCode content="https://github.com/oguzhnatly" /> |
31 | 59 | ``` |
32 | 60 |
|
33 | | -### Properties |
34 | | - |
35 | | -| Prop | Description | Default | |
36 | | -|---|---|---| |
37 | | -|**`content`**|The String to be encoded in the QR code. |`'No Content'`| |
38 | | -|**`codeStyle`**|The style of the centre QR Code pieces. |`square`| |
39 | | -|**`outerEyeStyle`**|The style of the outside of the QR Code's eyes. |`square`| |
40 | | -|**`innerEyeStyle`**|The style of the inside of the QR Code's eyes. |`square`| |
41 | | -|**`size`**|The width & height of the component. |`250`| |
42 | | -|**`color`**|The color of the QR Code. |`black`| |
43 | | -|**`backgroundColor`**|The background color of the component. |`white`| |
44 | | -|**`padding`**|The padding between the edge of the component and the QR Code itself (In terms of QR code piece sizes). |`1`| |
45 | | -|**`logo`**|The image to be put in the centre of the QR Code.<br>**Must use a higher `ecl` for QR Code to work with a logo. <br>(L->M->Q->H)** |none| |
46 | | -|**`logoSize`**|The size of the logo in the QR Code. |none| |
47 | | -|**`linearGradient`**|The two colors to be used for the linear gradient for the foreground. |none| |
48 | | -|**`gradientDirection`**|The numbers that [define the orientation of the linear gradient](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients). |`[0,0,170,0]`| |
49 | | -|**`backgroundImage`**|The image to be used as the filling of the QR Code pieces.<br>**The Eyes can not be styled if a background image is used.**|none| |
50 | | -|**`ecl`**|The [error correction level](http://www.qrcode.com/en/about/error_correction.html) of the QR Code. |`L`| |
| 61 | +--- |
| 62 | + |
| 63 | +## Props |
| 64 | + |
| 65 | +| Prop | Type | Default | Description | |
| 66 | +|---|---|---|---| |
| 67 | +| `content` | `string` | `'No Content'` | The string to encode in the QR code | |
| 68 | +| `size` | `number` | `250` | Width and height of the component in pixels | |
| 69 | +| `padding` | `number` | `1` | Padding between the edge and the QR code in piece units | |
| 70 | +| `color` | `string` | `'black'` | Foreground color of the QR code | |
| 71 | +| `backgroundColor` | `string` | `'white'` | Background color of the component | |
| 72 | +| `codeStyle` | `string` | `'square'` | Style of the centre QR code pieces. See values below | |
| 73 | +| `outerEyeStyle` | `string` | `'square'` | Style of the outer frame of the QR code eyes | |
| 74 | +| `innerEyeStyle` | `string` | `'square'` | Style of the inner dot of the QR code eyes | |
| 75 | +| `ecl` | `string` | `'L'` | Error correction level. Higher levels allow logo overlays. `L` `M` `Q` `H` | |
| 76 | +| `logo` | `ImageSource` | none | Image source to display in the center of the QR code. Requires a higher `ecl` | |
| 77 | +| `logoSize` | `number` | none | Size of the logo overlay in pixels | |
| 78 | +| `linearGradient` | `ColorValue[]` | none | Two colors used for a linear gradient on the foreground | |
| 79 | +| `gradientDirection` | `number[]` | `[0,0,170,0]` | Numbers defining the [gradient orientation](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients) | |
| 80 | +| `backgroundImage` | `ImageSource` | none | Image used as the fill pattern for QR code pieces. Eye styling is disabled when this is used | |
| 81 | +| `isRTL` | `boolean` | `false` | Enables right-to-left layout rendering | |
| 82 | + |
| 83 | +### `codeStyle` values |
| 84 | + |
| 85 | +`square` `circle` `dot` `diamond` `sharp` `ninja` |
| 86 | + |
| 87 | +### `outerEyeStyle` values |
| 88 | + |
| 89 | +`square` `circle` `circles` `diamond` `rounded` |
| 90 | + |
| 91 | +### `innerEyeStyle` values |
| 92 | + |
| 93 | +`square` `circle` `circles` `diamond` `rounded` |
| 94 | + |
| 95 | +--- |
51 | 96 |
|
52 | 97 | ## Examples |
53 | 98 |
|
54 | | -### `codeStyle` |
55 | | -```jsx |
56 | | -<QRCode codeStyle='square' /> |
57 | | -<QRCode codeStyle='circle' /> |
58 | | -<QRCode codeStyle='dot' /> |
59 | | -<QRCode codeStyle='diamond' /> |
60 | | -<QRCode codeStyle='sharp' /> |
61 | | -``` |
62 | | -<img src='./assets/example-code-styles.png' height='250'/> |
| 99 | +### Code styles |
63 | 100 |
|
64 | | -### `outerEyeStyle` |
65 | | -```jsx |
66 | | -<QRCode outerEyeStyle='square' /> |
67 | | -<QRCode outerEyeStyle='circle' /> |
68 | | -<QRCode outerEyeStyle='diamond' /> |
| 101 | +```tsx |
| 102 | +<QRCode content="https://example.com" codeStyle="square" /> |
| 103 | +<QRCode content="https://example.com" codeStyle="circle" /> |
| 104 | +<QRCode content="https://example.com" codeStyle="dot" /> |
| 105 | +<QRCode content="https://example.com" codeStyle="diamond" /> |
| 106 | +<QRCode content="https://example.com" codeStyle="sharp" /> |
69 | 107 | ``` |
70 | | -<img src='./assets/example-outer-eye-styles.png' height='250'/> |
71 | 108 |
|
72 | | -### `innerEyeStyle` |
73 | | -```jsx |
74 | | -<QRCode innerEyeStyle='square' /> |
75 | | -<QRCode innerEyeStyle='circle' /> |
76 | | -<QRCode innerEyeStyle='diamond' /> |
| 109 | +<img src="./assets/example-code-styles.png" height="220" /> |
| 110 | + |
| 111 | +### Eye styles |
| 112 | + |
| 113 | +```tsx |
| 114 | +<QRCode content="https://example.com" outerEyeStyle="square" innerEyeStyle="square" /> |
| 115 | +<QRCode content="https://example.com" outerEyeStyle="circle" innerEyeStyle="circle" /> |
| 116 | +<QRCode content="https://example.com" outerEyeStyle="diamond" innerEyeStyle="diamond" /> |
77 | 117 | ``` |
78 | | -<img src='./assets/example-inner-eye-styles.png' height='250'/> |
79 | 118 |
|
80 | | -### logo |
81 | | -```jsx |
82 | | -<QRCode logo={require('./dab.png')} /> |
| 119 | +<img src="./assets/example-outer-eye-styles.png" height="220" /> |
| 120 | +<img src="./assets/example-inner-eye-styles.png" height="220" /> |
| 121 | + |
| 122 | +### Logo overlay |
| 123 | + |
| 124 | +Use `ecl="H"` to ensure the QR code remains scannable with a logo covering the center: |
| 125 | + |
| 126 | +```tsx |
| 127 | +<QRCode |
| 128 | + content="https://example.com" |
| 129 | + logo={require('./logo.png')} |
| 130 | + logoSize={60} |
| 131 | + ecl="H" |
| 132 | +/> |
83 | 133 | ``` |
84 | | -<img src='./assets/example-logo.png' height='250'/> |
85 | 134 |
|
86 | | -### linearGradient |
87 | | -```jsx |
88 | | -<QRCode linearGradient={['rgb(255,0,0)','rgb(0,255,255)']} /> |
89 | | -<QRCode linearGradient={['rgb(255,0,0)','rgb(0,255,255)']} gradientDirection={[0,170,0,0]} /> |
| 135 | +<img src="./assets/example-logo.png" height="220" /> |
| 136 | + |
| 137 | +### Linear gradient |
| 138 | + |
| 139 | +```tsx |
| 140 | +<QRCode |
| 141 | + content="https://example.com" |
| 142 | + linearGradient={['rgb(255,0,0)', 'rgb(0,100,255)']} |
| 143 | +/> |
| 144 | + |
| 145 | +<QRCode |
| 146 | + content="https://example.com" |
| 147 | + linearGradient={['rgb(255,0,0)', 'rgb(0,100,255)']} |
| 148 | + gradientDirection={[0, 170, 0, 0]} |
| 149 | +/> |
90 | 150 | ``` |
91 | | -<img src='./assets/example-linear-gradient.png' height='250'/> |
92 | 151 |
|
93 | | -### backgroundImage |
94 | | -```jsx |
95 | | -<QRCode backgroundImage={require('./galaxy.png')} /> |
| 152 | +<img src="./assets/example-linear-gradient.png" height="220" /> |
| 153 | + |
| 154 | +### Background image |
| 155 | + |
| 156 | +Eye styling is not available when using `backgroundImage`: |
| 157 | + |
| 158 | +```tsx |
| 159 | +<QRCode |
| 160 | + content="https://example.com" |
| 161 | + backgroundImage={require('./texture.png')} |
| 162 | + ecl="H" |
| 163 | +/> |
96 | 164 | ``` |
97 | | -<img src='./assets/example-background-image.png' height='250'/> |
98 | 165 |
|
99 | | -## Contributing |
| 166 | +<img src="./assets/example-background-image.png" height="220" /> |
| 167 | + |
| 168 | +### RTL support |
| 169 | + |
| 170 | +```tsx |
| 171 | +<QRCode |
| 172 | + content="https://example.com" |
| 173 | + isRTL={true} |
| 174 | +/> |
| 175 | +``` |
100 | 176 |
|
101 | | -Take a look at [CONTRIBUTING.md](./CONTRIBUTING.md) 😁 |
| 177 | +--- |
102 | 178 |
|
103 | 179 | ## License |
104 | 180 |
|
105 | | -[MIT License](http://opensource.org/licenses/mit-license.html). © Geoffrey Natin 2017 |
| 181 | +MIT © [Oguzhan Atalay](https://github.com/oguzhnatly) |
0 commit comments