Skip to content

Commit 236c3bd

Browse files
authored
merge qrcode.react into rc-component/qrcode (#46)
1 parent 7ba54e8 commit 236c3bd

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@
7474
"peerDependencies": {
7575
"react": ">=16.9.0",
7676
"react-dom": ">=16.9.0"
77-
}
77+
},
78+
"packageManager": "[email protected]+sha512.8e4c3550fb500e808dbc30bb0ce4dd1eb614e30b1c55245f211591ec2cdf9c611cabd34e1364b42f564bd54b3945ed0f49d61d1bbf2ec9bd74b866fcdc723276"
7879
}

pnpm-lock.yaml

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QRCodeCanvas.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useRef, useState } from 'react';
1+
import React from 'react';
22
import { useQRCode } from './hooks/useQRCode';
33
import type { QRPropsCanvas } from './interface';
44
import {
@@ -29,10 +29,10 @@ const QRCodeCanvas = React.forwardRef<HTMLCanvasElement, QRPropsCanvas>(
2929
...otherProps
3030
} = props;
3131
const imgSrc = imageSettings?.src;
32-
const _canvas = useRef<HTMLCanvasElement | null>(null);
33-
const _image = useRef<HTMLImageElement>(null);
32+
const _canvas = React.useRef<HTMLCanvasElement | null>(null);
33+
const _image = React.useRef<HTMLImageElement>(null);
3434

35-
const setCanvasRef = useCallback(
35+
const setCanvasRef = React.useCallback(
3636
(node: HTMLCanvasElement | null) => {
3737
_canvas.current = node;
3838
if (typeof forwardedRef === 'function') {
@@ -45,7 +45,7 @@ const QRCodeCanvas = React.forwardRef<HTMLCanvasElement, QRPropsCanvas>(
4545
);
4646

4747

48-
const [, setIsImageLoaded] = useState(false);
48+
const [, setIsImageLoaded] = React.useState(false);
4949

5050
const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
5151
value,
@@ -57,7 +57,7 @@ const QRCodeCanvas = React.forwardRef<HTMLCanvasElement, QRPropsCanvas>(
5757
size,
5858
});
5959

60-
useEffect(() => {
60+
React.useEffect(() => {
6161
if (_canvas.current != null) {
6262
const canvas = _canvas.current;
6363

@@ -122,7 +122,7 @@ const QRCodeCanvas = React.forwardRef<HTMLCanvasElement, QRPropsCanvas>(
122122
}
123123
});
124124

125-
useEffect(() => {
125+
React.useEffect(() => {
126126
setIsImageLoaded(false);
127127
}, [imgSrc]);
128128

src/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function getImageSettings(
158158
*/
159159
export function getMarginSize(needMargin: boolean, marginSize?: number): number {
160160
if (marginSize != null) {
161-
return Math.floor(marginSize);
161+
return Math.max(Math.floor(marginSize), 0);
162162
}
163163
return needMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
164164
}

0 commit comments

Comments
 (0)