6.3.0 • Published 3 months ago

react-native-qrcode-svg v6.3.0

Weekly downloads
35,703
License
MIT
Repository
github
Last release
3 months ago

Looking for maintainers

I'm not working on any React Native projects anymore. Feel free to take over this project if you feel good about it!

NPM circleci

react-native-qrcode-svg

A QR Code generator for React Native based on react-native-svg and javascript-qrcode.

Discussion: https://discord.gg/RvFM97v

Features

  • Easily render QR code images
  • Optionally embed a logotype
AndroidiOS

Installation

Install dependency packages

yarn add react-native-svg react-native-qrcode-svg

Or

npm i -S react-native-svg react-native-qrcode-svg

If you are using React Native 0.60.+ go to the folder your-project/ios and run pod install, and you're done.

If not, use one of the following method to link.

Link with react-native link

If you are using React Native <= 0.59.X, link the native project:

react-native link react-native-svg

Examples

import QRCode from 'react-native-qrcode-svg';

// Simple usage, defaults for all but the value
render() {
  return (
    <QRCode
      value="http://awesome.link.qr"
    />
  );
};
// 30px logo from base64 string with transparent background
render() {
  let base64Logo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAA..';
  return (
    <QRCode
      value="Just some string value"
      logo={{uri: base64Logo}}
      logoSize={30}
      logoBackgroundColor='transparent'
    />
  );
};
// 20% (default) sized logo from local file string with white logo backdrop
render() {
  let logoFromFile = require('../assets/logo.png');
  return (
    <QRCode
      value="Just some string value"
      logo={logoFromFile}
    />
  );
};
// get base64 string encode of the qrcode (currently logo is not included)
getDataURL() {
  this.svg.toDataURL(this.callback);
}

callback(dataURL) {
  console.log(dataURL);
}

render() {
  return (
    <QRCode
      value="Just some string value"
      getRef={(c) => (this.svg = c)}
    />
  );
}

Props

NameDefaultDescription
size100Size of rendered image in pixels
value'this is a QR code'String Value of the QR code. Can also accept an array of segments as defined in Manual mode. Ex. [{ data: 'ABCDEFG', mode: 'alphanumeric' }, { data: '0123456', mode: 'numeric' }, { data: 253,254,255, mode: 'byte' }]
color'black'Color of the QR code
backgroundColor'white'Color of the background
enableLinearGradientfalseenables or disables linear gradient
linearGradient'rgb(255,0,0)','rgb(0,255,255)'array of 2 rgb colors used to create the linear gradient
gradientDirection170,0,0,0the direction of the linear gradient
logonullImage source object. Ex. {uri: 'base64string'} or {require('pathToImage')}
logoSize20% of sizeSize of the imprinted logo. Bigger logo = less error correction in QR code
logoBackgroundColorbackgroundColorThe logo gets a filled quadratic background with this color. Use 'transparent' if your logo already has its own backdrop.
logoMargin2logo's distance to its wrapper
logoBorderRadius0the border-radius of logo image (Android is not supported)
quietZone0quiet zone around the qr in pixels (useful when saving image to gallery)
getRefnullGet SVG ref for further usage
ecl'M'Error correction level
onError(error)undefinedCallback fired when exception happened during the code generating process

Saving generated code to gallery

Note: Experimental only ( not tested on iOS) , uses getRef() and needs RNFS module

npm install --save react-native-fs

Example for Android:

import { CameraRoll , ToastAndroid } from "react-native"
import RNFS from "react-native-fs"
...

  saveQrToDisk() {
   	this.svg.toDataURL((data) => {
   		RNFS.writeFile(RNFS.CachesDirectoryPath+"/some-name.png", data, 'base64')
   		  .then((success) => {
   			  return CameraRoll.saveToCameraRoll(RNFS.CachesDirectoryPath+"/some-name.png", 'photo')
   		  })
   		  .then(() => {
   			  this.setState({ busy: false, imageSaved: true  })
   			  ToastAndroid.show('Saved to gallery !!', ToastAndroid.SHORT)
   		  })
   	})
  }

Dependencies

PeerDependencies

Dependencies


If you like this project, please consider buy me a coffee :)

https://www.buymeacoffee.com/LquC7mid5

@neur0base/app-sdk@borderfreefinancial/revoshowtvui-test@borderfreefinancial/revotvvideocomponent-test@thirdweb-dev/react-nativeairmodrevoshowuireact-native-womasoft@everything-registry/sub-chunk-2588taro-qrcodeinso-motorbike-liability@aztec-3/react-native-walletconnect@carlosdp/react-native-dapp@arcturis/one-ui@communi/chat-ui-react-native@deficonnect/react-native-dapp@gaozh1024/rn-libs@final-ui/kit@functionland/component-library@functionland/fx-components@yoronsoft/rn-libs@xcoobee/react-native-xcoobee-payment-sdk@digitalfactory/react-native-componentsdu-track-ordereostokenexpo-solana-walletkelp-mobile-walletpoket-app-testphudao-componentsquasioreact-native-doreact-native-cottersales-sync-mobilesalmonwalletv2sayswitch-payment-sdkreact-native-kash-cash-sdkreact-native-sjzt-libraryreact-native-template-umbappsamplereact-native-template-marcusvbdarevoshowui-testrn-vayvaytaro-code-creatorui-amberstorybook-compostorybook-componentsstatefullapicjslibrarystablex-sdksubwallet-react-native-uiwallet-appzeninvest@7-eleven-platform/component-kits@7-eleven/component-kits@walletconnect/react-native-dapp@wallet_framework/rn@borderfreefinancial/revoshowui@borderfreefinancial/revoshowtvui@zalastax/nolb-react-native-q@kqinfo/ui@logo-rn/logo-qr-code@kancha/kancha-ui@infinitebrahmanuniverse/nolb-react-native-q@womasoft/rn-libs@mcplabs/mcp-rn-showtime-templateaphrica@muhammadz/elixir-react-native-components@metamask/sdk-uiaws-cognito-react-native-ui@nftearth/react-nativecenteridentity-expobitlabs@onebasket/ticketing-ui-react-native@onebasket/fnb-ui-react-native@peersyst/react-native-componentscoderzy260-rn@react-native-oh-tpl/react-native-qrcode-svgcomponent-kits@selene-wallet/app
6.3.0

3 months ago

6.2.0

1 year ago

6.1.2

2 years ago

6.1.1

3 years ago

6.1.0

3 years ago

6.0.7

3 years ago

6.0.6

4 years ago

6.0.5

4 years ago

6.0.3

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.3.2

4 years ago

5.3.1

5 years ago

5.2.0

5 years ago

5.1.2

5 years ago

5.1.1

6 years ago

5.1.0

6 years ago

5.0.7

6 years ago

5.0.6

6 years ago

5.0.5

6 years ago

5.0.4

6 years ago

5.0.3

7 years ago

5.0.2

7 years ago

5.0.0

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.2

7 years ago

3.0.0

7 years ago

2.0.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago