Skip to content

Commit 419a2fa

Browse files
committed
fix: fix wrong finder pattern coordinates calculation
1 parent 98d47d8 commit 419a2fa

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

packages/react-qr-code/src/components/finder-patterns-inner.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FINDER_PATTERN_INNER_RADIUSES,
66
FINDER_PATTERN_INNER_SIZE,
77
FINDER_PATTERN_OUTER_ROTATIONS,
8+
FINDER_PATTERN_SIZE,
89
} from '../constants'
910
import type { FinderPatternsInnerProps } from '../types/utils'
1011
import {
@@ -27,8 +28,8 @@ export const FinderPatternsInner = ({
2728
const coordinates = useMemo(
2829
() => [
2930
{ x: margin + 2, y: margin + 2 },
30-
{ x: modules.length - margin + 1, y: margin + 2 },
31-
{ x: margin + 2, y: modules.length - margin + 1 },
31+
{ x: modules.length + margin - FINDER_PATTERN_SIZE + 2, y: margin + 2 },
32+
{ x: margin + 2, y: modules.length + margin - FINDER_PATTERN_SIZE + 2 },
3233
],
3334
[margin, modules.length],
3435
)

packages/react-qr-code/src/components/finder-patterns-outer.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ export const FinderPatternsOuter = ({
2828
const coordinates = useMemo(
2929
() => [
3030
{ x: margin, y: margin },
31-
{ x: modules.length - margin - 1, y: margin },
32-
{ x: margin, y: modules.length - margin - 1 },
31+
{ x: modules.length + margin - FINDER_PATTERN_SIZE, y: margin },
32+
{ x: margin, y: modules.length + margin - FINDER_PATTERN_SIZE },
3333
],
3434
[margin, modules.length],
3535
)
3636

37+
console.log('modules.length', modules.length)
38+
console.log('coordinates', coordinates)
39+
3740
if (['rounded-sm', 'rounded', 'rounded-lg', 'circle', 'square'].includes(style)) {
3841
for (const coordinate of coordinates) {
3942
const { x, y } = coordinate

0 commit comments

Comments
 (0)