Skip to content

Commit

Permalink
Add camera permission handling and PIN
Browse files Browse the repository at this point in the history
functionality
  • Loading branch information
realjoshuau committed Nov 23, 2023
1 parent ca0af0b commit 0e51214
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
54 changes: 46 additions & 8 deletions apps/mobile/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// import { HomeIcon, HomeScreen } from '@acme/feature-home';
import { BarCodeScanner } from 'expo-barcode-scanner';
import { useEffect, useState } from 'react';
import { StyleSheet, View, Text, Image, Button } from 'react-native';
import { StyleSheet, View, Text, Image, Button, Linking, Alert } from 'react-native';
export default function App() {
const [hasPermission, setHasPermission] = useState(null);
const [scanned, setScanned] = useState(false);
const [message, setMessage] = useState('No PIN entered.');

Check warning on line 9 in apps/mobile/app/index.tsx

View workflow job for this annotation

GitHub Actions / packages

'setMessage' is assigned a value but never used

useEffect(() => {
const getBarCodeScannerPermissions = async () => {
Expand All @@ -16,18 +17,53 @@ export default function App() {
getBarCodeScannerPermissions();
}, []);

const handleBarCodeScanned = ({ type, data }) => {
setScanned(true);
alert(`Bar code with type ${type} and data ${data} has been scanned!`);
};

if (hasPermission === null) {
return <Text>Requesting for camera permission</Text>;
return (
<>
<View style={styles.container}>
<Text>Requesting for camera permission</Text>
<Button
title={'Enter Override PIN'}
onPress={() => {
Alert.alert('Not implemented.', "This feature hasn't been implemented yet.");
}}
/>

<Text>{message}</Text>
</View>
</>
);
}
if (hasPermission === false) {
return <Text>No access to camera</Text>;
return (
<>
<View style={styles.container}>
<Text>No access to camera</Text>
<Button
title={'Open Settings'}
onPress={() => {
// Launch settings for the app
Linking.openSettings();
}}
/>
<Button title={'Try Again'} onPress={() => setHasPermission(null)} />
<Button
title={'Enter Override PIN'}
onPress={() => {
Alert.alert('Not implemented.', "This feature hasn't been implemented yet.");
}}
/>
<Text>{message}</Text>
</View>
</>
);
}

const handleBarCodeScanned = ({ type, data }) => {
setScanned(true);
alert(`Bar code with type ${type} and data ${data} has been scanned!`);
};

return (
<View style={styles.container}>
<Text>Attendance!</Text>
Expand All @@ -46,6 +82,8 @@ export default function App() {
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
style={StyleSheet.absoluteFillObject}
/>
<Text>Has permission: {hasPermission.toString()}</Text>

{scanned && <Button title={'Tap to Scan Again'} onPress={() => setScanned(false)} />}
</View>
);
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"react-dom": "18.2.0",
"react-native": "0.72.4",
"react-native-gesture-handler": "~2.12.0",
"react-native-prompt": "^1.0.0",
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-svg": "^14.0.0",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0e51214

Please sign in to comment.