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.
162 lines
4.3 KiB
TypeScript
162 lines
4.3 KiB
TypeScript
import React, { useEffect, useRef } from 'react';
|
|
import { Stack } from 'expo-router';
|
|
import { StatusBar } from 'expo-status-bar';
|
|
import { Image, StyleSheet, View } from 'react-native';
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
import { useAuthStore } from '../store/authStore';
|
|
import { registerForPushNotifications, addNotificationListener, addNotificationResponseListener } from '../services/notifications';
|
|
import { ThemeProvider, useThemeContext } from '../components/ThemeProvider';
|
|
import { LanguageProvider, useTranslation } from '../src/i18n';
|
|
import { initFaro } from '../services/faro';
|
|
|
|
// Boot Faro RUM once, as early as possible.
|
|
initFaro();
|
|
|
|
const queryClient = new QueryClient();
|
|
|
|
const bgLight = require('../assets/bg.png');
|
|
const bgDark = require('../assets/bg_dark.png');
|
|
|
|
function RootLayoutInner() {
|
|
const { checkAuth } = useAuthStore();
|
|
const { colors, isDark } = useThemeContext();
|
|
const { t } = useTranslation();
|
|
const notificationListener = useRef<ReturnType<typeof addNotificationListener>>();
|
|
const responseListener = useRef<ReturnType<typeof addNotificationResponseListener>>();
|
|
|
|
useEffect(() => {
|
|
checkAuth();
|
|
|
|
registerForPushNotifications();
|
|
|
|
notificationListener.current = addNotificationListener((notification) => {
|
|
console.log('Notification received:', notification);
|
|
});
|
|
|
|
responseListener.current = addNotificationResponseListener((response) => {
|
|
console.log('Notification clicked:', response);
|
|
});
|
|
|
|
return () => {
|
|
notificationListener.current?.remove();
|
|
responseListener.current?.remove();
|
|
};
|
|
}, []);
|
|
|
|
return (
|
|
<>
|
|
<Stack
|
|
screenOptions={{
|
|
headerStyle: { backgroundColor: colors.card },
|
|
headerTintColor: colors.primary,
|
|
headerTitleStyle: { color: colors.text, fontWeight: '600' },
|
|
contentStyle: { backgroundColor: 'transparent' },
|
|
}}
|
|
>
|
|
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
|
<Stack.Screen
|
|
name="medicine/[id]"
|
|
options={{ title: t('stack.medicine') }}
|
|
/>
|
|
<Stack.Screen
|
|
name="pharmacy/[id]"
|
|
options={{ title: t('stack.pharmacy') }}
|
|
/>
|
|
<Stack.Screen
|
|
name="scanner"
|
|
options={{
|
|
title: t('stack.scanner'),
|
|
headerShown: false,
|
|
}}
|
|
/>
|
|
<Stack.Screen
|
|
name="auth/login"
|
|
options={{
|
|
title: t('stack.login'),
|
|
headerShown: false,
|
|
}}
|
|
/>
|
|
<Stack.Screen
|
|
name="auth/register"
|
|
options={{
|
|
title: t('stack.register'),
|
|
headerShown: false,
|
|
}}
|
|
/>
|
|
</Stack>
|
|
<StatusBar style={isDark ? 'light' : 'auto'} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
function ThemedBackground({ children }: { children: React.ReactNode }) {
|
|
const { isDark } = useThemeContext();
|
|
|
|
return (
|
|
<View style={styles.root}>
|
|
<Image
|
|
source={isDark ? bgDark : bgLight}
|
|
style={styles.bgImage}
|
|
resizeMode="cover"
|
|
/>
|
|
<View style={[styles.overlay, isDark && styles.overlayDark]} pointerEvents="none" />
|
|
<View style={styles.content} pointerEvents="auto">
|
|
{children}
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
export default function RootLayout() {
|
|
return (
|
|
<GestureHandlerRootView style={styles.root}>
|
|
<SafeAreaProvider>
|
|
<QueryClientProvider client={queryClient}>
|
|
<LanguageProvider>
|
|
<ThemeProvider>
|
|
<ThemedBackground>
|
|
<RootLayoutInner />
|
|
</ThemedBackground>
|
|
</ThemeProvider>
|
|
</LanguageProvider>
|
|
</QueryClientProvider>
|
|
</SafeAreaProvider>
|
|
</GestureHandlerRootView>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
root: {
|
|
flex: 1,
|
|
},
|
|
bgImage: {
|
|
position: 'absolute',
|
|
left: 0,
|
|
right: 0,
|
|
top: 0,
|
|
bottom: 0,
|
|
width: '100%',
|
|
height: '100%',
|
|
opacity: 0.55,
|
|
zIndex: 0,
|
|
},
|
|
overlay: {
|
|
position: 'absolute',
|
|
left: 0,
|
|
right: 0,
|
|
top: 0,
|
|
bottom: 0,
|
|
backgroundColor: 'rgba(255, 252, 245, 0.48)',
|
|
zIndex: 1,
|
|
},
|
|
overlayDark: {
|
|
backgroundColor: 'rgba(0, 0, 0, 0.25)',
|
|
},
|
|
content: {
|
|
flex: 1,
|
|
zIndex: 2,
|
|
},
|
|
});
|