import {BarCodeEvent, BarCodeScanner, PermissionResponse} from 'expo-barcode-scanner'; import React, {useEffect, useState} from 'react'; import {AppRegistry, SafeAreaView, Text, View} from 'react-native'; import {Appbar, DarkTheme, DefaultTheme, Provider as PaperProvider, Surface} from 'react-native-paper'; import {expo as appExpo} from './app.json'; import {CancelButton} from './components/Common'; import {BarCodeDisplay, PrintButton, PrintingMessage} from './components/Print'; import {ScanButton, Scanner} from './components/Scan'; import {colors, styles} from './components/Styles'; import {BarcodeScannerAppState} from './models/BarcodeScannerAppState'; import {ElementProps, StateProps} from './models/ElementProps'; const theme = { ...DefaultTheme, colors: colors, } export default function Main () { 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 _scan = () => setAppState(BarcodeScannerAppState.SCANNING); const _print = () => setAppState(BarcodeScannerAppState.PRINTING); const _home = () => setAppState(BarcodeScannerAppState.DEFAULT); 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 ActionButtons(props: ElementProps) { return } function App(props: StateProps) { switch (props.appState) { case BarcodeScannerAppState.INITIAL: return ; case BarcodeScannerAppState.DEFAULT: return ; case BarcodeScannerAppState.PRINTED: return ; case BarcodeScannerAppState.PRINTING: return ; case BarcodeScannerAppState.SCANNED: return ; case BarcodeScannerAppState.SCANNING: return ; default: return ; } } return ( ); }; AppRegistry.registerComponent(appExpo.name, () => Main);