9. Product details
Show a product, pick a variant, and add it to the cart.
On this page
In this step, you'll create the product detail screen that displays detailed information about a selected product.
You'll create the necessary components and utilities first, then implement the product detail screen and navigation.
Add Button Component
First, you'll create a button component that can be reused across the app.
Create the file components/ui/button.tsx with the following content:
tsx
The Button component accepts props for the title, variant (primary or secondary), loading state, and other touchable opacity props.
Add Product Image Slider Component
Next, you'll create a product image slider component to display multiple images of a product.
Create the file components/product-image-slider.tsx with the following content:
tsx
The ProductImageSlider component receives an array of image URLs as a prop and displays them in a horizontally scrollable FlatList. It also includes pagination dots to indicate the current image being viewed.
Add Product Skeleton Component
Next, you'll create a skeleton component to display while the product details are loading. This improves the user experience by providing a visual placeholder.
Create the file components/product-skeleton.tsx with the following content:
tsx
The ProductSkeleton component uses animated views to create a shimmering effect for various sections of the product detail screen, including the image, title, and buttons.
Add Toast Component
Next, you'll create a toast component to display brief messages to the user, such as confirming that an item has been added to the cart.
Create the file components/ui/toast.tsx with the following content:
tsx
The Toast component accepts props for the message, visibility, hide callback, duration, and type. It uses animated values to create fade-in and slide-up effects when the toast appears and disappears.
Add Inventory Utility
Next, you'll create a utility function to check if a product variant is in stock.
Create the file lib/inventory.ts with the following content:
ts
The isVariantInStock function checks if a product variant is in stock. A variant is considered in stock if:
manage_inventoryis false (inventory tracking is disabled), ORinventory_quantityis greater than 0.
Implement Product Detail Screen
You can now implement the product detail screen using the components and utilities you've created.
Create the file app/(drawer)/(tabs)/(home)/product/[id].tsx with the following content:
tsx
The ProductDetailsScreen includes the following variables:
id: The product ID from the URL parameters.colorSchemeandcolors: For theming based on the current color scheme.addToCart: Function to add items to the cart from the cart context.selectedRegion: The currently selected region from the region context.product: The product details fetched from the backend.selectedOptions: The currently selected product options, such as size or color.quantity: The quantity of the product to add to the cart.loading: Loading state for fetching product details.addingToCart: Loading state for adding the product to the cart.error: Error message if fetching product details fails.toastVisibleandtoastMessage: For displaying toast messages.
Next, you'll implement the logic to fetch the product details based on the product ID. Replace the // TODO fetch product comment with the following:
tsx
The fetchProduct function retrieves product details from the Aiminaabee backend using the product ID. The region ID is passed as a query parameter to get prices specific to the selected region.
The selectedOptions state is initialized with the option values of the product's first variant.
Next, you'll implement the logic to select the appropriate product variant based on the currently selected options. Replace the // TODO select variant based on selected options comment with the following:
tsx
You define the following memoized values:
selectedVariant: The product variant that matches the currently selected options.shouldShowOptions: A boolean indicating whether to show the options UI. The options UI is hidden if there's a single option with a single value.images: An array of image URLs for the product, falling back to the thumbnail if no images are available.
Next, you'll implement the logic to handle adding the selected product variant to the cart. Replace the // TODO handle add to cart comment with the following:
tsx
The handleAddToCart function adds the selected variant to the cart using the addToCart function from the cart context. It displays appropriate toast messages based on the outcome.
Finally, you'll implement the UI rendering for the product detail screen. Replace the // TODO render UI comment with the following:
tsx
You handle three main states:
- Loading: Displays the
ProductSkeletonwhile fetching product details. - Error: Displays an error message if fetching fails or the product is not found.
- Success: Renders the product detail screen with the image slider, title, description, price, stock status, options, quantity selector, and add to cart button.
Add Product Detail Screen to Navigation
Finally, you'll add the product detail screen to the home stack navigator.
In app/(drawer)/(tabs)/(home)/_layout.tsx, replace the TODO add product details screen comment with the following:
tsx
A new screen is added to the stack navigator for the product detail screen, allowing users to navigate between the home screen and the product detail screen seamlessly.
Test Product Detail Screen
To test out the product detail screen, run your Aiminaabee application and Expo app.
Then, in the home screen, click on a product to view its details. This will open the product detail screen where you can view its images, select options, adjust quantity, and add it to the cart.

You can try adding a product to the cart and see the toast notification confirming the action. You'll implement the cart screen in the next step.
Next: 10. Cart screen