8. Home screen
List products from the Store API on the home screen.
On this page
In this step, you'll create the home screen of the app. It will display a hero image with a list of products retrieved from the Aiminaabee backend.
To implement the home screen, you'll create:
- Necessary utilities and components for the home screen.
- The home screen and navigation setup.
Add Price Formatting Utility
First, you'll create a utility function to format prices based on the selected region's currency.
Create the file lib/format-price.ts with the following content:
ts
The formatPrice function takes an amount and a currency code as parameters. It formats the amount using the Intl.NumberFormat API to display it in the appropriate currency format.
Add Loading Component
Next, you'll create a loading component that can be reused across the app to indicate loading states.
Create the file components/loading.tsx with the following content:
tsx
The Loading component displays a spinner and an optional message.
Add Product Card Component
Next, you'll create a product card component to display individual products on the home screen.
Create the file components/product-card.tsx with the following content:
tsx
The ProductCard component receives a product as a prop.
It displays the product's thumbnail image, title, and price formatted using the formatPrice utility. When the card is pressed, it navigates to the product detail screen that you'll add later.
Add Home Screen
Next, you'll add the home screen that displays a hero image and a list of products.
Your app will have a tab-based navigation structure, with a tab for the home screen, and another you'll add later for the cart.
So, to set up the tab navigation within the drawer navigator, create the directory app/(drawer)/(tabs).
Then, to create the home screen, create the file app/(drawer)/(tabs)/(home)/index.tsx with the following content:
tsx
The home screen component fetches products from the Aiminaabee backend based on the selected region. It manages loading, refreshing, and error states.
Next, you'll add the return statement to render the home screen UI. Replace the // TODO add return statement comment with the following:
tsx
You handle three main states in the return statement:
- Loading State: If the products are still loading, you display the
Loadingcomponent with a message. - Error State: If there was an error fetching the products, you display an error message.
- Success State: If the products are successfully fetched, you render a
FlatListto display the products in a grid layout. The list includes a header with a hero image and a section title.
You also configure the FlatList to support pull-to-refresh functionality and handle empty states.
Next, you'll add stack navigation for the home screen, which will later allow you to add a product detail screen.
Create the file app/(drawer)/(tabs)/(home)/_layout.tsx with the following content:
tsx
The HomeStackLayout component sets up a stack navigator for the home screen. It adds a header with a title and a menu button to open the drawer navigator.
Next, you'll add the tab navigation layout to include the home screen tab.
Create the file app/(drawer)/(tabs)/_layout.tsx with the following content:
tsx
The TabLayout component sets up a tab navigator using Expo Router's Tabs component. It adds a tab for the home screen with an icon and title.
An index tab is also specified to redirect to the home screen, ensuring it's always the default tab when the app opens.
So, create the file app/(drawer)/(tabs)/index.tsx with the following content:
tsx
The MainScreen component redirects to the home screen tab when accessed.
If you get a type error regarding the href prop in the Redirect component, wait until the next time you run the project. The Expo Router types should update and the error should go away.
Add Tabs to Drawer Navigator
Finally, you'll add the tab navigator to the drawer navigator.
In app/(drawer)/_layout.tsx, update the return statement to replace the TODO comment with the tabs screen:
tsx
The drawer navigator now includes the tab navigator as its main screen.
Test the Home Screen
You can now test the home screen of your app.
There are different ways to run the React Native app, which you can learn about in Expo's documentation. The recommended way is to install the Expo Go app on your mobile device and run the app on it.
Before you run your app, start the Aiminaabee backend by running the following command in the Aiminaabee project directory:
bash
Then, run the following command in your Expo project directory to start the Expo server:
bash
In the terminal, you should see a QR code. Scan it using your device to open the app in Expo Go.
When the app opens, you'll see a home screen displaying a hero image and a list of products fetched from the Aiminaabee application.
Clicking on a product won't do anything yet, as you haven't implemented the product detail screen. You'll add it in the next step.

If you click the menu icon in the top-left corner, the drawer navigator will open, allowing you to select the region using the region selector you implemented earlier.

Next: 9. Product details