@oguzhnatly/react-native-custom-qr-codes 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ /*
2
+
3
+ circle.js
4
+
5
+ This file exports a function for drawing a circle centre piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React from "react";
11
+ import { Circle } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'circle' codeStyle
14
+ export function drawCirclePiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize + xsize / 2;
21
+ var py = y * ysize + ysize / 2;
22
+ return (
23
+ <Circle
24
+ key={px + ":" + py}
25
+ cx={px}
26
+ cy={py}
27
+ r={xsize / 2}
28
+ fill={props.color}
29
+ />
30
+ );
31
+ }
@@ -0,0 +1,35 @@
1
+ /*
2
+
3
+ diamond.js
4
+
5
+ This file exports a function for drawing a diamond centre piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React from "react";
11
+ import { G, Rect } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'diamond' codeStyle
14
+ export function drawDiamondPiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize;
21
+ var py = y * ysize;
22
+ return (
23
+ <G x={px + xsize / 2} y={py + ysize / 2} width={xsize} height={ysize}>
24
+ <Rect
25
+ key={px + ":" + py}
26
+ x={-xsize / 2}
27
+ y={-ysize / 2}
28
+ width={xsize}
29
+ height={ysize}
30
+ rotate={45}
31
+ fill={props.color}
32
+ />
33
+ </G>
34
+ );
35
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+
3
+ dot.js
4
+
5
+ This file exports a function for drawing a dot centre piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React from "react";
11
+ import { Circle } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'dot' codeStyle
14
+ export function drawDotPiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize + xsize / 2;
21
+ var py = y * ysize + ysize / 2;
22
+ return (
23
+ <Circle
24
+ key={px + ":" + py}
25
+ cx={px}
26
+ cy={py}
27
+ r={xsize / 3}
28
+ fill={props.color}
29
+ />
30
+ );
31
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+
3
+ index.js
4
+
5
+ This file exports a function for drawing the centre pieces of a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+
11
+ import { drawSquarePiece } from './square';
12
+ import { drawCirclePiece } from './circle';
13
+ import { drawDotPiece } from './dot';
14
+ import { drawDiamondPiece } from './diamond';
15
+ import { drawSharpPiece } from './sharp';
16
+ import { drawNinjaPiece } from './ninja';
17
+
18
+ //Returns an SVG Element for a centre piece in the style of the codeStyle
19
+ export function drawCentrePiece(x,y,modules,pieceProperties,props){
20
+ switch(props.codeStyle){
21
+ case 'square':
22
+ return drawSquarePiece(x,y,modules,pieceProperties,props);
23
+ case 'circle':
24
+ return drawCirclePiece(x,y,modules,pieceProperties,props);
25
+ case 'dot':
26
+ return drawDotPiece(x,y,modules,pieceProperties,props);
27
+ case 'diamond':
28
+ return drawDiamondPiece(x,y,modules,pieceProperties,props);
29
+ case 'sharp':
30
+ return drawSharpPiece(x,y,modules,pieceProperties,props);
31
+ case 'ninja':
32
+ return drawNinjaPiece(x,y,modules,pieceProperties,props);
33
+ default:
34
+ return drawSquarePiece(x,y,modules,pieceProperties,props);
35
+ }
36
+ }
@@ -0,0 +1,132 @@
1
+ /*
2
+
3
+ ninja.js
4
+
5
+ This file exports a function for drawing a ninja centre piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React from "react";
11
+ import { Rect } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'ninja' codeStyle
14
+ export function drawNinjaPiece(x, y, modules, pieceProperties, props) {
15
+ var orientation = pieceProperties.orientation;
16
+ var pieceType = pieceProperties.pieceType;
17
+ var width = props.size;
18
+ var height = props.size;
19
+ var length = modules.length;
20
+ var xsize = width / length;
21
+ var ysize = height / length;
22
+ var px = x * xsize;
23
+ var py = y * ysize;
24
+
25
+ // !!!! These aren't the proper paths yet
26
+ switch (pieceType) {
27
+ case "2b":
28
+ return (
29
+ <Rect
30
+ x={-(xsize / 2)}
31
+ y={-(ysize / 2)}
32
+ originX={px + xsize / 2}
33
+ originY={py + ysize / 2}
34
+ rotate={orientation}
35
+ width={xsize}
36
+ height={ysize}
37
+ fill={props.color}
38
+ />
39
+ );
40
+ case "1b":
41
+ return (
42
+ <Rect
43
+ x={-(xsize / 2)}
44
+ y={-(ysize / 2)}
45
+ originX={px + xsize / 2}
46
+ originY={py + ysize / 2}
47
+ rotate={orientation}
48
+ width={xsize}
49
+ height={ysize}
50
+ fill={props.color}
51
+ />
52
+ );
53
+ case "1b3b":
54
+ return (
55
+ <Rect
56
+ x={-(xsize / 2)}
57
+ y={-(ysize / 2)}
58
+ originX={px + xsize / 2}
59
+ originY={py + ysize / 2}
60
+ rotate={orientation}
61
+ width={xsize}
62
+ height={ysize}
63
+ fill={props.color}
64
+ />
65
+ );
66
+ case "2a1b":
67
+ return (
68
+ <Rect
69
+ x={-(xsize / 2)}
70
+ y={-(ysize / 2)}
71
+ originX={px + xsize / 2}
72
+ originY={py + ysize / 2}
73
+ rotate={orientation}
74
+ width={xsize}
75
+ height={ysize}
76
+ fill={props.color}
77
+ />
78
+ );
79
+ case "2a1b1a":
80
+ return (
81
+ <Rect
82
+ x={-(xsize / 2)}
83
+ y={-(ysize / 2)}
84
+ originX={px + xsize / 2}
85
+ originY={py + ysize / 2}
86
+ rotate={orientation}
87
+ width={xsize}
88
+ height={ysize}
89
+ fill={props.color}
90
+ />
91
+ );
92
+ case "2a1b2c":
93
+ return (
94
+ <Rect
95
+ x={-(xsize / 2)}
96
+ y={-(ysize / 2)}
97
+ originX={px + xsize / 2}
98
+ originY={py + ysize / 2}
99
+ rotate={orientation}
100
+ width={xsize}
101
+ height={ysize}
102
+ fill={props.color}
103
+ />
104
+ );
105
+ case "2a1b2c3b":
106
+ return (
107
+ <Rect
108
+ x={-(xsize / 2)}
109
+ y={-(ysize / 2)}
110
+ originX={px + xsize / 2}
111
+ originY={py + ysize / 2}
112
+ rotate={orientation}
113
+ width={xsize}
114
+ height={ysize}
115
+ fill={props.color}
116
+ />
117
+ );
118
+ default:
119
+ return (
120
+ <Rect
121
+ x={-(xsize / 2)}
122
+ y={-(ysize / 2)}
123
+ originX={px + xsize / 2}
124
+ originY={py + ysize / 2}
125
+ rotate={orientation}
126
+ width={xsize}
127
+ height={ysize}
128
+ fill={props.color}
129
+ />
130
+ );
131
+ }
132
+ }
@@ -0,0 +1,118 @@
1
+ /*
2
+
3
+ sharp.js
4
+
5
+ This file exports a function for drawing a sharp centre piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React from "react";
11
+ import { Circle, Rect } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'sharp' codeStyle
14
+ export function drawSharpPiece(x, y, modules, pieceProperties, props) {
15
+ var orientation = pieceProperties.orientation;
16
+ var pieceType = pieceProperties.pieceType;
17
+ var width = props.size;
18
+ var height = props.size;
19
+ var length = modules.length;
20
+ var xsize = width / length;
21
+ var ysize = height / length;
22
+ var px = x * xsize;
23
+ var py = y * ysize;
24
+
25
+ // !!!! These aren't the proper paths yet
26
+ var str = xsize + "," + 0 + " " + xsize + "," + ysize + " " + 0 + "," + ysize;
27
+ var rotationStr = orientation + ", " + xsize / 2 + ", " + ysize / 2;
28
+
29
+ switch (pieceType) {
30
+ case "1a":
31
+ return (
32
+ <Circle
33
+ key={px + ":" + py}
34
+ cx={px + xsize / 2}
35
+ cy={py + ysize / 2}
36
+ r={xsize / 2}
37
+ fill={props.color}
38
+ />
39
+ );
40
+ case "2b":
41
+ return (
42
+ <Rect
43
+ key={px + ":" + py}
44
+ x={px}
45
+ y={py}
46
+ width={xsize}
47
+ height={ysize}
48
+ fill={props.color}
49
+ />
50
+ );
51
+ case "1b3b":
52
+ return (
53
+ <Rect
54
+ key={px + ":" + py}
55
+ x={px}
56
+ y={py}
57
+ width={xsize}
58
+ height={ysize}
59
+ fill={props.color}
60
+ />
61
+ );
62
+ case "2a1b":
63
+ return (
64
+ <Rect
65
+ key={px + ":" + py}
66
+ x={px}
67
+ y={py}
68
+ width={xsize}
69
+ height={ysize}
70
+ fill={props.color}
71
+ />
72
+ );
73
+ case "2a1b1a":
74
+ return (
75
+ <Rect
76
+ key={px + ":" + py}
77
+ x={px}
78
+ y={py}
79
+ width={xsize}
80
+ height={ysize}
81
+ fill={props.color}
82
+ />
83
+ );
84
+ case "2a1b2c":
85
+ return (
86
+ <Rect
87
+ key={px + ":" + py}
88
+ x={px}
89
+ y={py}
90
+ width={xsize}
91
+ height={ysize}
92
+ fill={props.color}
93
+ />
94
+ );
95
+ case "2a1b2c3b":
96
+ return (
97
+ <Rect
98
+ key={px + ":" + py}
99
+ x={px}
100
+ y={py}
101
+ width={xsize}
102
+ height={ysize}
103
+ fill={props.color}
104
+ />
105
+ );
106
+ default:
107
+ return (
108
+ <Rect
109
+ key={px + ":" + py}
110
+ x={px}
111
+ y={py}
112
+ width={xsize}
113
+ height={ysize}
114
+ fill={props.color}
115
+ />
116
+ );
117
+ }
118
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+
3
+ square.js
4
+
5
+ This file exports a function for drawing a square centre piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React from "react";
11
+ import { Rect } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'square' codeStyle
14
+ export function drawSquarePiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize;
21
+ var py = y * ysize;
22
+ return (
23
+ <Rect
24
+ key={px + ":" + py}
25
+ x={px}
26
+ y={py}
27
+ width={xsize}
28
+ height={ysize}
29
+ fill={props.color}
30
+ />
31
+ );
32
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+
3
+ index.js
4
+
5
+ This file exports a function for drawing a piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+
11
+ import { drawOuterEyePiece } from './outerEyeStyles';
12
+ import { drawInnerEyePiece } from './innerEyeStyles';
13
+ import { drawCentrePiece } from './codeStyles';
14
+
15
+ //Returns an SVG Element for a piece in the style of the codeStyle
16
+ export function drawPiece(x,y,modules,pieceProperties,props){
17
+
18
+ //Check the QR Code the piece is a part of: Centre, Inner Eye, or Outer Eye
19
+ var length = modules.length;
20
+
21
+ if( //If in the corners of the QR Code
22
+ (x<7 && y<7) ||
23
+ (x<7 && (length-y)<8) ||
24
+ ((length-x)<8 && y<7)
25
+ ){
26
+ if(//If part of the Outer Eye
27
+ x==0 ||
28
+ y==0 ||
29
+ x==6 ||
30
+ y==6 ||
31
+ x==(length-1) ||
32
+ y==(length-1) ||
33
+ (length-y)==7 ||
34
+ (length-x)==7
35
+ ){
36
+ return drawOuterEyePiece(x,y,modules,pieceProperties,props);
37
+ }
38
+ else{//If part of Inner Eye
39
+ return drawInnerEyePiece(x,y,modules,pieceProperties,props);
40
+ }
41
+ }
42
+ else{
43
+ return drawCentrePiece(x,y,modules,pieceProperties,props);
44
+ }
45
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+
3
+ circle.js
4
+
5
+ This file exports a function for drawing a circle outer eye piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React, { Component } from "react";
11
+ import Svg, { Circle } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'circle' outerEyeStyle
14
+ export function drawCirclesPiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize + xsize / 2;
21
+ var py = y * ysize + ysize / 2;
22
+ return (
23
+ <Circle
24
+ key={px + ":" + py}
25
+ cx={px}
26
+ cy={py}
27
+ r={xsize / 2}
28
+ fill={props.color}
29
+ />
30
+ );
31
+ }
@@ -0,0 +1,35 @@
1
+ /*
2
+
3
+ diamond.js
4
+
5
+ This file exports a function for drawing a diamond outer eye piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React, { Component } from "react";
11
+ import Svg, { G, Rect } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'diamond' outerEyeStyle
14
+ export function drawDiamondPiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize;
21
+ var py = y * ysize;
22
+ return (
23
+ <G x={px + xsize / 2} y={py + ysize / 2} width={xsize} height={ysize}>
24
+ <Rect
25
+ key={px + ":" + py}
26
+ x={-xsize / 2}
27
+ y={-ysize / 2}
28
+ width={xsize}
29
+ height={ysize}
30
+ rotate={45}
31
+ fill={props.color}
32
+ />
33
+ </G>
34
+ );
35
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+
3
+ index.js
4
+
5
+ This file exports a function for drawing the inner eye pieces of a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+
11
+ import { drawCirclesPiece } from "./circle";
12
+ import { drawDiamondPiece } from "./diamond";
13
+ import { drawNone } from "./none";
14
+ import { drawSquarePiece } from "./square";
15
+
16
+ //Returns an SVG Element for an outer eye piece in the style of the innerEyeStyle
17
+ export function drawInnerEyePiece(x, y, modules, pieceProperties, props) {
18
+ switch (props.innerEyeStyle) {
19
+ case "square":
20
+ return drawSquarePiece(x, y, modules, pieceProperties, props);
21
+ case "circles":
22
+ return drawCirclesPiece(x, y, modules, pieceProperties, props);
23
+ case "diamond":
24
+ return drawDiamondPiece(x, y, modules, pieceProperties, props);
25
+ case "circle":
26
+ case "rounded":
27
+ return drawNone(x, y, modules, pieceProperties, props);
28
+ default:
29
+ return drawSquarePiece(x, y, modules, pieceProperties, props);
30
+ }
31
+ }
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+
3
+ import { View } from "react-native";
4
+
5
+ //Returns an SVG Element for a piece of the 'circle' outerEyeStyle
6
+ export function drawNone(x, y, modules, pieceProperties, props) {
7
+ return <View key={x + ":" + y} />;
8
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+
3
+ square.js
4
+
5
+ This file exports a function for drawing a square outer eye piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React, { Component } from "react";
11
+ import Svg, { Rect } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'square' outerEyeStyle
14
+ export function drawSquarePiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize;
21
+ var py = y * ysize;
22
+ return (
23
+ <Rect
24
+ key={px + ":" + py}
25
+ x={px}
26
+ y={py}
27
+ width={xsize}
28
+ height={ysize}
29
+ fill={props.color}
30
+ />
31
+ );
32
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+
3
+ circle.js
4
+
5
+ This file exports a function for drawing a circle outer eye piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React, { Component } from "react";
11
+ import Svg, { Circle } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'circle' outerEyeStyle
14
+ export function drawCirclesPiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize + xsize / 2;
21
+ var py = y * ysize + ysize / 2;
22
+ return (
23
+ <Circle
24
+ key={px + ":" + py}
25
+ cx={px}
26
+ cy={py}
27
+ r={xsize / 2}
28
+ fill={props.color}
29
+ />
30
+ );
31
+ }
@@ -0,0 +1,35 @@
1
+ /*
2
+
3
+ diamond.js
4
+
5
+ This file exports a function for drawing a diamond outer eye piece for a QRCode
6
+
7
+ --Geoff Natin 11/1/18 17:41
8
+
9
+ */
10
+ import React, { Component } from "react";
11
+ import Svg, { G, Rect } from "react-native-svg";
12
+
13
+ //Returns an SVG Element for a piece of the 'diamond' outerEyeStyle
14
+ export function drawDiamondPiece(x, y, modules, pieceProperties, props) {
15
+ var length = modules.length;
16
+ var width = props.size;
17
+ var height = props.size;
18
+ var xsize = width / length;
19
+ var ysize = height / length;
20
+ var px = x * xsize;
21
+ var py = y * ysize;
22
+ return (
23
+ <G x={px + xsize / 2} y={py + ysize / 2} width={xsize} height={ysize}>
24
+ <Rect
25
+ key={px + ":" + py}
26
+ x={-xsize / 2}
27
+ y={-ysize / 2}
28
+ width={xsize}
29
+ height={ysize}
30
+ rotate={45}
31
+ fill={props.color}
32
+ />
33
+ </G>
34
+ );
35
+ }