Skip to content

Commit

Permalink
fix: qr scasnner and expo camera
Browse files Browse the repository at this point in the history
Signed-off-by: Jan <[email protected]>
  • Loading branch information
janrtvld committed Dec 16, 2024
1 parent 4d3ff3f commit 1b2ff79
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 70 deletions.
6 changes: 6 additions & 0 deletions apps/easypid/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ const config = {
},
],
'expo-router',
[
'expo-camera',
{
cameraPermission: 'Allow $(PRODUCT_NAME) to access your camera.',
},
],
],
assetBundlePatterns: ['**/*'],
ios: {
Expand Down
2 changes: 1 addition & 1 deletion apps/easypid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"babel-plugin-module-resolver": "^4.1.0",
"burnt": "^0.12.2",
"expo": "~51.0.39",
"expo-barcode-scanner": "~13.0.1",
"expo-blur": "^13.0.2",
"expo-camera": "~16.0.9",
"expo-constants": "~16.0.2",
"expo-dev-client": "~4.0.16",
"expo-device": "~6.0.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/paradym/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"babel-plugin-module-resolver": "^4.1.0",
"burnt": "^0.12.2",
"expo": "~51.0.39",
"expo-barcode-scanner": "~13.0.1",
"expo-camera": "~16.0.9",
"expo-constants": "~16.0.2",
"expo-dev-client": "~4.0.16",
"expo-font": "~12.0.7",
Expand Down
2 changes: 1 addition & 1 deletion apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@storybook/addons": "^7.6.17",
"burnt": "^0.12.2",
"expo": "~51.0.39",
"expo-barcode-scanner": "~13.0.1",
"expo-camera": "~16.0.9",
"expo-constants": "~16.0.2",
"expo-dev-client": "~4.0.16",
"expo-font": "~12.0.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/scanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"devDependencies": {
"@react-native-masked-view/masked-view": "0.3.1",
"@types/react": "~18.2.79",
"expo-barcode-scanner": "~13.0.1",
"expo-camera": "~16.0.9",
"react-native": "catalog:"
},
"peerDependencies": {
"@react-native-masked-view/masked-view": "0.3.1",
"expo-barcode-scanner": "~13.0.1",
"expo-camera": "~16.0.9",
"react-native": "catalog:"
}
}
71 changes: 37 additions & 34 deletions packages/scanner/src/Scanner.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { StyleProp, ViewStyle } from 'react-native'

import { AnimatePresence, Button, Heading, LucideIcons, Page, Paragraph, Spacer, XStack, YStack } from '@package/ui'
import { AnimatePresence, Button, Heading, HeroIcons, Page, Paragraph, Spacer, XStack, YStack } from '@package/ui'
import MaskedView from '@react-native-masked-view/masked-view'
import { BarCodeScanner as ExpoBarCodeScanner } from 'expo-barcode-scanner'
import { Camera, CameraView } from 'expo-camera'
import { useCallback, useEffect, useState } from 'react'
import { Dimensions, Linking, Platform, StyleSheet } from 'react-native'

Expand All @@ -16,12 +16,12 @@ export const QrScanner = ({ onScan, onCancel, helpText }: BarcodeScannerProps) =
const [hasPermission, setHasPermission] = useState<boolean>()

useEffect(() => {
const getBarCodeScannerPermissions = async () => {
const { status } = await ExpoBarCodeScanner.requestPermissionsAsync()
const getCameraPermissions = async () => {
const { status } = await Camera.requestCameraPermissionsAsync()
setHasPermission(status === 'granted')
}

void getBarCodeScannerPermissions()
void getCameraPermissions()
}, [])

const _openAppSetting = useCallback(() => {
Expand All @@ -44,7 +44,7 @@ export const QrScanner = ({ onScan, onCancel, helpText }: BarcodeScannerProps) =
Please allow camera access
</Heading>
<Paragraph textAlign="center">
This allows Paradym to scan QR codes that include credentials or data requests.
This allows the app to scan QR codes that include credentials or data requests.
</Paragraph>
<Button.Text onPress={() => _openAppSetting()}>Open settings</Button.Text>
</Page>
Expand All @@ -54,15 +54,44 @@ export const QrScanner = ({ onScan, onCancel, helpText }: BarcodeScannerProps) =
return (
<Page f={1} fd="column" jc="space-between" bg="$black">
{hasPermission && (
<ExpoBarCodeScanner
<CameraView
style={[cameraStyle, StyleSheet.absoluteFill]}
onBarCodeScanned={({ data }) => onScan(data)}
onBarcodeScanned={({ data }) => onScan(data)}
barcodeScannerSettings={{
barcodeTypes: ['qr'],
}}
/>
)}
<YStack zi="$5" ai="center">
<Heading variant="h1" lineHeight={36} ta="center" dark py="$8" maxWidth="80%">
Use the camera to scan a QR code
</Heading>
<XStack maxHeight="$10">
<AnimatePresence>
{helpText && (
<XStack
key="scan-help-text"
enterStyle={{ opacity: 0, scale: 0.5, y: 25 }}
exitStyle={{ opacity: 0, scale: 1, y: 25 }}
y={0}
opacity={1}
scale={1}
animation="quick"
bg="$warning-500"
br="$12"
px="$3"
h="$3"
gap="$2"
ai="center"
>
<HeroIcons.ExclamationTriangleFilled size={14} mt="$0.5" color="$grey-800" />
<Paragraph variant="sub" fontWeight="$semiBold" color="$grey-800">
{helpText}
</Paragraph>
</XStack>
)}
</AnimatePresence>
</XStack>
</YStack>
<MaskedView
style={StyleSheet.absoluteFill}
Expand Down Expand Up @@ -98,32 +127,6 @@ export const QrScanner = ({ onScan, onCancel, helpText }: BarcodeScannerProps) =
</Button.Solid>
</XStack>
)}
{/* TODO move this to the top */}
<XStack maxHeight="$10">
<AnimatePresence>
{helpText && (
<XStack
key="scan-help-text"
enterStyle={{ opacity: 0, scale: 0.5, y: 25 }}
exitStyle={{ opacity: 0, scale: 1, y: 25 }}
y={0}
opacity={1}
scale={1}
animation="quick"
bg="$warning-500"
br="$12"
px="$4"
py="$2"
jc="center"
ai="center"
gap="$2"
>
<LucideIcons.AlertOctagon size={16} />
<Paragraph variant="sub">{helpText}</Paragraph>
</XStack>
)}
</AnimatePresence>
</XStack>
<Spacer />
</YStack>
</Page>
Expand Down
66 changes: 35 additions & 31 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 1b2ff79

Please sign in to comment.