Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
rn-mobile-barcode-scanner
Advanced tools
A barcode scanner component for React Native built on top of Dynamsoft Mobile Barcode SDK.
We have designed a new SDK suite Dynamsoft Capture Vision (DCV) as a replacement for all previous projects that showcase how Dynamsoft Mobile SDKs work in various mobile frameworks, including React Native, Flutter, Xamarin, Cordova, and more. DCV provides better documentation and a better integration experience for customers using one of these mobile frameworks.
The React-Native edition of DCV was released on June 23rd, 2022, with the release, we announced the deprecation of this package "rn-mobile-barcode-scanner", which means that this package will stop getting updates or patches from Dynamsoft.
We recommend that you select the DCV React-Native package in your project.
npx react-native init newBarcodeScanner
"dependencies": {
"react": "16.9.0",
"react-native": "0.61.1",
"react-native-canvas": "^0.1.37",
"rn-mobile-barcode-scanner": "^9.0.1",
"react-native-webview": "^11.2.0"
}
yarn install
import React from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Dimensions
} from 'react-native';
import { DBRRNCamera } from 'rn-mobile-barcode-scanner';
import Canvas from 'react-native-canvas';
const deviceH = Dimensions.get('window').height
const deviceW = Dimensions.get('window').width
class CameraScreen extends React.Component {
state = {
license: '-- put your license here -- ',
barcodeFormat: DBRRNCamera.Constants.DynamsoftBarcodeFormats.BarcodeFormat.ALL,
barcodeFormat2: DBRRNCamera.Constants.DynamsoftBarcodeFormats.BarcodeFormat2.NULL,
type: 'back',
canDetectBarcode: false,
barcodes: [{
type: '',
data: '',
localizationResult: []
}]
};
toggle = value => () => this.setState(prevState => ({ [value]: !prevState[value] }));
barcodeRecognized = ({ barcodes }) => {
this.setState({
barcodes: barcodes
});
}
handleCanvas = (canvas,barcodes) => {
if (canvas) {
canvas.width = deviceW
canvas.height = deviceH
const ctx = canvas.getContext('2d')
ctx.fillStyle = 'green'
ctx.lineWidth = 1
ctx.globalAlpha = 0.5
for(let res of this.state.barcodes){
if (res.localizationResult.length > 0) {
let loc = res.localizationResult
// console.log('canvas', res.data)
ctx.beginPath()
ctx.moveTo(loc[0], loc[1])
ctx.lineTo(loc[2], loc[3])
ctx.lineTo(loc[4], loc[5])
ctx.lineTo(loc[6], loc[7])
ctx.fill()
ctx.closePath()
ctx.stroke()
}
}
}else{
// console.log('no canvas')
}
}
renderBarcodes = () => (
<React.Fragment key={this.state.barcodes.length}>
{this.state.barcodes.map((barcodes)=><Canvas style={[styles.overlay]} ref={cvs=>this.handleCanvas(cvs,barcodes)} key={this.state.barcodes.length}/>)}
<Text style={styles.textBlock}>{this.state.barcodes[0] ?'result:'+ this.state.barcodes[0].data:'result: null'}</Text>
</React.Fragment>
);
renderCamera() {
const { canDetectBarcode } = this.state;
return (
<DBRRNCamera
ref={ref => {
this.camera = ref;
}}
style={{
flex: 1,
justifyContent: 'space-between',
}}
type={this.state.type}
license={this.state.license}
androidCameraPermissionOptions={{
title: 'Permission to use camera',
message: 'We need your permission to use your camera',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}
onDynamsoftBarcodesReader={canDetectBarcode ? this.barcodeRecognized : null}
barcodeFormat={this.state.barcodeFormat}
barcodeFormat2={this.state.barcodeFormat2}
>
<View style={{height:'100%'}}>
<View style={{height:'90%'}}>
{!!canDetectBarcode && this.renderBarcodes()}
</View>
<View style={{ flexDirection: 'row', alignSelf: 'center' }}>
<TouchableOpacity
onPress={this.toggle('canDetectBarcode')}
style={[styles.flipButton, { flex: 0.5, alignSelf: 'center' }]}
>
<Text style={styles.flipText}>{!canDetectBarcode ? 'Decode' : 'Decoding'}</Text>
</TouchableOpacity>
</View>
</View>
</DBRRNCamera>
);
}
render() {
return (
<View style={styles.container}>{this.renderCamera()}</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
flipButton: {
flex: 0.3,
height: 40,
marginHorizontal: 2,
borderRadius: 8,
borderColor: 'white',
borderWidth: 1,
padding: 5,
alignItems: 'center',
justifyContent: 'center',
},
flipText: {
color: 'white',
fontSize: 15,
},
text: {
padding: 10,
borderWidth: 2,
borderRadius: 2,
position: 'absolute',
borderColor: '#F00',
justifyContent: 'center',
},
textBlock: {
height: 'auto',
color: 'white',
textAlign: 'center',
padding: 10,
flexWrap: 'wrap'
},
overlay: {
flex: 1,
},
});
export default CameraScreen;
If you have completed the preparations, use the following command to run the project on your device.
npx react-native run-android
cd ios
pod install
cd ..
npx react-native run-ios
FAQs
Dynamsoft Barcode Reader for React Native
The npm package rn-mobile-barcode-scanner receives a total of 0 weekly downloads. As such, rn-mobile-barcode-scanner popularity was classified as not popular.
We found that rn-mobile-barcode-scanner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.