import { BarCodeScanner } 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?: any[]; alerting: boolean; haveDimensions: boolean; canvasHeight?: number; canvasWidth?: number; boundingBox?: { origin: { x: number; y: number; }; size: { width: number; height: number; }; }; } 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, }; componentDidFocus = async () => { const { status } = await Permissions.askAsync(Permissions.CAMERA); this.setState({ isPermissionsGranted: status === 'granted' }); }; toggleAlertingAboutResult = () => { this.setState({ alerting: !this.state.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.boundingBox && ( )} {circles} )}