Skip to content
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

[TS migration] Migrate 'QRCode' component to TypeScript #29941

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions src/components/QRCode/index.js

This file was deleted.

71 changes: 71 additions & 0 deletions src/components/QRCode/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React, {Ref} from 'react';
import QRCodeLibrary from 'react-native-qrcode-svg';
import {ImageSourcePropType} from 'react-native';
import defaultTheme from '../../styles/themes/default';
import CONST from '../../CONST';

type LogoRatio = typeof CONST.QR.DEFAULT_LOGO_SIZE_RATIO | typeof CONST.QR.EXPENSIFY_LOGO_SIZE_RATIO;

type LogoMarginRatio = typeof CONST.QR.DEFAULT_LOGO_MARGIN_RATIO | typeof CONST.QR.EXPENSIFY_LOGO_MARGIN_RATIO;

type QRCodeProps = {
/** The QR code URL */
url: string;

/**
* The logo which will be displayed in the middle of the QR code.
* Follows ImageProps href from react-native-svg that is used by react-native-qrcode-svg.
*/
logo?: ImageSourcePropType;

/** The size ratio of logo to QR code */
logoRatio?: LogoRatio;

/** The size ratio of margin around logo to QR code */
logoMarginRatio?: LogoMarginRatio;

/** The QRCode size */
size?: number;

/** The QRCode color */
color?: string;

/** The QRCode background color */
backgroundColor?: string;

/**
* Function to retrieve the internal component ref and be able to call it's
* methods
*/
getRef?: (ref: Ref<SVGElement>) => Ref<SVGElement>;
};

function QRCode({
url,
logo,
getRef,
size = 120,
color = defaultTheme.text,
backgroundColor = defaultTheme.highlightBG,
logoRatio = CONST.QR.DEFAULT_LOGO_SIZE_RATIO,
logoMarginRatio = CONST.QR.DEFAULT_LOGO_MARGIN_RATIO,
}: QRCodeProps) {
return (
<QRCodeLibrary
getRef={getRef}
value={url}
size={size}
logo={logo}
logoBackgroundColor={backgroundColor}
logoSize={size * logoRatio}
logoMargin={size * logoMarginRatio}
logoBorderRadius={size}
backgroundColor={backgroundColor}
color={color}
/>
);
}

QRCode.displayName = 'QRCode';

export default QRCode;
Loading