-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29941 from VickyStash/ts-migration/qrcode-component
[TS migration] Migrate 'QRCode' component to TypeScript
- Loading branch information
Showing
2 changed files
with
71 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |