Files
FarmaFinder/apps/frontend-mobile/app/(tabs)/index.tsx
T
Antoni Nuñez Romeu 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
feat(i18n-mobile): add bilingual support (Català / Castellano) for React Native app
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.
2026-07-17 10:22:41 +02:00

166 lines
4.6 KiB
TypeScript

import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Image, useWindowDimensions } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { useRouter } from 'expo-router';
import { useThemeContext } from '../../components/ThemeProvider';
import { useTranslation } from '../../src/i18n';
import { spacing, borderRadius, shadows } from '../../constants/theme';
const TABLET_MIN_WIDTH = 768;
export default function HomeScreen() {
const router = useRouter();
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const { colors } = useThemeContext();
const { t } = useTranslation();
return (
<View style={[styles.container, { backgroundColor: colors.background }]}>
<View style={[styles.hero, isTablet && styles.heroTablet]}>
<Image
source={require('../../assets/farmaclic_logo.png')}
style={[styles.logo, isTablet && styles.logoTablet]}
resizeMode="contain"
/>
<Text style={[styles.brandName, isTablet && styles.brandNameTablet, { color: colors.text }]}>FarmaClic</Text>
<Text style={[styles.description, isTablet && styles.descriptionTablet, { color: colors.textSecondary }]}>
{t('home.description')}
</Text>
</View>
<View style={[styles.cards, isTablet && styles.cardsTablet]}>
<TouchableOpacity
style={[styles.card, isTablet && styles.cardTablet, { backgroundColor: colors.primaryContainer }]}
activeOpacity={0.85}
onPress={() => router.push('/(tabs)/search')}
>
<View style={[styles.cardIcon, styles.cardIconSearch]}>
<Ionicons name="search" size={isTablet ? 28 : 24} color={colors.onPrimaryContainer} />
</View>
<View style={styles.cardContent}>
<Text style={[styles.cardLabel, isTablet && styles.cardLabelTablet, { color: colors.onPrimaryContainer }]}>{t('home.searchMedicine')}</Text>
<Ionicons name="chevron-forward" size={20} color={colors.onPrimaryContainer} style={{ opacity: 0.7 }} />
</View>
</TouchableOpacity>
<TouchableOpacity
style={[styles.card, styles.cardScan, isTablet && styles.cardTablet]}
activeOpacity={0.85}
onPress={() => router.push('/scanner')}
>
<View style={[styles.cardIcon, styles.cardIconScan]}>
<Ionicons name="scan" size={isTablet ? 28 : 24} color="#ffffff" />
</View>
<View style={styles.cardContent}>
<Text style={[styles.cardLabel, styles.cardLabelScan, isTablet && styles.cardLabelTablet]}>{t('home.scanTSI')}</Text>
<Ionicons name="chevron-forward" size={20} color="#ffffff" style={{ opacity: 0.7 }} />
</View>
</TouchableOpacity>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: spacing.lg,
gap: spacing.lg,
},
hero: {
alignItems: 'center',
gap: spacing.sm,
marginBottom: spacing.md,
},
heroTablet: {
marginBottom: spacing.xl,
},
logo: {
width: 120,
height: 120,
marginBottom: spacing.xs,
},
logoTablet: {
width: 160,
height: 160,
},
brandName: {
fontSize: 28,
fontWeight: 'bold',
letterSpacing: -0.5,
},
brandNameTablet: {
fontSize: 36,
},
description: {
fontSize: 16,
textAlign: 'center',
maxWidth: 260,
lineHeight: 24,
},
descriptionTablet: {
fontSize: 18,
maxWidth: 400,
lineHeight: 28,
},
cards: {
width: '100%',
maxWidth: 320,
gap: spacing.md,
},
cardsTablet: {
maxWidth: 480,
},
card: {
flexDirection: 'row',
alignItems: 'center',
gap: spacing.md,
borderRadius: borderRadius.lg,
padding: spacing.md,
minHeight: 64,
...shadows.card,
},
cardTablet: {
padding: spacing.lg,
minHeight: 72,
},
cardScan: {
backgroundColor: '#2b5bb5',
},
cardIcon: {
width: 48,
height: 48,
borderRadius: borderRadius.md,
backgroundColor: 'rgba(255, 255, 255, 0.2)',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
},
cardIconSearch: {
backgroundColor: 'rgba(255, 255, 255, 0.3)',
},
cardIconScan: {
backgroundColor: 'rgba(255, 255, 255, 0.2)',
},
cardContent: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
cardLabel: {
fontSize: 18,
fontWeight: '700',
lineHeight: 24,
},
cardLabelTablet: {
fontSize: 20,
},
cardLabelScan: {
color: '#ffffff',
},
});