Files
FarmaFinder/apps/frontend-mobile/components/SearchBar.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

102 lines
2.7 KiB
TypeScript

import React, { useState } from 'react';
import { View, TextInput, StyleSheet, TouchableOpacity, useWindowDimensions } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { useThemeContext } from './ThemeProvider';
import { spacing, borderRadius } from '../constants/theme';
import { useTranslation } from '../src/i18n';
const TABLET_MIN_WIDTH = 768;
interface SearchBarProps {
placeholder?: string;
onSearch: (query: string) => void;
value?: string;
onChangeText?: (text: string) => void;
}
export function SearchBar({
placeholder,
onSearch,
value,
onChangeText
}: SearchBarProps) {
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const { colors } = useThemeContext();
const { t } = useTranslation();
const [localValue, setLocalValue] = useState(value || '');
const handleChange = (text: string) => {
setLocalValue(text);
onChangeText?.(text);
};
const handleSubmit = () => {
onSearch(localValue);
};
const handleClear = () => {
setLocalValue('');
onChangeText?.('');
onSearch('');
};
return (
<View style={[styles.container, isTablet && styles.containerTablet, { backgroundColor: colors.card }]}>
<Ionicons name="search" size={20} color={colors.textSecondary} style={styles.icon} />
<TextInput
style={[styles.input, isTablet && styles.inputTablet, { color: colors.text }]}
placeholder={placeholder ?? t('search.placeholder')}
placeholderTextColor={colors.textSecondary}
value={localValue}
onChangeText={handleChange}
onSubmitEditing={handleSubmit}
returnKeyType="search"
autoCorrect={false}
/>
{localValue.length > 0 && (
<TouchableOpacity onPress={handleClear} style={styles.clearButton}>
<Ionicons name="close-circle" size={20} color={colors.textSecondary} />
</TouchableOpacity>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
borderRadius: borderRadius.lg,
paddingHorizontal: spacing.md,
paddingVertical: spacing.sm + 2,
marginVertical: spacing.sm,
alignSelf: 'center',
width: '80%',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.06,
shadowRadius: 8,
elevation: 2,
},
containerTablet: {
paddingHorizontal: spacing.lg,
paddingVertical: spacing.md,
},
icon: {
marginRight: spacing.sm,
},
input: {
flex: 1,
fontSize: 16,
paddingVertical: spacing.xs,
},
inputTablet: {
fontSize: 18,
paddingVertical: spacing.sm,
},
clearButton: {
marginLeft: spacing.sm,
},
});