react-native-qrcode-svg 6.3.2 → 6.3.12

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.
Files changed (91) hide show
  1. package/Example/.bundle/config +2 -0
  2. package/Example/.eslintrc.js +4 -0
  3. package/Example/.prettierrc.js +7 -0
  4. package/Example/.watchmanconfig +1 -0
  5. package/Example/Gemfile +9 -0
  6. package/Example/Gemfile.lock +103 -0
  7. package/Example/README.md +48 -0
  8. package/Example/__tests__/App.test.tsx +17 -0
  9. package/Example/android/app/build.gradle +119 -0
  10. package/Example/android/app/debug.keystore +0 -0
  11. package/Example/android/app/proguard-rules.pro +10 -0
  12. package/Example/android/app/src/debug/AndroidManifest.xml +9 -0
  13. package/Example/android/app/src/main/AndroidManifest.xml +25 -0
  14. package/Example/android/app/src/main/java/com/example/MainActivity.kt +22 -0
  15. package/Example/android/app/src/main/java/com/example/MainApplication.kt +45 -0
  16. package/Example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  17. package/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  18. package/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  19. package/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  20. package/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  21. package/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  22. package/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  23. package/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  24. package/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  25. package/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  26. package/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  27. package/Example/android/app/src/main/res/values/strings.xml +3 -0
  28. package/Example/android/app/src/main/res/values/styles.xml +9 -0
  29. package/Example/android/build.gradle +21 -0
  30. package/Example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  31. package/Example/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  32. package/Example/android/gradle.properties +41 -0
  33. package/Example/android/gradlew +249 -0
  34. package/Example/android/gradlew.bat +92 -0
  35. package/Example/android/settings.gradle +4 -0
  36. package/Example/app.json +4 -0
  37. package/Example/babel.config.js +4 -0
  38. package/Example/dist/index.html +24 -0
  39. package/Example/global.d.ts +7 -0
  40. package/Example/index.js +14 -0
  41. package/Example/ios/.xcode.env +11 -0
  42. package/Example/ios/Example/AppDelegate.h +6 -0
  43. package/Example/ios/Example/AppDelegate.mm +31 -0
  44. package/Example/ios/Example/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  45. package/Example/ios/Example/Images.xcassets/Contents.json +6 -0
  46. package/Example/ios/Example/Info.plist +52 -0
  47. package/Example/ios/Example/LaunchScreen.storyboard +47 -0
  48. package/Example/ios/Example/main.m +10 -0
  49. package/Example/ios/Example.xcodeproj/project.pbxproj +698 -0
  50. package/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme +88 -0
  51. package/Example/ios/Example.xcworkspace/contents.xcworkspacedata +10 -0
  52. package/Example/ios/ExampleTests/ExampleTests.m +66 -0
  53. package/Example/ios/ExampleTests/Info.plist +24 -0
  54. package/Example/ios/Podfile +55 -0
  55. package/Example/ios/Podfile.lock +1378 -0
  56. package/Example/jest.config.js +3 -0
  57. package/Example/macos/.xcode.env +1 -0
  58. package/Example/macos/.xcode.env.local +2 -0
  59. package/Example/macos/Example-macOS/AppDelegate.h +6 -0
  60. package/Example/macos/Example-macOS/AppDelegate.mm +40 -0
  61. package/Example/macos/Example-macOS/Assets.xcassets/AppIcon.appiconset/Contents.json +58 -0
  62. package/Example/macos/Example-macOS/Assets.xcassets/Contents.json +6 -0
  63. package/Example/macos/Example-macOS/Base.lproj/Main.storyboard +684 -0
  64. package/Example/macos/Example-macOS/Example.entitlements +12 -0
  65. package/Example/macos/Example-macOS/Info.plist +47 -0
  66. package/Example/macos/Example-macOS/main.m +5 -0
  67. package/Example/macos/Example.xcodeproj/project.pbxproj +567 -0
  68. package/Example/macos/Example.xcodeproj/xcshareddata/xcschemes/Example-macOS.xcscheme +78 -0
  69. package/Example/macos/Example.xcworkspace/contents.xcworkspacedata +10 -0
  70. package/Example/macos/Podfile +26 -0
  71. package/Example/macos/Podfile.lock +1233 -0
  72. package/Example/metro.config.js +47 -0
  73. package/Example/package.json +53 -0
  74. package/Example/src/App.tsx +130 -0
  75. package/Example/src/assets/google.png +0 -0
  76. package/Example/src/assets/ruby.svg +12 -0
  77. package/Example/src/components/Description.tsx +16 -0
  78. package/Example/src/styles.ts +21 -0
  79. package/Example/tsconfig.json +9 -0
  80. package/Example/webpack.config.js +60 -0
  81. package/Example/yarn.lock +8957 -0
  82. package/README.md +0 -6
  83. package/index.d.ts +10 -2
  84. package/package.json +11 -2
  85. package/src/LogoSVG/index.js +22 -0
  86. package/src/LogoSVG/index.native.js +24 -0
  87. package/src/index.js +158 -125
  88. package/src/utils.js +7 -0
  89. package/.github/workflows/npmpublish.yml +0 -31
  90. package/.huskyrc +0 -5
  91. package/.lintstagedrc +0 -3
package/README.md CHANGED
@@ -164,9 +164,3 @@ import RNFS from "react-native-fs"
164
164
  ### Dependencies
165
165
 
166
166
  * [node-qrcode](https://github.com/soldair/node-qrcode)
167
-
168
- ---
169
-
170
- If you like this project, please consider buy me a coffee :)
171
-
172
- https://www.buymeacoffee.com/LquC7mid5
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as React from "react";
2
- import { Image, ImageSourcePropType } from "react-native";
2
+ import type {ImageSourcePropType} from "react-native";
3
+ import type {SvgProps} from "react-native-svg";
3
4
 
4
5
  declare class QRCode extends React.PureComponent<QRCodeProps, any> {}
5
6
 
@@ -12,13 +13,20 @@ export interface QRCodeProps {
12
13
  color?: string;
13
14
  /* the color of the background */
14
15
  backgroundColor?: string;
16
+ /* SVG to render as logo.
17
+ * Can be either a svg string or a React component if you're using ex: '@svgr/webpack' or similar
18
+ * In case both this prop and `logo` are provided, then this prop takes precedence and `logo` will be ignored. */
19
+ logoSVG?: React.FC<SvgProps> | string;
15
20
  /* an image source object. example {uri: 'base64string'} or {require('pathToImage')} */
16
- logo?: ImageSourcePropType;
21
+ logo?: ImageSourcePropType | string;
17
22
  /* logo size in pixels */
18
23
  logoSize?: number;
19
24
  /* the logo gets a filled rectangular background with this color. Use 'transparent'
20
25
  if your logo already has its own backdrop. Default = same as backgroundColor */
21
26
  logoBackgroundColor?: string;
27
+ /* If the logo is provided via `logoSVG` prop, this color will be set as it's `fill` property,
28
+ * otherwise it does nothing */
29
+ logoColor?: string;
22
30
  /* logo's distance to its wrapper */
23
31
  logoMargin?: number;
24
32
  /* the border-radius of logo image */
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "react-native-qrcode-svg",
3
- "version": "6.3.2",
3
+ "version": "6.3.12",
4
4
  "description": "A QR Code generator for React Native based on react-native-svg and javascript-qrcode.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
- "prepare": "rm -rf example",
8
+ "prepack": "rm -rf example",
9
9
  "test": "jest",
10
10
  "test:update": "npm run test -- --updateSnapshot",
11
11
  "lint": "standard 'src/**/*.js'",
@@ -30,6 +30,14 @@
30
30
  "type": "git",
31
31
  "url": "git+ssh://git@github.com/awesomejerry/react-native-qrcode-svg.git"
32
32
  },
33
+ "files": [
34
+ "Example",
35
+ "screenshot",
36
+ "src",
37
+ "babel.config.js",
38
+ "index.d.ts",
39
+ "index.js"
40
+ ],
33
41
  "keywords": [
34
42
  "react-native",
35
43
  "qrcode",
@@ -52,6 +60,7 @@
52
60
  "text-encoding": "^0.7.0"
53
61
  },
54
62
  "devDependencies": {
63
+ "@types/react": "^18.2.75",
55
64
  "babel-eslint": "^10.1.0",
56
65
  "babel-jest": "^27.4.2",
57
66
  "husky": "^7.0.4",
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { Image } from "react-native-svg";
3
+ import { isString, isUrlString } from "../utils";
4
+
5
+ const LogoSVG = ({ svg, logoSize, logoColor }) => {
6
+ if (isString(svg)) {
7
+ const href = isUrlString(svg)
8
+ ? svg
9
+ : `data:image/svg+xml;base64,${window.btoa(svg)}`;
10
+
11
+ return <Image href={encodeURI(href)} width={logoSize} height={logoSize} />;
12
+ }
13
+
14
+ // if `svg` prop is actually a svg asset wrapped in a React component, then we can just render it
15
+ const LogoSVGComponent = svg;
16
+
17
+ return (
18
+ <LogoSVGComponent fill={logoColor} width={logoSize} height={logoSize} />
19
+ );
20
+ };
21
+
22
+ export default LogoSVG;
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import { LocalSvg } from "react-native-svg/css";
3
+ import { SvgUri, SvgXml } from "react-native-svg";
4
+ import { isString, isUrlString } from "../utils";
5
+
6
+ const LogoSVG = ({ svg, logoSize, logoColor }) => {
7
+ if (isString(svg)) {
8
+ if (isUrlString(svg)) {
9
+ return (
10
+ <SvgUri uri={svg} fill={logoColor} width={logoSize} height={logoSize} />
11
+ );
12
+ }
13
+
14
+ return (
15
+ <SvgXml xml={svg} fill={logoColor} width={logoSize} height={logoSize} />
16
+ );
17
+ }
18
+
19
+ return (
20
+ <LocalSvg asset={svg} fill={logoColor} width={logoSize} height={logoSize} />
21
+ );
22
+ };
23
+
24
+ export default LogoSVG;
package/src/index.js CHANGED
@@ -1,150 +1,183 @@
1
- global.TextEncoder = require('text-encoding').TextEncoder;
1
+ global.TextEncoder = require("text-encoding").TextEncoder;
2
2
 
3
- import React, { useMemo } from 'react';
4
- import Svg, { Defs, G, Path, Rect, Image, ClipPath, LinearGradient, Stop } from 'react-native-svg';
5
- import genMatrix from './genMatrix';
6
- import transformMatrixIntoPath from './transformMatrixIntoPath';
3
+ import React, { useMemo } from "react";
4
+ import Svg, {
5
+ Defs,
6
+ G,
7
+ Path,
8
+ Rect,
9
+ Image,
10
+ ClipPath,
11
+ LinearGradient,
12
+ Stop,
13
+ } from "react-native-svg";
14
+ import genMatrix from "./genMatrix";
15
+ import transformMatrixIntoPath from "./transformMatrixIntoPath";
16
+ import LogoSVG from "./LogoSVG";
7
17
 
8
18
  const renderLogo = ({
9
- size,
10
- logo,
11
- logoSize,
12
- logoBackgroundColor,
13
- logoMargin,
14
- logoBorderRadius,
19
+ size,
20
+ backgroundColor,
21
+ logo,
22
+ logoSVG,
23
+ logoSize,
24
+ logoBackgroundColor,
25
+ logoColor,
26
+ logoMargin,
27
+ logoBorderRadius,
15
28
  }) => {
16
- const logoPosition = (size - logoSize - logoMargin * 2) / 2;
17
- const logoBackgroundSize = logoSize + logoMargin * 2;
18
- const logoBackgroundBorderRadius =
19
- logoBorderRadius + (logoMargin / logoSize) * logoBorderRadius;
29
+ const logoPosition = (size - logoSize - logoMargin * 2) / 2;
30
+ const logoBackgroundSize = logoSize + logoMargin * 2;
31
+ const logoBackgroundBorderRadius =
32
+ logoBorderRadius + (logoMargin / logoSize) * logoBorderRadius;
20
33
 
21
- return (
22
- <G x={logoPosition} y={logoPosition}>
23
- <Defs>
24
- <ClipPath id='clip-logo-background'>
25
- <Rect
26
- width={logoBackgroundSize}
27
- height={logoBackgroundSize}
28
- rx={logoBackgroundBorderRadius}
29
- ry={logoBackgroundBorderRadius}
30
- />
31
- </ClipPath>
32
- <ClipPath id='clip-logo'>
33
- <Rect
34
- width={logoSize}
35
- height={logoSize}
36
- rx={logoBorderRadius}
37
- ry={logoBorderRadius}
38
- />
39
- </ClipPath>
40
- </Defs>
41
- <G>
42
- <Rect
43
- width={logoBackgroundSize}
44
- height={logoBackgroundSize}
45
- fill={logoBackgroundColor}
46
- clipPath='url(#clip-logo-background)'
47
- />
48
- </G>
49
- <G x={logoMargin} y={logoMargin}>
50
- <Image
51
- width={logoSize}
52
- height={logoSize}
53
- preserveAspectRatio='xMidYMid slice'
54
- href={logo}
55
- clipPath='url(#clip-logo)'
56
- />
57
- </G>
58
- </G>
59
- );
34
+ return (
35
+ <G x={logoPosition} y={logoPosition}>
36
+ <Defs>
37
+ <ClipPath id="clip-logo-background">
38
+ <Rect
39
+ width={logoBackgroundSize}
40
+ height={logoBackgroundSize}
41
+ rx={logoBackgroundBorderRadius}
42
+ ry={logoBackgroundBorderRadius}
43
+ />
44
+ </ClipPath>
45
+ <ClipPath id="clip-logo">
46
+ <Rect
47
+ width={logoSize}
48
+ height={logoSize}
49
+ rx={logoBorderRadius}
50
+ ry={logoBorderRadius}
51
+ />
52
+ </ClipPath>
53
+ </Defs>
54
+ <G>
55
+ <Rect
56
+ width={logoBackgroundSize}
57
+ height={logoBackgroundSize}
58
+ fill={backgroundColor}
59
+ clipPath="url(#clip-logo-background)"
60
+ />
61
+ </G>
62
+ <G x={logoMargin} y={logoMargin} clipPath="url(#clip-logo)">
63
+ <Rect
64
+ width={logoBackgroundSize - logoMargin}
65
+ height={logoBackgroundSize - logoMargin}
66
+ fill={logoBackgroundColor}
67
+ />
68
+ {logoSVG ? (
69
+ <LogoSVG svg={logoSVG} logoSize={logoSize} logoColor={logoColor} />
70
+ ) : (
71
+ <Image
72
+ width={logoSize}
73
+ height={logoSize}
74
+ preserveAspectRatio="xMidYMid slice"
75
+ href={logo}
76
+ clipPath="url(#clip-logo)"
77
+ />
78
+ )}
79
+ </G>
80
+ </G>
81
+ );
60
82
  };
61
83
 
62
84
  const QRCode = ({
63
- value = 'this is a QR code',
85
+ value = "this is a QR code",
64
86
  size = 100,
65
- color = 'black',
66
- backgroundColor = 'white',
87
+ color = "black",
88
+ backgroundColor = "white",
67
89
  logo,
90
+ logoSVG,
68
91
  logoSize = size * 0.2,
69
- logoBackgroundColor = 'transparent',
92
+ logoBackgroundColor = "transparent",
93
+ logoColor,
70
94
  logoMargin = 2,
71
95
  logoBorderRadius = 0,
72
96
  quietZone = 0,
73
97
  enableLinearGradient = false,
74
- gradientDirection = ['0%', '0%', '100%', '100%'],
75
- linearGradient = ['rgb(255,0,0)', 'rgb(0,255,255)'],
76
- ecl = 'M',
98
+ gradientDirection = ["0%", "0%", "100%", "100%"],
99
+ linearGradient = ["rgb(255,0,0)", "rgb(0,255,255)"],
100
+ ecl = "M",
77
101
  getRef,
78
102
  onError,
79
- testID
103
+ testID,
80
104
  }) => {
81
- const result = useMemo(() => {
82
- try {
83
- return transformMatrixIntoPath(genMatrix(value, ecl), size);
84
- } catch (error) {
85
- if (onError && typeof onError === 'function') {
86
- onError(error);
87
- } else {
88
- // Pass the error when no handler presented
89
- throw error;
90
- }
91
- }
92
- }, [value, size, ecl]);
93
-
94
- if (!result) {
95
- return null;
105
+ const result = useMemo(() => {
106
+ try {
107
+ return transformMatrixIntoPath(genMatrix(value, ecl), size);
108
+ } catch (error) {
109
+ if (onError && typeof onError === "function") {
110
+ onError(error);
111
+ } else {
112
+ // Pass the error when no handler presented
113
+ throw error;
114
+ }
96
115
  }
116
+ }, [value, size, ecl]);
117
+
118
+ if (!result) {
119
+ return null;
120
+ }
97
121
 
98
- const { path, cellSize } = result;
122
+ const { path, cellSize } = result;
123
+ const displayLogo = logo || logoSVG;
99
124
 
100
- return (
101
- <Svg
102
- testID={testID}
103
- ref={getRef}
104
- viewBox={[-quietZone, -quietZone, size + quietZone * 2, size + quietZone * 2].join(' ')}
105
- width={size}
106
- height={size}
125
+ return (
126
+ <Svg
127
+ testID={testID}
128
+ ref={getRef}
129
+ viewBox={[
130
+ -quietZone,
131
+ -quietZone,
132
+ size + quietZone * 2,
133
+ size + quietZone * 2,
134
+ ].join(" ")}
135
+ width={size}
136
+ height={size}
137
+ >
138
+ <Defs>
139
+ <LinearGradient
140
+ id="grad"
141
+ x1={gradientDirection[0]}
142
+ y1={gradientDirection[1]}
143
+ x2={gradientDirection[2]}
144
+ y2={gradientDirection[3]}
107
145
  >
108
- <Defs>
109
- <LinearGradient
110
- id='grad'
111
- x1={gradientDirection[0]}
112
- y1={gradientDirection[1]}
113
- x2={gradientDirection[2]}
114
- y2={gradientDirection[3]}
115
- >
116
- <Stop offset='0' stopColor={linearGradient[0]} stopOpacity='1' />
117
- <Stop offset='1' stopColor={linearGradient[1]} stopOpacity='1' />
118
- </LinearGradient>
119
- </Defs>
120
- <G>
121
- <Rect
122
- x={-quietZone}
123
- y={-quietZone}
124
- width={size + quietZone * 2}
125
- height={size + quietZone * 2}
126
- fill={backgroundColor}
127
- />
128
- </G>
129
- <G>
130
- <Path
131
- d={path}
132
- strokeLinecap='butt'
133
- stroke={enableLinearGradient ? 'url(#grad)' : color}
134
- strokeWidth={cellSize}
135
- />
136
- </G>
137
- {logo &&
138
- renderLogo({
139
- size,
140
- logo,
141
- logoSize,
142
- logoBackgroundColor,
143
- logoMargin,
144
- logoBorderRadius,
145
- })}
146
- </Svg>
147
- );
146
+ <Stop offset="0" stopColor={linearGradient[0]} stopOpacity="1" />
147
+ <Stop offset="1" stopColor={linearGradient[1]} stopOpacity="1" />
148
+ </LinearGradient>
149
+ </Defs>
150
+ <G>
151
+ <Rect
152
+ x={-quietZone}
153
+ y={-quietZone}
154
+ width={size + quietZone * 2}
155
+ height={size + quietZone * 2}
156
+ fill={backgroundColor}
157
+ />
158
+ </G>
159
+ <G>
160
+ <Path
161
+ d={path}
162
+ strokeLinecap="butt"
163
+ stroke={enableLinearGradient ? "url(#grad)" : color}
164
+ strokeWidth={cellSize}
165
+ />
166
+ </G>
167
+ {displayLogo &&
168
+ renderLogo({
169
+ size,
170
+ backgroundColor,
171
+ logo,
172
+ logoSVG,
173
+ logoSize,
174
+ logoBackgroundColor,
175
+ logoColor,
176
+ logoMargin,
177
+ logoBorderRadius,
178
+ })}
179
+ </Svg>
180
+ );
148
181
  };
149
182
 
150
183
  export default QRCode;
package/src/utils.js ADDED
@@ -0,0 +1,7 @@
1
+ export function isString(variable) {
2
+ return typeof variable === "string";
3
+ }
4
+
5
+ export function isUrlString(variable) {
6
+ return isString(variable) && variable.startsWith("http");
7
+ }
@@ -1,31 +0,0 @@
1
- name: Node.js Package
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- jobs:
9
- build:
10
- runs-on: ubuntu-latest
11
- steps:
12
- - uses: actions/checkout@v1
13
- - uses: actions/setup-node@v1
14
- with:
15
- node-version: 12
16
- - run: npm ci
17
- - run: npm test
18
-
19
- publish-npm:
20
- needs: build
21
- runs-on: ubuntu-latest
22
- steps:
23
- - uses: actions/checkout@v1
24
- - uses: actions/setup-node@v1
25
- with:
26
- node-version: 12
27
- registry-url: https://registry.npmjs.org/
28
- - run: npm ci
29
- - run: npm publish
30
- env:
31
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/.huskyrc DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "hooks": {
3
- "pre-commit": "npm run lint:staged && npm run test"
4
- }
5
- }
package/.lintstagedrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "*.js": "npm run lint"
3
- }