ee958d4525
Run Tests on Branches / Detect Changes (push) Successful in 13s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Successful in 1m40s
Run Tests on Branches / Frontend Mobile Tests (push) Successful in 1m37s
Run Tests on Branches / Parapharmacy API Tests (push) Has been skipped
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
Add lightweight i18n system matching the web app architecture.
Language persisted in AsyncStorage('ff-lang').
New files:
- src/i18n/locales/ca.js (~190 translation keys)
- src/i18n/locales/es.js (~190 translation keys)
- src/i18n/LanguageContext.jsx (Provider + AsyncStorage)
- src/i18n/useTranslation.js (hook)
- src/i18n/index.js (barrel export)
Modified 16 files:
- app/_layout.tsx: wrap with LanguageProvider, translate stack titles
- app/(tabs)/_layout.tsx: translate tab bar labels
- app/(tabs)/index.tsx: translate home screen
- app/(tabs)/search.tsx: translate search screen
- app/(tabs)/alerts.tsx: translate alerts screen
- app/(tabs)/profile.tsx: translate profile + add language selector (CA/ES)
- app/(tabs)/scan.tsx: translate scanner screen
- app/auth/login.tsx: translate login/register
- app/medicine/[id].tsx: translate medicine detail
- app/pharmacy/[id].tsx: translate pharmacy detail
- app/product/[source]/[id].tsx: translate product detail
- 5 components: MedicineCard, StockBadge, SearchBar, LoadingSpinner, BarcodeScanner
Language selector in Profile screen (globe icon + CA/ES toggle).
No routes changed. No API calls affected.
205 lines
5.6 KiB
TypeScript
205 lines
5.6 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
|
import { CameraView, useCameraPermissions } from 'expo-camera';
|
|
import { Ionicons } from '@expo/vector-icons';
|
|
import { useThemeContext } from './ThemeProvider';
|
|
import { spacing, borderRadius } from '../constants/theme';
|
|
import { useTranslation } from '../src/i18n';
|
|
|
|
interface BarcodeScannerProps {
|
|
onBarcodeScanned: (barcode: string) => void;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export function BarcodeScanner({ onBarcodeScanned, onClose }: BarcodeScannerProps) {
|
|
const [permission, requestPermission] = useCameraPermissions();
|
|
const [scanned, setScanned] = useState(false);
|
|
const { colors } = useThemeContext();
|
|
const { t } = useTranslation();
|
|
|
|
if (!permission) {
|
|
return <View style={styles.container} />;
|
|
}
|
|
|
|
if (!permission.granted) {
|
|
return (
|
|
<View style={[styles.permissionContainer, { backgroundColor: colors.background }]}>
|
|
<Ionicons name="camera" size={64} color={colors.textSecondary} />
|
|
<Text style={[styles.permissionTitle, { color: colors.text }]}>{t('barcodeScanner.permissionRequired')}</Text>
|
|
<Text style={[styles.permissionText, { color: colors.textSecondary }]}>
|
|
{t('barcodeScanner.permissionDesc')}
|
|
</Text>
|
|
<TouchableOpacity style={[styles.permissionButton, { backgroundColor: colors.primary }]} onPress={requestPermission}>
|
|
<Text style={styles.permissionButtonText}>{t('barcodeScanner.grantPermission')}</Text>
|
|
</TouchableOpacity>
|
|
<TouchableOpacity style={styles.cancelButton} onPress={onClose}>
|
|
<Text style={[styles.cancelButtonText, { color: colors.textSecondary }]}>{t('barcodeScanner.cancel')}</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const handleBarCodeScanned = ({ type, data }: { type: string; data: string }) => {
|
|
if (scanned) return;
|
|
setScanned(true);
|
|
onBarcodeScanned(data);
|
|
};
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
<CameraView
|
|
style={StyleSheet.absoluteFillObject}
|
|
facing="back"
|
|
barcodeScannerSettings={{
|
|
barcodeTypes: ['ean13', 'ean8', 'upc_a', 'upc_e'],
|
|
}}
|
|
onBarcodeScanned={scanned ? undefined : handleBarCodeScanned}
|
|
/>
|
|
|
|
<View style={styles.overlay}>
|
|
<View style={styles.scannerFrame}>
|
|
<View style={[styles.corner, styles.topLeft, { borderColor: colors.primary }]} />
|
|
<View style={[styles.corner, styles.topRight, { borderColor: colors.primary }]} />
|
|
<View style={[styles.corner, styles.bottomLeft, { borderColor: colors.primary }]} />
|
|
<View style={[styles.corner, styles.bottomRight, { borderColor: colors.primary }]} />
|
|
</View>
|
|
|
|
<Text style={styles.instruction}>
|
|
{t('barcodeScanner.scanningHint')}
|
|
</Text>
|
|
|
|
<TouchableOpacity style={styles.closeButton} onPress={onClose}>
|
|
<Ionicons name="close" size={24} color={colors.textInverse} />
|
|
</TouchableOpacity>
|
|
</View>
|
|
|
|
{scanned && (
|
|
<View style={styles.scannedOverlay}>
|
|
<TouchableOpacity
|
|
style={[styles.scanAgainButton, { backgroundColor: colors.primary }]}
|
|
onPress={() => setScanned(false)}
|
|
>
|
|
<Text style={styles.scanAgainText}>{t('barcodeScanner.scanAgain')}</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
)}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: '#000',
|
|
},
|
|
permissionContainer: {
|
|
flex: 1,
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
padding: spacing.xl,
|
|
},
|
|
permissionTitle: {
|
|
fontSize: 20,
|
|
fontWeight: 'bold',
|
|
marginTop: spacing.lg,
|
|
},
|
|
permissionText: {
|
|
fontSize: 16,
|
|
textAlign: 'center',
|
|
marginTop: spacing.sm,
|
|
marginBottom: spacing.xl,
|
|
},
|
|
permissionButton: {
|
|
borderRadius: borderRadius.md,
|
|
paddingVertical: spacing.md,
|
|
paddingHorizontal: spacing.xl,
|
|
},
|
|
permissionButtonText: {
|
|
color: '#ffffff',
|
|
fontSize: 16,
|
|
fontWeight: '600',
|
|
},
|
|
cancelButton: {
|
|
marginTop: spacing.md,
|
|
},
|
|
cancelButtonText: {
|
|
fontSize: 14,
|
|
},
|
|
overlay: {
|
|
flex: 1,
|
|
backgroundColor: 'transparent',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
},
|
|
scannerFrame: {
|
|
width: 250,
|
|
height: 250,
|
|
borderWidth: 2,
|
|
borderColor: 'transparent',
|
|
position: 'relative',
|
|
},
|
|
corner: {
|
|
position: 'absolute',
|
|
width: 30,
|
|
height: 30,
|
|
},
|
|
topLeft: {
|
|
top: 0,
|
|
left: 0,
|
|
borderTopWidth: 3,
|
|
borderLeftWidth: 3,
|
|
},
|
|
topRight: {
|
|
top: 0,
|
|
right: 0,
|
|
borderTopWidth: 3,
|
|
borderRightWidth: 3,
|
|
},
|
|
bottomLeft: {
|
|
bottom: 0,
|
|
left: 0,
|
|
borderBottomWidth: 3,
|
|
borderLeftWidth: 3,
|
|
},
|
|
bottomRight: {
|
|
bottom: 0,
|
|
right: 0,
|
|
borderBottomWidth: 3,
|
|
borderRightWidth: 3,
|
|
},
|
|
instruction: {
|
|
color: '#ffffff',
|
|
fontSize: 14,
|
|
textAlign: 'center',
|
|
marginTop: spacing.xl,
|
|
backgroundColor: 'rgba(0,0,0,0.6)',
|
|
paddingHorizontal: spacing.md,
|
|
paddingVertical: spacing.sm,
|
|
borderRadius: borderRadius.sm,
|
|
},
|
|
closeButton: {
|
|
position: 'absolute',
|
|
top: spacing.xl,
|
|
right: spacing.xl,
|
|
backgroundColor: 'rgba(0,0,0,0.6)',
|
|
borderRadius: 20,
|
|
padding: spacing.sm,
|
|
},
|
|
scannedOverlay: {
|
|
position: 'absolute',
|
|
bottom: spacing.xxl,
|
|
left: spacing.xl,
|
|
right: spacing.xl,
|
|
},
|
|
scanAgainButton: {
|
|
borderRadius: borderRadius.md,
|
|
padding: spacing.md,
|
|
alignItems: 'center',
|
|
},
|
|
scanAgainText: {
|
|
color: '#ffffff',
|
|
fontSize: 16,
|
|
fontWeight: '600',
|
|
},
|
|
});
|