import {BarCodeEvent, BarCodeScanner, PermissionResponse} from 'expo-barcode-scanner'; import React, {ReactElement, useEffect, useState} from 'react'; import {AppRegistry, SafeAreaView, View} from 'react-native'; import { Appbar, Button, DarkTheme, DefaultTheme, HelperText, Provider as PaperProvider, Snackbar, Subheading, TextInput, Title } 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 _doNothing = () => {}; const _scan = () => setAppState(BarcodeScannerAppState.SCANNING); const _print = () => setAppState(BarcodeScannerAppState.PRINTING); const _home = () => setAppState(BarcodeScannerAppState.DEFAULT); const _settings = () => setAppState(BarcodeScannerAppState.SETTINGS); const handleBarCodeScanned = (e: BarCodeEvent) => { // Make sure the data is the right length. const barCodeString = e.data; const pattern = /^[\d]{14}$/; if (pattern.test(barCodeString)) { setBarCodeData(e.data); setDate(new Date()); setAppState(BarcodeScannerAppState.SCANNED); } else { setAppState(BarcodeScannerAppState.ERROR); } }; function ErrorMessage(props: ElementProps): ReactElement { return Something went wrong. Try again. } function LoadingMessage(props: ElementProps): ReactElement { return Loading...; } function SuccessMessage(props: ElementProps): ReactElement { return Your barcode label has printed successfully.; } function ActionButtons(props: ElementProps): ReactElement { return } function SettingsModal(props: ElementProps): ReactElement { const [inputStr, setInputStr] = useState(locationStr); const pattern = /^[\d]{4}$/; const hasErrors = () => { return !pattern.test(inputStr); }; return Settings Please do NOT change this unless you know what you are doing. Entering an incorrect location number may prevent patients from getting accurate info about their test results. setInputStr(inputStr)} mode="outlined" theme={DefaultTheme} /> Location number must be exactly 4 digits. No other characters are allowed. } function App(props: StateProps): ReactElement { 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 ; case BarcodeScannerAppState.SETTINGS: return ; default: return ; } } return ( ); }; AppRegistry.registerComponent(appExpo.name, () => Main);