Skip to content

Instantly share code, notes, and snippets.

@shahnawaz
Last active March 15, 2024 12:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shahnawaz/d24ae843fc3a6056bef9c752d9b35e03 to your computer and use it in GitHub Desktop.
Save shahnawaz/d24ae843fc3a6056bef9c752d9b35e03 to your computer and use it in GitHub Desktop.
react-native-barcode-mask example usage
import React from "react";
import {
Text,
View,
Item,
Icon,
Input,
Button
} from 'native-base';
import { KeyboardAvoidingView } from "react-native";
import { RNCamera } from 'react-native-camera';
import BarcodeMask from 'react-native-barcode-mask';
const styles = {
root: {
flex: 1,
},
upperSection: {
flex: 1
},
lowerSection: {
paddingVertical: 30,
paddingHorizontal: 20,
backgroundColor: 'white',
},
camera: {
height: '100%',
},
};
class ItemBarcodeScanContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
barcode: ''
}
}
onBarCodeRead = (scanResult) => {
// scanResult.data will contain your scanned data
}
onGetItemPress = () => {
// do something with button press
}
handleChange = () => {
// handle user input
}
render() {
return (
<KeyboardAvoidingView style={styles.root}> {/* OR Use a simple <View> instead of <KeyboardAvoidingView> */}
<View style={styles.upperSection}>
<RNCamera
onBarCodeRead={this.onBarCodeRead}
// ... other related props of RNCamera
>
<BarcodeMask
width={100} height={300} showAnimatedLine={false} outerMaskOpacity={0.8}
/>
</RNCamera>
</View>
<View style={styles.lowerSection}>
<Item>
<Icon type={"Ionicons"} active name='md-barcode' />
<Input
placeholder='Barcode of the item'
value={this.state.barcode}
onChangeText={this.handleChange}
/>
</Item>
<Button
primary
onPress={this.onGetItemPress}
>
<Text>Get Item</Text>
</Button>
</View>
</KeyboardAvoidingView>
)
}
}
export default ItemBarcodeScanContainer;
@valn1
Copy link

valn1 commented Feb 11, 2021

is there a way to make this work with QRCodeScanner from react-native-qrcode-scanner?

@Ch3my
Copy link

Ch3my commented Aug 6, 2021

is there a way to make this work with QRCodeScanner from react-native-qrcode-scanner?

I'm also interested in this

@mariovalney
Copy link

@valn1 and @Ch3my it's easy with customMarker prop.

<QRCodeScanner
  showMarker
  topViewStyle={{ display: 'none' }}
  bottomViewStyle={{ display: 'none' }}
  customMarker={
    <BarcodeMask
      edgeColor={ Colors.container_background }
      edgeWidth={ 50 }
      edgeHeight={ 50 }
      edgeBorderWidth={ 10 }
      showAnimatedLine={ false }
    />
  }
/>

@NagaSwathiAmbati07
Copy link

while scanning if there is no barcode then for other things is it able to show no bar code text automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment