Giter Club home page Giter Club logo

react-native-barcode-mask's Introduction

react-native-barcode-mask

version download licence build vulnerabilities dependencies

๐Ÿ“ท A barcode and QR code scan layout for react-native applications with customizable styling

Install

npm i react-native-barcode-mask -s

Usage

All you need is to import BarcodeMask from the react-native-barcode-mask module and then use it.

Example use with RNCamera

Inside <RNCamera>...</RNCamera> tag as a child component.

'use strict';
import React, { Component } from 'react';
import { RNCamera } from 'react-native-camera';
import BarcodeMask from 'react-native-barcode-mask';

...
    <RNCamera
        ...
    >
        <BarcodeMask />
    </RNCamera>
...

Examples

Few style modifications:

// Barcode
<BarcodeMask width={300} height={100} />

// QR
<BarcodeMask edgeColor={'#62B1F6'} showAnimatedLine={false}/>

// Barcode example 2
<BarcodeMask width={100} height={300} showAnimatedLine={false} outerMaskOpacity={0.8}/>

// Barcode example 3
<BarcodeMask width={300} height={100} edgeBorderWidth={1} />

Barcode full code example:

https://gist.github.com/shahnawaz/d24ae843fc3a6056bef9c752d9b35e03

โญ Pretty cool! Right?

Properties

width

Value: number | string (%)
Default: 280

Finder's width (the visible area)

height

Value: number | string (%)
Default: 230

Finder's height (the visible area)

edgeWidth

Value: number | string (%)
Default: 20

Edge/Corner's width

edgeHeight

Value: number | string (%)
Default: 20

Edge/Corner's height

edgeColor

Value: string
Default: #FFF

Use this to give custom color to edges

edgeBorderWidth

Value: number | string (%)
Default: 4

Use this to modify the border (thickness) of edges

edgeRadius

Value: number Default: 0

Use this to modify the border radius of edges

backgroundColor

Value: string
Default: rgb(0, 0, 0, 0.6)

Use this to modify the background color of area around finder

outerMaskOpacity

Value: number (0 - 1)
Default: 0.6

Use this to modify the transparency of outer mask

showAnimatedLine

Value: boolean
Default: true

animatedLineColor

Value: string
Default: #FFF

animatedLineHeight

Value: number
Default: 2

animatedLineWidth

Value: number | string (%)
Default: 85%

lineAnimationDuration

Value: number
Default: 1500

animatedLineOrientation

Value: string (horizontal | vertical)
Default: horiontal

useNativeDriver

Value: boolean
Default: true

React Native > 0.62.x requires us to sepcify useNativeDriver while working with animation

onLayoutMeasured

value: function

Details: Handler to receive onLayout event of finder. Useful if you want to only detect barcode inside the Finder area.

parameter: event

{
    nativeEvent: {
        target: number,
        layout: { height: number, width: number, x: number, y: number}
    }
}

Contribution

Want to add some new styles or layout?
Want to update few things?

Feel free to open a PR.

License

MIT

react-native-barcode-mask's People

Contributors

h11g avatar masterlambaster avatar pixelize avatar shahnawaz avatar slavikdenis avatar uehqzxi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-barcode-mask's Issues

Overlay does not completely cover some screens

I ran into a strange issue where the "squares" that make up the overlay have a tiny gap between them, but only on a Samsung Galaxy S20+ running Android 10. It works fine on a Nexus 5X and iPhone.

I was running the app in development mode through Expo.

In the screenshot below, you can see the line across the top of the barcode area.

WhatsApp Image 2020-05-19 at 13 06 30

Example of how to use `onLayoutMeasured`

Please can someone help me with how to make this work? I already added this props handler to BarcodeMask

const onFinderLayoutMeasured = ({nativeEvent}) => {

}

    <BarcodeMask
      width={250}
      height={250}
      showAnimatedLine={true}
      outerMaskOpacity={0.8}
      lineAnimationDuration={1500}
      edgeRadius={5}
      edgeBorderWidth={10}
      edgeColor={COLORS.skyBlue}
      edgeHeight={20}
      animatedLineColor={COLORS.primaryblue}
      animatedLineHeight={4}
      onLayoutMeasured={onFinderLayoutMeasured}
    />

Add onMaskLayout event

Provide onMaskLayout event so we could get mask position on screen and filter coordinates from camera component. Just trigger event with nativeEvent in method below.

_onMaskCenterViewLayoutUpdated = ({ nativeEvent }) => {
this.setState({
maskCenterViewHeight: nativeEvent.layout.height,
});
};

Custom style

I wouldn't think o this as an issue, more of a feature. My react native camera covers the entire screen, and I want to keep it that way. Having absolutely positioned content at the bottom, I don't have the ability to move the scanner mask box up. it's always centered

Change masking position

After adding the mask, the scanning area will be in the center of the view, How would I change its position?
Say, I want to move the scanning area to top of the view or place it to the bottom of the view. Is there a way to do it?

zIndex makes outer mask not visible

I don't know if this zIndex: -1 is important, but I'm trying to get the outer mask appear and the zIndex: -1 is making the outer mask be invisible. I think the zIndex: -1 is pushing the outer mask to back of camera view.

image

When I remove that line, it works!

image

Am I doing something wrong?

Animated line stops when device view is changed

Hi. I would like to report a visual bug that I found when testing this component.

When I open the camera on portrait view, animated line works fine. But when I changed to landscape view, still with the camera on, to see if any changes would apply to any props, the animated line stopped at the middle of the mask and didn't resume its animation even when I changed view back to portrait. This happens too when I open the camera on landscape view, animated line works fine until I change view to portrait. This was tested in a real device.

These are my output info of the project:

OS: Windows 10 10.0.19042
    CPU: (4) x64 Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
    Memory: 2.87 GB / 7.92 GB
  Binaries:
    Node: 15.2.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 7.0.8 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
      Build Tools: 23.0.1, 28.0.3, 29.0.2, 30.0.2, 30.0.3
      System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-24 | Google Play Intel x86 Atom
  IDEs:
    Android Studio: Version  4.1.0.0 AI-201.8743.12.41.6953283
    Visual Studio: 16.7.30621.155 (Visual Studio Community 2019)
  Languages:
    Java: 1.8.0_221
    Python: 3.9.0
  npmPackages:
    @react-native-community/cli: 4.13.0
    react: 16.13.1 => 16.13.1
    react-native: 0.63.3 => 0.63.3

Device info:
Model: moto x4
OS: Android 9 - API level 28

I'm using the mask with RNCamera inside a modal component which shows itself when a button is pressed and qrCodeVisible is set to true. Here's the snippet:

import React from 'react';
import {
    Modal,
} from 'react-native';
import { RNCamera } from 'react-native-camera';
import BarCodeMask from 'react-native-barcode-mask';

const QrCode = ({ qrCodeVisible, setQrCodeVisible, handleQrCode }) => {
    return (
        <Modal
            animationType={'slide'}
            transparent={true}
            visible={qrCodeVisible}
            onRequestClose={() => setQrCodeVisible(false)}
        >
            <RNCamera
                captureAudio={false}
                onBarCodeRead={(res) => handleQrCode(res.data)}
                barCodeTypes={[RNCamera.Constants.BarCodeType.qr]}
                style={{ flex: 1 }}
            >
                <BarCodeMask 
                    edgeColor={'#039be5'}
                    height={250}
                    width={250}
                    showAnimatedLine={true}
                    animatedLineColor={'red'}
                />
            </RNCamera>
        </Modal>
    );
}

export default QrCode;

I know it's a small bug and doesn't affect its funcionality but I would like to see this project as much perfect as possible. Keep with the nice work and thank you.

CameraManager.checkIfRecordAudioPermissionsAreDefined

hi bro ,
i was given camera persmission on manifest but its still return this mistake .. how can be solve that

CameraManager.checkIfRecordAudioPermissionsAreDefined is not a function. (In 'CameraManager.checkIfRecordAudioPermissionsAreDefined()', 'CameraManager.checkIfRecordAudioPermissionsAreDefined' is undefined)

edgeRadius blurred because it is not in camera!

<BarcodeMask
          edgeBorderWidth={4}
          edgeWidth={80}
          edgeHeight={80}
          backgroundColor={Colors.background}
          outerMaskOpacity={0.9}
          animatedLineHeight={4}
          animatedLineWidth="98%"
          edgeRadius={40}
        />

Invariant Violation: Element type is invalid when adding BarcodeMask as a child component

I've imported the module to use with my implemented RNCamera and I followed the example to put the BarcodeMask tag as a child component of the RNCamera, but it throws this error:

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Any help please? I need this in a hurry!

Platforms

Android

Versions

  • Android: 9
  • iOS: (not tested yet)
  • react-native-camera: ^3.19.0
  • react-native: 0.61.5
  • react: 16.9.0
  • react-native-barcode-mask: ^1.1.0

Description/Current Behaviour

Expected Behaviour

The barcode scan area is limited in a box by the barcode mask component.

Steps to Reproduce

Can't provide much other than importing the modules and use the tags.

Additionals

The code I use to implement it:

import {RNCamera} from 'react-native-camera'
import {BarcodeMask} from 'react-native-barcode-mask'
import {View} from 'react-native'

<View style={[styles.container, styles.bgColor]}>
    <RNCamera {props}>
        <BarcodeMask />
    </RNCamera>
</View>

Add typescript typings

It would be great if you could add simple typescript typings like index.d.ts:

import React from 'react';

export interface BarcodeMaskProps {
  width?: number | string;
  height?: number | string;
  edgeWidth?: number | string;
  edgeHeight?: number | string;
  edgeColor?: string;
  edgeBorderWidth?: number | string;
  transparency?: number;
  showAnimatedLine?: boolean;
  animatedLineColor?: string;
  animatedLineHeight?: number;
  lineAnimationDuration?: number;
}

export class BarcodeMask extends React.Component<BarcodeMaskProps, {}> {}

export default BarcodeMask;

Thanks :)

npm audit report

I know this may not be an actual issue, but I consider important to report them.

image

Custom mask background color

Could you make it possible to specify a mask background color other than black?

e.g.) rgba(0.0,0.5,0.3,0.6)

Thank you.

Use useNativeDriver=true for performance

For performance reasons, please consider using useNativeDriver on the Animated object. For this, you'll need to change from animating 'top' directly, to using translateY. I've 'hacked in' those changes locally, and it's a lot smoother.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.