Created
September 19, 2021 09:39
-
-
Save majirosstefan/537b35ccb70550aba7287ec930fe40e2 to your computer and use it in GitHub Desktop.
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 {Dimensions, StyleSheet, TouchableOpacity, View} from 'react-native'; | |
import {RNCamera} from 'react-native-camera'; | |
import {launchImageLibrary} from 'react-native-image-picker'; | |
import {QRreader} from 'react-native-qr-decode-image-camera'; | |
import QRCodeScanner from 'react-native-qrcode-scanner'; | |
import Ionicon from 'react-native-vector-icons/Ionicons'; | |
export default class CameraScaningScreen extends Component { | |
scanner; | |
constructor(props) { | |
super(props); | |
this.state = { | |
cameraType: RNCamera.Constants.Type.front, | |
uri: '', | |
isCameraVisible: true, | |
torchOn: false, | |
}; | |
} | |
//π this method calls business logic | |
onSuccessScan = e => { | |
console.log('Scanned', {e}); | |
if (this.props.onScan) { | |
console.log('calling parent', {e}); | |
this.props.onScan(e.data); | |
} | |
}; | |
render() { | |
const {height} = Dimensions.get('window'); | |
return ( | |
<View style={{flex: 1}}> | |
// π QRCodeScanner uses react-native-camera underhood | |
<QRCodeScanner | |
fadeIn={true} | |
ref={node => { | |
this.scanner = node; | |
}} | |
cameraProps={{ | |
androidCameraPermissionOptions: null, | |
checkAndroid6Permissions: false | |
}} | |
checkAndroid6Permissions={false} | |
cameraStyle={{flex: 1, height: height}} | |
// π | |
onRead={this.onSuccessScan} | |
showMarker={true} | |
flashMode={ | |
this.state.torchOn === false | |
? RNCamera.Constants.FlashMode.off | |
: RNCamera.Constants.FlashMode.torch | |
} | |
/> | |
</View> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment