// State for modal visibility and new food entry
const [modalVisible, setModalVisible] = useState(false);
const [newFood, setNewFood] = useState({
name: '',
calories: '',
protein: '',
carbs: '',
fat: '',
icon: 'food',
});
// State for selected items
const [selectedIds, setSelectedIds] = useState([]);
// State for search query
const [searchQuery, setSearchQuery] = useState('');
// Calculate total nutrients based on filtered items
const filteredFoodItems = foodItems.filter((item) =>
item.name.toLowerCase().includes(searchQuery.toLowerCase())
);
Handler for the logout button
*/
const handleLogout = () => {
Alert.alert(
'Logout',
'Are you sure you want to logout?',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Logout',
style: 'destructive',
onPress: () => signOut(),
},
],
{ cancelable: true }
);
};
/**
If the app is still loading user data, show a loading indicator
*/
if (loading) {
return (
);
}
/**
If no user is logged in, prompt the user to log in
*/
if (!user) {
return (
No user data available. Please log in.
<Button
mode="contained"
onPress={() => navigation.navigate('Login')}
style={styles.loginButton}
accessibilityLabel="Navigate to Login"
{/* Logout Button */}
<Button
mode="contained"
icon="logout"
onPress={handleLogout}
style={styles.logoutButton}
contentStyle={styles.buttonContent}
accessibilityLabel="Logout"
accessibilityHint="Logs you out of the application"
To align the search bar and barcode button in your NutritionScreen to be on the same horizontal level as the user.name in the ProfileScreen, you'll need to adjust the layout and styling accordingly. This typically involves organizing the components within a parent View with a flexDirection of 'row' and ensuring proper alignment and spacing.
Here's a step-by-step guide to achieve this:
Create a Header Section:
Introduce a header section at the top of the NutritionScreen that mirrors the layout of the ProfileScreen's user information.
This header will contain the search bar and barcode button aligned horizontally.
Adjust the Layout:
Use flexDirection: 'row' to arrange the search bar and barcode button side by side.
Utilize alignItems: 'center' to vertically center the components within the row.
Apply appropriate justifyContent to manage the spacing between elements.
Update Styles:
Ensure that the search bar takes up the majority of the horizontal space, while the barcode button maintains a consistent size.
Add padding and margins to achieve a clean and balanced look.
Below is the updated code for NutritionScreen.js with these adjustments:
The search bar stretches to fill the available space.
The barcode button is positioned to the right of the search bar.
Additional Recommendations:
Responsive Design:
Ensure that the layout looks good on various screen sizes and orientations.
Test on both iOS and Android devices/emulators.
Accessibility:
Maintain accessibility labels and roles for better support with screen readers.
Ensure sufficient color contrast between text and background.
Consistent Styling:
If you have common styles across different screens (like headers), consider creating shared style objects or using a component library to maintain consistency.
Optimizing Icons:
If you frequently use the same icons, manage them centrally to avoid redundancy.
Ensure that the chosen icons effectively represent their actions.
Final Thoughts
By organizing the search bar and barcode button within a horizontally aligned View, you can achieve a clean and intuitive layout that mirrors the alignment and design of the user.name in the ProfileScreen. Adjust the styling as needed to fit the overall aesthetic of your application.
If you encounter any specific issues or need further customization, feel free to ask!