Custom Qr Code Scanner
See original GitHub issueI just wanna share my custom Qr Code Scanner with scanBar that animates up and down
You need to install this first (Google them because their installation requires linking)
react-native-vector-icons
react-native-animatable
Just change the color, size of the following depending on your needs
const overlayColor = "rgba(0,0,0,0.5)"; // this gives us a black color with a 50% transparency
const rectDimensions = SCREEN_WIDTH * 0.65; // this is equivalent to 255 from a 393 device width
const rectBorderWidth = SCREEN_WIDTH * 0.005; // this is equivalent to 2 from a 393 device width
const rectBorderColor = "#fff";
const scanBarWidth = SCREEN_WIDTH * 0.46; // this is equivalent to 180 from a 393 device width
const scanBarHeight = SCREEN_WIDTH * 0.0025; //this is equivalent to 1 from a 393 device width
const scanBarColor = "red";
const iconScanColor = "#fff";
Full Code
import React, { Component } from "react";
import { View, Dimensions, Text } from "react-native";
import QRCodeScanner from "react-native-qrcode-scanner";
import Icon from "react-native-vector-icons/Ionicons";
import * as Animatable from "react-native-animatable";
const SCREEN_HEIGHT = Dimensions.get("window").height;
const SCREEN_WIDTH = Dimensions.get("window").width;
console.disableYellowBox = true;
class QrCodeCamera extends Component {
onSuccess(e) {
alert(e);
}
makeSlideOutTranslation(translationType, fromValue) {
return {
from: {
[translationType]: SCREEN_WIDTH * -0.18
},
to: {
[translationType]: fromValue
}
};
}
render() {
return (
<QRCodeScanner
showMarker
onRead={this.onSuccess.bind(this)}
cameraStyle={{ height: SCREEN_HEIGHT }}
customMarker={
<View style={styles.rectangleContainer}>
<View style={styles.topOverlay}>
<Text style={{ fontSize: 30, color: "white" }}>
QR CODE SCANNER
</Text>
</View>
<View style={{ flexDirection: "row" }}>
<View style={styles.leftAndRightOverlay} />
<View style={styles.rectangle}>
<Icon
name="ios-qr-scanner"
size={SCREEN_WIDTH * 0.73}
color={iconScanColor}
/>
<Animatable.View
style={styles.scanBar}
direction="alternate-reverse"
iterationCount="infinite"
duration={1700}
easing="linear"
animation={this.makeSlideOutTranslation(
"translateY",
SCREEN_WIDTH * -0.54
)}
/>
</View>
<View style={styles.leftAndRightOverlay} />
</View>
<View style={styles.bottomOverlay} />
</View>
}
/>
);
}
}
const overlayColor = "rgba(0,0,0,0.5)"; // this gives us a black color with a 50% transparency
const rectDimensions = SCREEN_WIDTH * 0.65; // this is equivalent to 255 from a 393 device width
const rectBorderWidth = SCREEN_WIDTH * 0.005; // this is equivalent to 2 from a 393 device width
const rectBorderColor = "red";
const scanBarWidth = SCREEN_WIDTH * 0.46; // this is equivalent to 180 from a 393 device width
const scanBarHeight = SCREEN_WIDTH * 0.0025; //this is equivalent to 1 from a 393 device width
const scanBarColor = "#22ff00";
const iconScanColor = "blue";
const styles = {
rectangleContainer: {
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: "transparent"
},
rectangle: {
height: rectDimensions,
width: rectDimensions,
borderWidth: rectBorderWidth,
borderColor: rectBorderColor,
alignItems: "center",
justifyContent: "center",
backgroundColor: "transparent"
},
topOverlay: {
flex: 1,
height: SCREEN_WIDTH,
width: SCREEN_WIDTH,
backgroundColor: overlayColor,
justifyContent: "center",
alignItems: "center"
},
bottomOverlay: {
flex: 1,
height: SCREEN_WIDTH,
width: SCREEN_WIDTH,
backgroundColor: overlayColor,
paddingBottom: SCREEN_WIDTH * 0.25
},
leftAndRightOverlay: {
height: SCREEN_WIDTH * 0.65,
width: SCREEN_WIDTH,
backgroundColor: overlayColor
},
scanBar: {
width: scanBarWidth,
height: scanBarHeight,
backgroundColor: scanBarColor
}
};
export default QrCodeCamera;
Issue Analytics
- State:
- Created 5 years ago
- Reactions:122
- Comments:14 (1 by maintainers)
Top Results From Across the Web
QRCode Monkey - The free QR Code Generator to create ...
Create custom QR Codes with Logo, Color and Design for free. This QR Code Maker offers free vector formats for best print quality.'...
Read more >QR Code Generator | Create Your Free QR Codes
QR Code Generator for URL, vCard, and more. Add logo, colors, frames, and download in high print quality. Get your free QR Codes...
Read more >Home of QR | The free QR code generator - Unitag
Try our powerful free Qr code generator and let your imagination guide your creation with our powerful tool. ... Customized QR Codes may...
Read more >QR Code Generator - Reliable. Custom. Easy. Free
Beaconstac's free QR Code generator with logo allows you to create QR Codes instantly. Custom QR Codes. Unlimited scans. Never expires.
Read more >QR Code Generator - Free Custom QR Code Maker and ...
Best QR code generator to create dynamic QR codes with logo and track data for professional use and marketing, free customized QR code...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
amazing. It’s fantastic. thank you
Thanks for sharing the code.
But I found an issue it happens on
onPress function won’t trigger on Android. ( iOS is working )
I have no idea why.
If just test a code like this it’s still not working with yellow background.