react-native-qrcode-svg 6.3.1 → 6.3.11

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 +12 -2
  84. package/package.json +14 -4
  85. package/src/LogoSVG/index.js +22 -0
  86. package/src/LogoSVG/index.native.js +24 -0
  87. package/src/index.js +72 -49
  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 */
@@ -37,6 +45,8 @@ export interface QRCodeProps {
37
45
  ecl?: "L" | "M" | "Q" | "H";
38
46
  /* error handler called when matrix fails to generate */
39
47
  onError?: Function;
48
+ /** testID for testing */
49
+ testID?: string;
40
50
  }
41
51
 
42
52
  export default QRCode;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "react-native-qrcode-svg",
3
- "version": "6.3.1",
3
+ "version": "6.3.11",
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",
@@ -42,15 +50,17 @@
42
50
  },
43
51
  "homepage": "https://github.com/awesomejerry/react-native-qrcode-svg#readme",
44
52
  "peerDependencies": {
45
- "react-native": ">=0.63.4",
46
53
  "react": "*",
54
+ "react-native": ">=0.63.4",
47
55
  "react-native-svg": ">=13.2.0"
48
56
  },
49
57
  "dependencies": {
50
58
  "prop-types": "^15.8.0",
51
- "qrcode": "^1.5.1"
59
+ "qrcode": "^1.5.1",
60
+ "text-encoding": "^0.7.0"
52
61
  },
53
62
  "devDependencies": {
63
+ "@types/react": "^18.2.75",
54
64
  "babel-eslint": "^10.1.0",
55
65
  "babel-jest": "^27.4.2",
56
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,4 +1,6 @@
1
- import React, { useMemo } from 'react'
1
+ global.TextEncoder = require("text-encoding").TextEncoder;
2
+
3
+ import React, { useMemo } from "react";
2
4
  import Svg, {
3
5
  Defs,
4
6
  G,
@@ -7,28 +9,32 @@ import Svg, {
7
9
  Image,
8
10
  ClipPath,
9
11
  LinearGradient,
10
- Stop
11
- } from 'react-native-svg'
12
- import genMatrix from './genMatrix'
13
- import transformMatrixIntoPath from './transformMatrixIntoPath'
12
+ Stop,
13
+ } from "react-native-svg";
14
+ import genMatrix from "./genMatrix";
15
+ import transformMatrixIntoPath from "./transformMatrixIntoPath";
16
+ import LogoSVG from "./LogoSVG";
14
17
 
15
18
  const renderLogo = ({
16
19
  size,
20
+ backgroundColor,
17
21
  logo,
22
+ logoSVG,
18
23
  logoSize,
19
24
  logoBackgroundColor,
25
+ logoColor,
20
26
  logoMargin,
21
- logoBorderRadius
27
+ logoBorderRadius,
22
28
  }) => {
23
- const logoPosition = (size - logoSize - logoMargin * 2) / 2
24
- const logoBackgroundSize = logoSize + logoMargin * 2
29
+ const logoPosition = (size - logoSize - logoMargin * 2) / 2;
30
+ const logoBackgroundSize = logoSize + logoMargin * 2;
25
31
  const logoBackgroundBorderRadius =
26
- logoBorderRadius + (logoMargin / logoSize) * logoBorderRadius
32
+ logoBorderRadius + (logoMargin / logoSize) * logoBorderRadius;
27
33
 
28
34
  return (
29
35
  <G x={logoPosition} y={logoPosition}>
30
36
  <Defs>
31
- <ClipPath id='clip-logo-background'>
37
+ <ClipPath id="clip-logo-background">
32
38
  <Rect
33
39
  width={logoBackgroundSize}
34
40
  height={logoBackgroundSize}
@@ -36,7 +42,7 @@ const renderLogo = ({
36
42
  ry={logoBackgroundBorderRadius}
37
43
  />
38
44
  </ClipPath>
39
- <ClipPath id='clip-logo'>
45
+ <ClipPath id="clip-logo">
40
46
  <Rect
41
47
  width={logoSize}
42
48
  height={logoSize}
@@ -49,82 +55,96 @@ const renderLogo = ({
49
55
  <Rect
50
56
  width={logoBackgroundSize}
51
57
  height={logoBackgroundSize}
52
- fill={logoBackgroundColor}
53
- clipPath='url(#clip-logo-background)'
58
+ fill={backgroundColor}
59
+ clipPath="url(#clip-logo-background)"
54
60
  />
55
61
  </G>
56
- <G x={logoMargin} y={logoMargin}>
57
- <Image
58
- width={logoSize}
59
- height={logoSize}
60
- preserveAspectRatio='xMidYMid slice'
61
- href={logo}
62
- clipPath='url(#clip-logo)'
62
+ <G x={logoMargin} y={logoMargin} clipPath="url(#clip-logo)">
63
+ <Rect
64
+ width={logoBackgroundSize - logoMargin}
65
+ height={logoBackgroundSize - logoMargin}
66
+ fill={logoBackgroundColor}
63
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
+ )}
64
79
  </G>
65
80
  </G>
66
- )
67
- }
81
+ );
82
+ };
68
83
 
69
84
  const QRCode = ({
70
- value = 'this is a QR code',
85
+ value = "this is a QR code",
71
86
  size = 100,
72
- color = 'black',
73
- backgroundColor = 'white',
87
+ color = "black",
88
+ backgroundColor = "white",
74
89
  logo,
90
+ logoSVG,
75
91
  logoSize = size * 0.2,
76
- logoBackgroundColor = 'transparent',
92
+ logoBackgroundColor = "transparent",
93
+ logoColor,
77
94
  logoMargin = 2,
78
95
  logoBorderRadius = 0,
79
96
  quietZone = 0,
80
97
  enableLinearGradient = false,
81
- gradientDirection = ['0%', '0%', '100%', '100%'],
82
- linearGradient = ['rgb(255,0,0)', 'rgb(0,255,255)'],
83
- ecl = 'M',
98
+ gradientDirection = ["0%", "0%", "100%", "100%"],
99
+ linearGradient = ["rgb(255,0,0)", "rgb(0,255,255)"],
100
+ ecl = "M",
84
101
  getRef,
85
- onError
102
+ onError,
103
+ testID,
86
104
  }) => {
87
105
  const result = useMemo(() => {
88
106
  try {
89
- return transformMatrixIntoPath(genMatrix(value, ecl), size)
107
+ return transformMatrixIntoPath(genMatrix(value, ecl), size);
90
108
  } catch (error) {
91
- if (onError && typeof onError === 'function') {
92
- onError(error)
109
+ if (onError && typeof onError === "function") {
110
+ onError(error);
93
111
  } else {
94
112
  // Pass the error when no handler presented
95
- throw error
113
+ throw error;
96
114
  }
97
115
  }
98
- }, [value, size, ecl])
116
+ }, [value, size, ecl]);
99
117
 
100
118
  if (!result) {
101
- return null
119
+ return null;
102
120
  }
103
121
 
104
- const { path, cellSize } = result
122
+ const { path, cellSize } = result;
123
+ const displayLogo = logo || logoSVG;
105
124
 
106
125
  return (
107
126
  <Svg
127
+ testID={testID}
108
128
  ref={getRef}
109
129
  viewBox={[
110
130
  -quietZone,
111
131
  -quietZone,
112
132
  size + quietZone * 2,
113
- size + quietZone * 2
114
- ].join(' ')}
133
+ size + quietZone * 2,
134
+ ].join(" ")}
115
135
  width={size}
116
136
  height={size}
117
137
  >
118
138
  <Defs>
119
139
  <LinearGradient
120
- id='grad'
140
+ id="grad"
121
141
  x1={gradientDirection[0]}
122
142
  y1={gradientDirection[1]}
123
143
  x2={gradientDirection[2]}
124
144
  y2={gradientDirection[3]}
125
145
  >
126
- <Stop offset='0' stopColor={linearGradient[0]} stopOpacity='1' />
127
- <Stop offset='1' stopColor={linearGradient[1]} stopOpacity='1' />
146
+ <Stop offset="0" stopColor={linearGradient[0]} stopOpacity="1" />
147
+ <Stop offset="1" stopColor={linearGradient[1]} stopOpacity="1" />
128
148
  </LinearGradient>
129
149
  </Defs>
130
150
  <G>
@@ -139,22 +159,25 @@ const QRCode = ({
139
159
  <G>
140
160
  <Path
141
161
  d={path}
142
- strokeLinecap='butt'
143
- stroke={enableLinearGradient ? 'url(#grad)' : color}
162
+ strokeLinecap="butt"
163
+ stroke={enableLinearGradient ? "url(#grad)" : color}
144
164
  strokeWidth={cellSize}
145
165
  />
146
166
  </G>
147
- {logo &&
167
+ {displayLogo &&
148
168
  renderLogo({
149
169
  size,
170
+ backgroundColor,
150
171
  logo,
172
+ logoSVG,
151
173
  logoSize,
152
174
  logoBackgroundColor,
175
+ logoColor,
153
176
  logoMargin,
154
- logoBorderRadius
177
+ logoBorderRadius,
155
178
  })}
156
179
  </Svg>
157
- )
158
- }
180
+ );
181
+ };
159
182
 
160
- export default QRCode
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
- }