Import the QRCode component from react-native-qrcode-svg.
The main prop is value, which takes the string you want to encode, such as a URL or some text.
/components/MyQRCode.tsx
import React from 'react';import { View, StyleSheet, Text } from 'react-native';import QRCode from 'react-native-qrcode-svg'; // 라이브러리에서 QRCode 컴포넌트 가져오기interface MyQRCodeProps { value: string; // QR 코드로 만들 값 (URL 등) size?: number; // QR 코드 크기 (선택적)}const MyQRCode: React.FC<MyQRCodeProps> = ({ value, size = 128 }) => { if (!value) { // value 값이 없을 경우 에러 처리 또는 대체 UI 표시 return ( <View style={styles.container}> <Text>QR 코드를 생성할 값이 없습니다.</Text> </View> ); } return ( <View style={styles.container}> <QRCode value={value} // QR 코드로 변환할 문자열 전달 size={size} // QR 코드의 가로, 세로 크기 (기본값 128) // --- 추가 옵션들 --- // color="black" // QR 코드 색상 (기본값 black) // backgroundColor="white" // 배경색 (기본값 white) // quietZone={10} // QR 코드 주변의 여백 크기 /> <Text style={styles.valueText}>데이터: {value}</Text> </View> );};const styles = StyleSheet.create({ container: { alignItems: 'center', justifyContent: 'center', padding: 20, }, valueText: { marginTop: 10, fontSize: 12, color: '#666', },});export default MyQRCode;
Import the QRCode component.
Pass the string you want to encode, such as a URL, to the value prop.
Use the size prop to set the QR code's size. The default is 128.
Now let's use MyQRCode to display a deep link as a QR code.
/app/generateQRScreen.tsx
import React from 'react';import { View, Text, StyleSheet, SafeAreaView } from 'react-native';import MyQRCode from '../components/MyQRCode'; // 위에서 만든 QR 코드 컴포넌트export default function GenerateQRScreen() { // 예시 딥링크 URL (실제 앱 스킴과 경로에 맞게 수정 필요) const deepLinkUrl = 'myawesomeapp://products/detail?productId=777&source=qrcode'; return ( <SafeAreaView style={styles.safeArea}> <View style={styles.container}> <Text style={styles.title}>상품 상세 페이지 딥링크 QR 코드</Text> <Text style={styles.description}> 아래 QR 코드를 스캔하면 앱의 상품 상세 페이지(ID: 777)로 이동합니다. </Text> {/* MyQRCode 컴포넌트에 딥링크 URL 전달 */} <MyQRCode value={deepLinkUrl} size={200} /> </View> </SafeAreaView> );}const styles = StyleSheet.create({ safeArea: { flex: 1, backgroundColor: '#fff', }, container: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: 20, }, title: { fontSize: 22, fontWeight: 'bold', marginBottom: 15, textAlign: 'center', }, description: { fontSize: 14, color: '#555', textAlign: 'center', marginBottom: 30, },});
Put the deep link you want to encode in deepLinkUrl. It must match the app's scheme and the Expo Router path.
Render MyQRCode with deepLinkUrl as its value and the desired size, such as 200.
When you open this screen in the app, it generates and displays a QR code for the deep link. Users can scan it with another device's camera or a QR scanner app to open the link.
react-native-qrcode-svg offers more ways to customize the code.
color sets the QR code color. For example, use color="blue".
backgroundColor sets the background color. For example, use backgroundColor="#f0f0f0".
logo places a logo image in the center of the QR code. Use require to specify a local image path.
logoSize, logoBackgroundColor, logoMargin, and logoBorderRadius control the logo's styling.
ecl sets the error correction level. Choose from 'L', 'M', 'Q', or 'H'. A higher level makes a partially damaged QR code more likely to scan but makes the pattern more complex. 'H' is sometimes recommended when including a logo.
// 로고를 포함한 예시import logoImage from '../assets/my_app_logo.png'; // 로고 이미지 import// ... 컴포넌트 내부 ...<QRCode value={deepLinkUrl} size={250} logo={logoImage} // 로고 이미지 전달 logoSize={40} logoBackgroundColor="transparent" ecl="H" // 오류 복원 수준 높게 설정/>// ...
We used react-native-qrcode-svg to generate and display a QR code for a URL, including a deep link, in an Expo app. QR codes connect online and offline experiences and make links easier for users to open.