-
Notifications
You must be signed in to change notification settings - Fork 36
chore: round qr code logo borders #497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0e475b6
5b8eb47
a5c2e34
0e2c0ed
b92831d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| '@reown/appkit-react-native': patch | ||
| '@reown/appkit-ui-react-native': patch | ||
| '@reown/appkit-bitcoin-react-native': patch | ||
| '@reown/appkit-coinbase-react-native': patch | ||
| '@reown/appkit-common-react-native': patch | ||
| '@reown/appkit-core-react-native': patch | ||
| '@reown/appkit-ethers-react-native': patch | ||
| '@reown/appkit-solana-react-native': patch | ||
| '@reown/appkit-wagmi-react-native': patch | ||
| --- | ||
|
|
||
| chore: round logo from qr code + added borderWidth 0 to card component |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { memo, useMemo } from 'react'; | ||
| import { View, type StyleProp, type ViewStyle } from 'react-native'; | ||
| import Svg from 'react-native-svg'; | ||
| import Svg, { Circle, Line, Rect } from 'react-native-svg'; | ||
| import { Icon } from '../../components/wui-icon'; | ||
| import { Image } from '../../components/wui-image'; | ||
| import { Shimmer } from '../../components/wui-shimmer'; | ||
|
|
@@ -17,17 +17,32 @@ export interface QrCodeProps { | |
| testID?: string; | ||
| arenaClear?: boolean; | ||
| style?: StyleProp<ViewStyle>; | ||
| logoSize?: number; | ||
| logoBorderRadius?: number; | ||
| } | ||
|
|
||
| export function QrCode_({ size, uri, imageSrc, testID, arenaClear, icon, style }: QrCodeProps) { | ||
| export function QrCode_({ | ||
| size, | ||
| uri, | ||
| imageSrc, | ||
| testID, | ||
| arenaClear, | ||
| icon, | ||
| style, | ||
| logoSize, | ||
| logoBorderRadius | ||
| }: QrCodeProps) { | ||
| const Theme = LightTheme; | ||
| const containerPadding = Spacing.l; | ||
| const qrSize = size - containerPadding * 2; | ||
| const logoSize = arenaClear ? 0 : qrSize / 4; | ||
| const _logoSize = arenaClear ? 0 : logoSize ?? qrSize / 4; | ||
|
|
||
| const dots = useMemo( | ||
| () => (uri ? QRCodeUtil.generate(uri, qrSize, logoSize) : []), | ||
| [uri, qrSize, logoSize] | ||
| const dotColor = Theme['inverse-000']; | ||
| const edgeColor = Theme['inverse-100']; | ||
|
|
||
| const qrData = useMemo( | ||
| () => (uri ? QRCodeUtil.generate(uri, qrSize, _logoSize, logoBorderRadius) : null), | ||
| [uri, qrSize, _logoSize, logoBorderRadius] | ||
| ); | ||
|
|
||
| const logoTemplate = () => { | ||
|
|
@@ -40,8 +55,12 @@ export function QrCode_({ size, uri, imageSrc, testID, arenaClear, icon, style } | |
| <Image | ||
| source={imageSrc} | ||
| style={[ | ||
| styles.icon, | ||
| { height: qrSize / 4, width: qrSize / 4, borderRadius: qrSize / 16 } | ||
| { | ||
| position: 'absolute' as const, | ||
| height: _logoSize, | ||
| width: _logoSize, | ||
| borderRadius: logoBorderRadius | ||
| } | ||
| ]} | ||
| /> | ||
| ); | ||
|
|
@@ -51,14 +70,18 @@ export function QrCode_({ size, uri, imageSrc, testID, arenaClear, icon, style } | |
| <Icon | ||
| name={icon ?? 'walletConnect'} | ||
| color="accent-100" | ||
| height={qrSize / 3.5} | ||
| width={qrSize / 3.5} | ||
| style={styles.icon} | ||
| height={_logoSize} | ||
| width={_logoSize} | ||
| style={{ position: 'absolute' as const }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| return uri ? ( | ||
| if (!uri || !qrData) { | ||
| return <Shimmer width={size} height={size} borderRadius={BorderRadius.l} />; | ||
| } | ||
|
|
||
| return ( | ||
| <View | ||
| style={[ | ||
| styles.container, | ||
|
|
@@ -68,19 +91,55 @@ export function QrCode_({ size, uri, imageSrc, testID, arenaClear, icon, style } | |
| testID={testID} | ||
| > | ||
| <Svg height={qrSize} width={qrSize}> | ||
| {dots} | ||
| {/* Render rectangles */} | ||
| {qrData.rects.map(rect => ( | ||
| <Rect | ||
| key={`rect_${rect.x}_${rect.y}`} | ||
| fill={rect.fillType === 'dot' ? dotColor : edgeColor} | ||
| height={rect.size} | ||
| rx={rect.size * 0.32} | ||
| ry={rect.size * 0.32} | ||
| width={rect.size} | ||
| x={rect.x} | ||
| y={rect.y} | ||
| /> | ||
| ))} | ||
|
|
||
| {/* Render circles */} | ||
| {qrData.circles.map(circle => ( | ||
| <Circle | ||
| key={`circle_${circle.cx}_${circle.cy}`} | ||
| cx={circle.cx} | ||
| cy={circle.cy} | ||
| fill={dotColor} | ||
| r={circle.r} | ||
| /> | ||
| ))} | ||
|
|
||
| {/* Render lines */} | ||
| {qrData.lines.map(line => ( | ||
| <Line | ||
| key={`line_${line.x1}_${line.y1}_${line.y2}`} | ||
| x1={line.x1} | ||
| x2={line.x2} | ||
| y1={line.y1} | ||
| y2={line.y2} | ||
| stroke={dotColor} | ||
| strokeWidth={line.strokeWidth} | ||
| strokeLinecap="round" | ||
| /> | ||
| ))} | ||
| </Svg> | ||
| {logoTemplate()} | ||
| </View> | ||
| ) : ( | ||
| <Shimmer width={size} height={size} borderRadius={BorderRadius.l} /> | ||
| ); | ||
| } | ||
|
|
||
| export const QrCode = memo(QrCode_, (prevProps, nextProps) => { | ||
| return ( | ||
| prevProps.size === nextProps.size && | ||
| prevProps.uri === nextProps.uri && | ||
| prevProps.style === nextProps.style | ||
| prevProps.style === nextProps.style && | ||
| prevProps.logoBorderRadius === nextProps.logoBorderRadius | ||
| ); | ||
| }); | ||
|
Comment on lines
138
to
145
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Incomplete memo props cause stale QR codes.
The
QrCodecomponent'smemocomparison is incomplete. It misseslogoSize,imageSrc,icon,arenaClear, andtestIDprops. Changes to these props won't trigger a re-render, which can lead to stale QR codes or incorrect logo display.