import {BarCodeEvent, BarCodeScanner, PermissionResponse} from 'expo-barcode-scanner'; import React, {useEffect, useState} from 'react'; import {Text, View} from 'react-native'; import {CancelButton} from './components/Common'; import {BarCodeDisplay, PrintButton, PrintingMessage} from './components/Print'; import {ScanButton, Scanner} from './components/Scan'; import {styles} from './components/Styles'; import {BarcodeScannerAppState} from './models/BarcodeScannerAppState'; import {ElementProps, StateProps} from './models/ElementProps'; const App = () => { const [appState, setAppState] = useState(BarcodeScannerAppState.INITIAL); const [barCodeData, setBarCodeData] = useState(''); const [date, setDate] = useState(new Date()); const [locationStr, setLocationStr] = useState('4321'); useEffect(() => { BarCodeScanner.requestPermissionsAsync().then((value: PermissionResponse) => { if (value.granted) { setAppState(BarcodeScannerAppState.DEFAULT); } else { setAppState(BarcodeScannerAppState.ERROR); } }); }, []); const handleBarCodeScanned = (e: BarCodeEvent) => { setBarCodeData(e.data); setDate(new Date()); setAppState(BarcodeScannerAppState.SCANNED); }; function ErrorMessage(props: ElementProps) { return Something went wrong.; } function LoadingMessage(props: ElementProps) { return Loading...; } function SuccessMessage(props: ElementProps) { return Your barcode label has printed successfully.; } function Menu(props: StateProps) { switch (props.appState) { case BarcodeScannerAppState.INITIAL: return ; case BarcodeScannerAppState.DEFAULT: return setAppState(BarcodeScannerAppState.SCANNING)}/>; case BarcodeScannerAppState.PRINTED: return ; case BarcodeScannerAppState.PRINTING: return setAppState(BarcodeScannerAppState.SCANNED)}/>; case BarcodeScannerAppState.SCANNED: return setAppState(BarcodeScannerAppState.PRINTING)}/> setAppState(BarcodeScannerAppState.SCANNING)}/> setAppState(BarcodeScannerAppState.DEFAULT)}/> ; case BarcodeScannerAppState.SCANNING: return ; default: return ; } } return ( ); }; export default App;