Created
May 9, 2018 10:21
-
-
Save fariswd/33ea914a8bb104909923764e349c09ec to your computer and use it in GitHub Desktop.
barcode scanner oppacity background
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { Text, View, StyleSheet, Alert } from 'react-native'; | |
import { Constants, BarCodeScanner, Permissions } from 'expo'; | |
export default class App extends Component { | |
state = { | |
hasCameraPermission: null | |
}; | |
componentDidMount() { | |
this._requestCameraPermission(); | |
} | |
_requestCameraPermission = async () => { | |
const { status } = await Permissions.askAsync(Permissions.CAMERA); | |
this.setState({ | |
hasCameraPermission: status === 'granted', | |
}); | |
}; | |
_handleBarCodeRead = data => { | |
Alert.alert( | |
'Scan successful!', | |
JSON.stringify(data) | |
); | |
}; | |
render() { | |
return ( | |
<BarCodeScanner | |
onBarCodeRead={(scan) => alert(scan.data)} | |
style={[StyleSheet.absoluteFill, styles.container]} | |
> | |
<View style={styles.layerTop} /> | |
<View style={styles.layerCenter}> | |
<View style={styles.layerLeft} /> | |
<View style={styles.focused} /> | |
<View style={styles.layerRight} /> | |
</View> | |
<View style={styles.layerBottom} /> | |
</BarCodeScanner> | |
); | |
} | |
} | |
const opacity = 'rgba(0, 0, 0, .6)'; | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
flexDirection: 'column', | |
}, | |
layerTop: { | |
flex: 1, | |
backgroundColor: opacity | |
}, | |
layerCenter: { | |
flex: 1, | |
flexDirection: 'row' | |
}, | |
layerLeft: { | |
flex: 3, | |
backgroundColor: opacity | |
}, | |
focused: { | |
flex: 10 | |
}, | |
layerRight: { | |
flex: 3, | |
backgroundColor: opacity | |
}, | |
layerBottom: { | |
flex: 1, | |
backgroundColor: opacity | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment