Skip to content

Instantly share code, notes, and snippets.

@majirosstefan
Created September 19, 2021 09:39
Show Gist options
  • Save majirosstefan/537b35ccb70550aba7287ec930fe40e2 to your computer and use it in GitHub Desktop.
Save majirosstefan/537b35ccb70550aba7287ec930fe40e2 to your computer and use it in GitHub Desktop.
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