Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-qrcode-package

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-qrcode-package

This package include QR code generator and QR code Scanner for React Native.

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
25
decreased by-51.92%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-qrcode-package

QR Code generator and QR Code Scanner for React Native.

Features

  • Rendering of QR code images from JSON file
  • Scanning QR code images, data processing, log errors

Installation

npm i react-native-qrcode-package

Install dependency packages to generate qr code:

yarn add react-native-svg

Or

npm i react-native-svg

Install dependency packages to scan qr code:

yarn add react-native-camera
yarn add react-native-permissions

Or

npm i react-native-camera
npm i react-native-permissions

IMPORTANT New version of react-native-permissions (3.8.0) has breaking changes and doesn't work correctly on ios with camera permission. Use "react-native-permissions": "3.7.3" or below version.

After that for ios go to the folder your-project/ios and run pod install.

WARNING

You may got this warn after install react-native-camera: ViewPropTypes will be removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'. If you have warn then: go to the node-modules folder -> find react-native-camera folder -> src folder -> find the file RNCamera.js -> find inside the file: import ViewPropTypes from from 'react-native'; -> delete this import from 'react-native' -> create new import: import {ViewPropTypes} from 'deprecated-react-native-prop-types'; This is one of the solutions to this warn.

Requirements

iOS 10

With iOS 10 and higher you need to add the "Privacy - Camera Usage Description" key to the Info.plist of your project. This should be found in 'your_project/ios/your_project/Info.plist'. Add the following code:

<key>NSCameraUsageDescription</key>
<string>Your message to user when the camera is accessed for the first time</string>

Also you will need to add the following code to your Podfile (as part of the react-native-permissions setup):

permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"

You may also need to reset your simulator data after adding those permissions Device -> Erase All

Android 7

With Android 7 and higher you need to add the "Vibration" permission to your AndroidManifest.xml of your project if you want to use vibration after a successful scan. This should be found in your android/app/src/main/AndroidManifest.xml Add the following:

<uses-permission android:name="android.permission.VIBRATE"/>

You need to add the "missingDimensionStrategy" config for the 'react-native-camera' setting to 'general', this should be found in your android/app/build.gradle add the following:

android {
  ...
  defaultConfig {
    ...
    missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
  }
}

Examples

GenerateQRCode
import GenerateQRCode from 'react-native-qrcode-package';

// Simple usage(all fields have default values except 'jsonObject')
 render() {
    return (
      <View>
        <GenerateQRCode
          jsonObject={data} // data - it's your json file(data.json)
          sizeQRcode={200}
        />
      </View>
    );
  }
// error handle
handleError = (error: undefined) => {
    console.error('Something went wrong', error);
  };
render() {
    return (
      <View>
        <GenerateQRCode
          jsonObject={data}
          onError={e => handleError(e)}
        />
      </View>
    );
  }
ScanQRCode
import ScanQRCode from 'react-native-qrcode-package';

// Simple usage(all fields have default values except 'onQRCodeScanned')
handleScanJsonObject = (json: object) => {
    console.log('QR Code data:', json);
  };
 render() {
    return (
      <View>
        <ScanQRCode
          onQRCodeScanned={handleScanJsonObject}
        />
      </View>
    );
  }
// error handle
handleError = (error: undefined) => {
    console.error('Something went wrong', error);
    Alert.alert(
      'Invalid QR Code',
      'The scanned QR code does not contain valid JSON',
      [
        {
          text: 'OK',
          onPress: () => {},
        },
      ],
    );
  };
render() {
    return (
      <View>
         <ScanQRCode
          onQRCodeScanned={handleScanJsonObject}
          onError={handleError}
        />
      </View>
    );
  }

Props

GenerateQRCode
NameDefaultDescription
sizeQRCode150Size of rendered image in pixels
jsonObjectobjectPut your a JSON .json file of the QR code. Example: '{"brand": "Name","model": "Model name"}'
colorQrCode'black'Color of the QR code
onError(error)undefinedCallback fired when exception happened during the code generating process
backgroundColorQRCode'white'Color of the background QR code
enableLinearGradientfalseEnable or disable linear gradient
linearGradient['rgb(255,0,0)','rgb(0,255,255)']Array of 2 rgb colors used to create the linear gradient
gradientDirection[170,0,0,0]The direction of the linear gradient
logonullImage source object. Ex. {uri: 'base64string'} or {require('pathToImage')}
logoSize20% of sizeSize of the imprinted logo. Bigger logo equals less error correction in QR code
logoBackgroundColor'transparent'The logo gets a filled quadratic background with this color. Use 'transparent' if your logo already has its own backdrop.
logoMargin2Logo distance to it's wrapper
logoBorderRadius0Border-radius of logo image (Android isn't 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
PropType
sizeQRCodenumber
jsonObjectobject
colorQrCodestring
onError(error)Function
backgroundColorQRCodestring
enableLinearGradientboolean
linearGradientstring []
gradientDirectionstring []
logoImageSourcePropType
logoSizenumber
logoBackgroundColorstring
logoMarginnumber
logoBorderRadiusnumber
quietZonenumber
getRef(c: any) => anyFunction
ecl'L' or 'M' or 'Q' or 'H'
ScanQRCode
NameDefaultDescription
onQRCodeScanned(object)-Will call this specified method when a QR code is detected in the camera.
vibrateAfterScanfalseVibrate after Scanned QR
reactivateCameratrueWill reactivate the scanning ability of the component.
reactivateScanTimeout0Use this to configure how long it should take (in milliseconds) before the ScanQRCode should reactivate.
fadeImageIntrueWhen set to true this ensures that the camera view fades in after the initial load up instead of being rendered immediately. Set this to false to prevent the animated fade in of the camera view.
showScanMarkerfalseUse this to show marker on the camera scanning window.
cameraType'back'Use this to control which camera to use for scanning QR codes.(propType: ['front', 'back'])
customMarker-Pass a RN element/component to use it as a custom marker.
containerStyle-Use this to pass styling for the outermost container.
cameraStyle-Use this to pass or overwrite styling for the camera window rendered.
cameraContainerStyle-Use this to pass or overwrite styling for the camera container (view) window rendered.
markerStyle-Use this to add custom styling to the default marker.
topViewStyle-Use this to pass or overwrite styling for the '' that contains the topContent prop.
bottomViewStyle-Use this to pass or overwrite styling for the '' that contains the bottomContent prop.
topContent-Use this to render any additional content at the top of the camera view.(propType: oneOfType([ PropTypes.element, PropTypes.string, ]))
bottomContent-Use this to render any additional content at the bottom of the camera view.(propType: oneOfType([ PropTypes.element, PropTypes.string, ]))
notAuthorizedView-Pass a RN element/component to use it when no permissions given to a camera (only IOS).
permissionDialogTitle'Permission'Use this to set permission dialog title (only Android).(propType: string)
permissionDialogMessage'Requires camera permission to scan'Use this to set permission dialog message (only Android).(propType: string)
buttonPositive'OK'Use this to set permission dialog button text (only Android).(propType: string)
checkAndroid6PermissionsfalseUse this to enable permission checking on Android 6.
lightModeRNCamera.Constants.FlashMode.offPart of the react-native-camera package react-native-camera/flashMode:RNCamera.Constants.FlashMode.off (turns it off) / RNCamera.Constants.FlashMode.on(means camera will use flash in all photos taken) / RNCamera.Constants.FlashMode.auto(leaves your phone to decide when to use flash when taking photos, based on the lightning conditions that the camera observes) / RNCamera.Constants.FlashMode.torch(turns on torch mode, meaning the flash light will be turned on all the time (even before taking photo) just like a flashlight).
onError(error: Error)'this is handling errors that occurred during scanning'Callback fired when exception happened during the scanning process
cameraScanTimeout0Use this to configure how long it should take (in milliseconds) before the ScanQRCode should be displayed. After that the camera will be inactive and press the view to reactivate it.
cameraProps-Properties to be passed to the Camera component.(prop type: object)
cameraTimeoutView-Pass an RN element/component to show it when the camera is inactive for cameraScanTimeout (another prop) milliseconds. If the cameraScanTimeout is 0 or not specified, this prop will never be used.
PropType
onQRCodeScanned(json: object) => voidFunction
vibrateAfterScanboolean
reactivateCameraboolean
reactivateScanTimeoutnumber
fadeImageInboolean
showScanMarkerboolean
cameraType'front'
customMarkerJSX.Element
containerStyleStyleProp
cameraStyleStyleProp
cameraContainerStyleStyleProp
markerStyleStyleProp
topViewStyleStyleProp
bottomViewStyleStyleProp
topContentJSX.Element or string
bottomContentJSX.Element or string
notAuthorizedViewJSX.Element
permissionDialogTitlestring
permissionDialogMessagestring
buttonPositivestring
checkAndroid6Permissionsboolean
lightModeRNCamera.Constants.FlashMode.off or RNCamera.Constants.FlashMode.on or RNCamera.Constants.FlashMode.auto or RNCamera.Constants.FlashMode.torch
onError(error: undefined) => voidFunction
cameraScanTimeoutnumber
cameraPropsRNCameraProps
cameraTimeoutViewJSX.Element

Keywords

FAQs

Package last updated on 17 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc