We're going to be building a Calories Counter and Meal Planner application using React Native and Expo. This application will allow users to set their health goals, choose items from a food database to track caloric intake, and plan meals accordingly. As we work through this project, we'll be learning and applying key concepts we saw during the course, including user input handling, API integration, state management, and UI styling. Let's dive right in.
Rules
Each item is mandatory
- Teams of 2 students
- Use React Native AND Expo
- The two students have to commit to the project repository
- The use of GPT is prohibited and punishable by a 0/20
Module 1: Setting up the project
Our first step in this journey is to set up our development environment and initiate our project. Here are the steps to follow:
- Step 1: Create a New Expo Project
- Step 2: Install eslint and prettier
- Step 3: Install React Navigation
- Step 4: Run the app on your phone using Expo Go
After this we will create 3 tabs using a Bottom Tab Navigator
- Tab 1: Health goals
- Tab 2: Food database
- Tab 3: Meal planning
Module 2 : Health goals
In this module, we will be implementing the functionality for users to set their health goals and receive a daily caloric intake suggestion based on these goals. The main objective of this module is to understand how to capture user inputs, handle state management in React Native, and apply basic mathematical models in software applications.
Here's a step-by-step breakdown:
Step 1: Creating a Form for User Input
Firstly, we need to create a form where users can input their personal details and health goals. The form should include fields for:
- Age
- Gender
- Height
- Weight
- Activity level (with options like sedentary, light exercise, moderate exercise, heavy exercise, extra active)
- Health goal (with options like weight loss, weight maintenance, weight gain)
You can use the TextInput and Picker components from React Native for this.
Step 2: Handling User Input
Once the form is set up, we need to handle user input. This involves setting up state variables for each input field using the useState hook and updating these variables as the user enters their data.
Also, you should add proper form validation (disable the button one of the fields is empty for example).
Step 3: Calculating BMR Using the Harris-Benedict Equation
The next step is to calculate the user's Basal Metabolic Rate (BMR) using the Harris-Benedict equation. The equation is different for men and women:
For men: BMR = 88.362 + (13.397 * weight in kg) + (4.799 * height in cm) - (5.677 * age in years)
For women: BMR = 447.593 + (9.247 * weight in kg) + (3.098 * height in cm) - (4.330 * age in years)
We will need to create a function that takes the user's age, gender, height, and weight as input, and returns the BMR as output.
Step 4: Adjusting BMR Based on Activity Level
The BMR needs to be adjusted based on the user's activity level to get the total amount of calories they need to maintain their current weight. The adjustment factors are as follows:
- Sedentary (little or no exercise):
BMR * 1.2 - Lightly active (light exercise/sports 1-3 days/week):
BMR * 1.375 - Moderately active (moderate exercise/sports 3-5 days/week):
BMR * 1.55 - Very active (hard exercise/sports 6-7 days a week):
BMR * 1.725 - Super active (very hard exercise/physical job & exercise 2x/day):
BMR * 1.9
We need to add this calculation to the function created in the previous step.
Step 5: Adjusting Caloric Intake Based on Health Goal
Finally, the total caloric intake needs to be adjusted based on the user's health goal. If the user wants to lose weight, subtract 10% calories from the total. If the user wants to gain weight, add 10% calories to the total. If the user wants to maintain weight, the total caloric intake remains the same.
Step 6: Displaying the Result to the User
Once the daily caloric intake has been calculated, it should be displayed to the user. we can create a new component to display the result, or they can display it in an existing component.
Absolutely! Welcome back, students. We've made great progress on our Calories Counter and Meal Planner application, having already set up our project and implemented the functionality for users to set their health goals. Now, it's time to move on to the next part of our application: the Food Database.
Module 3: Food Database
In this module, we're going to a feature where users can search for foods and see their nutritional information. This will involve integrating with a nutrition API to get this information, and creating a user interface where users can search for foods and view their details. Let's dive into the steps.
Step 1: Choosing a Nutrition API
There are several nutrition APIs available that provide detailed information about different foods, including their calorie content and other nutritional facts. Some examples include these: https://developer.edamam.com/food-database-api or https://www.nutritionix.com/business/api. You'll need to choose one of these APIs (or another of your choice), sign up to get an API key, and familiarize yourself with the API documentation to understand how to make requests.
Step 2: Creating the Search Interface
Next, you'll create a new screen in your application for the food database. This screen should include a search bar where users can enter the name of a food. You can use the TextInput component from React Native for this.
Step 3: Handling User Input
Set up a state variable for the search query and update this variable as the user types into the search bar. You can do this using the useState and onChangeText props. Add a submit button to launch the search.
Step 4: Fetching Data from the API
When the user submits their search, make a request to the nutrition API to get information about the food. You'll need to refer to your chosen API's documentation to know exactly how to structure this request, but typically it will involve sending a GET request to a specific endpoint, with the search query and your API key included as parameters.
Step 5: Displaying the Results
Once you receive the response from the API, extract the relevant information and display it to the user. This could include the food's name, calorie content, and other nutritional facts. Ensure to handle any errors that might occur, such as the food not being found in the database.
Step 6: Selecting Food for Meal Planning
After displaying the search results, allow the user to select a food item to add to their meal plan. You will need to create some form of selection interface – this could be as simple as the reult item being a TouchableOpacity with a Text.
When a food item is selected, prompt the user to specify the quantity the day AND which meal this food item should be added to (Breakfast, Lunch, Dinner, or Snack). You can create a modal or a new screen to handle this. Use the Picker component from React Native for the meal type selection.
Step 7: Updating the Meal Plan
Upon the user's confirmation, update the user's meal plan with the chosen food item. The meal plan could be an object in your application's state that stores an array of food items for each day and each meal type. Here is an example structure:
{
"Day": {
"Breakfast": [],
"Lunch": [],
"Snack": [],
"Dinner": []
}
}
Each time a food item is added, push it to the appropriate array in this object.
Module 4: Meal Planning
In this module, we'll develop the core feature of our application: the Meal Planner. This will allow users to plan their meals for the week and view a summary of the planned meals along with the total calories for each day. Let's get started!
Step 1: Creating the Meal Planner Interface
First, create a new screen in your application for the Meal Planner. This screen should include a view for each day of the week, and within each day, a section for each meal (Breakfast, Lunch, Dinner, Snack). You may use the View and Text components from React Native for this purpose.
Step 2: Displaying the Meal Plan
Next, you'll need to display the user's meal plan in the Meal Planner screen.
For each day and each meal, list out the food items that the user has added to their meal plan. You might want to create a separate component for each meal that takes the array of food items as a prop and renders them in a list.
Step 3: Calculating Daily Calories
For each day, calculate the total calories of all food items in the meal plan. This can be done by looping through the food items for each meal, summing up their calorie content, and displaying the total.
Step 4: Adding and Removing Food Items
Give the user the option to add more food items to their meal plan from the food database, or remove existing items. When the user chooses to add an item, redirect them to the food database search screen, and after they've selected a food item, add it to the appropriate meal. When the user chooses to remove an item, simply remove it from the meal plan object.
Step 5: Saving the Meal Plan
Finally, consider how you want to handle data persistence. When the user closes and reopens the app, their meal plan should be saved.
Grading grid
Here is the grading grid for this project. Note that bonus points can be awarded for outstanding work or additional features (using an external library, outstanding styling, adding an icon or a splashcreen...). Please be creative :)
| Criteria | Unsatisfactory | Satisfactory | Good | Excellent | Outstanding |
|---|---|---|---|---|---|
| Project Setup & Code Organization (2 points) | Project setup is incorrect and/or code is disorganized or unreadable. | Project setup is mostly correct and code is somewhat organized and readable. | Project setup is correct, code is organized, and most naming conventions are followed. | Project setup is correct and efficient, code is well-organized, and naming conventions are followed. | Project setup is correct and efficient, code is extremely well-organized, with clear, thoughtful naming conventions. |
| Implementation of Health Goals (5 points) | The health goals functionality is missing or implemented incorrectly. | The health goals functionality is partially implemented, with some minor errors. | The health goals functionality is mostly implemented correctly and works as expected. | The health goals functionality is fully implemented, works as expected, and includes robust error checking. | The health goals functionality is fully implemented, works as expected, includes robust error checking, and demonstrates a deep understanding of the underlying concepts. |
| Implementation of Food Database (5 points) | The food database functionality is missing or implemented incorrectly. | The food database functionality is partially implemented, with some minor errors. | The food database functionality is mostly implemented correctly and works as expected. | The food database functionality is fully implemented, works as expected, and includes robust error checking. | The food database functionality is fully implemented, works as expected, includes robust error checking, and demonstrates a deep understanding of the underlying concepts. |
| Implementation of Meal Planning (5 points) | The meal planning functionality is missing or implemented incorrectly. | The meal planning functionality is partially implemented, with some minor errors. | The meal planning functionality is mostly implemented correctly and works as expected. | The meal planning functionality is fully implemented, works as expected, and includes robust error checking. | The meal planning functionality is fully implemented, works as expected, includes robust error checking, and demonstrates a deep understanding of the underlying concepts. |
| UI Design & Styling (3 points) | The application's UI is poorly designed and/or styled. | The application's UI is somewhat well-designed and styled, with some minor issues. | The application's UI is well-designed and styled, and is mostly consistent across the application. | The application's UI is very well-designed and styled, and is consistent across the application. | The application's UI is exceptionally well-designed and styled, demonstrating a high level of creativity and attention to detail, and is consistent across the application. |
| Overall Functionality | The application has many bugs or is non-functional. | The application has some minor bugs, but is mostly functional. | The application is functional and behaves mostly as expected. | The application is fully functional, behaves as expected, and includes robust error checking. | The application is fully functional, behaves as expected, includes robust error checking, and demonstrates a deep understanding of the underlying concepts. |
Deliverables
- Project Setup and Code Repository: Students should deliver a properly setup project with a GitHub repository. The repository should contain clear, well-organized code and a README file describing your team, the project, how to set it up, and how to use it. Important: I need to see the two teammates git users committing to the project, otherwise you'll face a penalty of 5 points
- Documentation: Objective, application's architecture, succeded features, unsucceded features, roadmap and screenshots, and the difficulties you faced while developing it.
- Demo: Students should prepare a video presentation showcasing their application and all the requested features. You face a penalty of 5 points if the demo is not included.
Please put the documentation (as a PDF) and the demo (as a MP4 video) in the repo.
Remember, these deliverables are not just about completing the project but also about demonstrating a clear understanding of the underlying concepts and skills. It's important to take the time to understand each step, ask questions when necessary, and strive for continuous learning and improvement.
Deadline
The final project, including all deliverables, must be submitted no later than 23:59 on June 21, 2023. Please note that late submissions may not be accepted, so plan your work accordingly to meet this deadline.