import { BarCodeScanner, BarCodePoint, BarCodeEvent, BarCodeBounds } from 'expo-barcode-scanner'; import * as Permissions from 'expo-permissions'; import * as ScreenOrientation from 'expo-screen-orientation'; import React from 'react'; import { Button, Platform, StyleSheet, Text, View } from 'react-native'; import * as Svg from 'react-native-svg'; import { NavigationEvents } from 'react-navigation'; const BUTTON_COLOR = Platform.OS === 'ios' ? '#fff' : '#666'; interface State { isPermissionsGranted: boolean; type: any; cornerPoints?: BarCodePoint[]; alerting: boolean; haveDimensions: boolean; canvasHeight?: number; canvasWidth?: number; boundingBox?: BarCodeBounds; cornerPointsString?: string; showBoundingBox: boolean; showText: boolean; data: string; } export default class BarcodeScannerExample extends React.Component { static navigationOptions = { title: '', }; canChangeOrientation = false; readonly state: State = { isPermissionsGranted: false, type: BarCodeScanner.Constants.Type.back, alerting: false, haveDimensions: false, showBoundingBox: false, data: '', showText: false, }; componentDidFocus = async () => { const { status } = await Permissions.askAsync(Permissions.CAMERA); this.setState({ isPermissionsGranted: status === 'granted' }); }; toggleAlertingAboutResult = () => { this.setState(({ alerting }) => ({ alerting: !alerting, })); }; toggleScreenOrientationState = () => { if (this.canChangeOrientation) { ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP); } else { ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.ALL); } this.canChangeOrientation = !this.canChangeOrientation; }; setCanvasDimensions = (e: any) => { this.setState({ canvasWidth: e.nativeEvent.layout.width, canvasHeight: e.nativeEvent.layout.height, haveDimensions: true, }); }; render() { if (!this.state.isPermissionsGranted) { return ( You have not granted permission to use the camera on this device! ); } const circles = []; if (this.state.cornerPoints) { for (const point of this.state.cornerPoints) { circles.push( ); } } return ( {this.state.haveDimensions && ( {this.state.showBoundingBox && this.state.cornerPointsString && ( )} {this.state.showText && this.state.boundingBox && ( {this.state.data} )} {circles} )}