HomeScreen
The main entry point of the app, providing product search functionality with real-time updates.Overview
HomeScreen displays a search interface with dynamic results rendering based on UI state. It uses:
- Hilt for dependency injection (
hiltViewModel()) - Material3 Scaffold for consistent layout
- State Management via
UiStatesealed class - Composable Components for modular UI
The HomeScreen manages search query state locally while delegating business logic to
HomeViewModel.Implementation
Key Features
Search Integration
Dynamic search with Material3 SearchBar component
State Management
Handles Loading, Success, Error, and Empty states
Error Handling
Custom ErrorState component with retry functionality
Navigation
Navigates to product details via callback
UI States
The screen responds to four distinct states:| State | Display | User Action |
|---|---|---|
Loading | Centered circular progress indicator | Wait for results |
Success | Scrollable list of products | Click to view details |
Error | Error message with retry button | Retry the search |
Empty | Informative text based on query | Start/refine search |
Components Used
SearchBarComponent
SearchBarComponent
Provides an expandable Material3 SearchBar with placeholder text “Buscar en Mercado Libre” and search icon.Location:
ui/screen/home/components/SearchBar.kt:14ProductList
ProductList
LazyColumn displaying search results with ProductListItem composables.Location:
ui/screen/home/components/ProductList.kt:11ErrorState
ErrorState
Reusable error display component handling AppError types with retry functionality.Location:
ui/components/ErrorState.ktProductDetailScreen
Displays detailed information about a selected product, including images, description, and attributes.Overview
The detail screen fetches product information on launch using the product ID and displays:- Product Images using Coil’s AsyncImage
- Title and Description with Material3 typography
- Attributes in an organized list format
- Top App Bar with back navigation
Implementation
ProductDetailContent
The content composable renders the product information in a scrollable column:Key Features
LaunchedEffect
Automatically fetches product details when screen loads
Image Loading
Uses Coil for async image loading with ContentScale.Fit
Conditional Rendering
Shows description and attributes only when available
Material3 Components
TopAppBar, ListItem, and typography system
Layout Structure
The detail screen follows a vertical layout pattern:- Top App Bar - Title with back navigation
- Product Image - 300dp height, full width, fitted content
- Product Title - Bold, 20sp text
- Description Section - Conditional, 16sp with 22sp line height
- Attributes List - Material3 ListItem components
All spacing uses 16dp increments following Material Design spacing guidelines.
Navigation
The screen receives:id: String- Product identifier from navigation argumentsonBack: () -> Unit- Callback to return to previous screen
Best Practices
State Management
State Management
- Collect state as Compose State using
collectAsState() - Use
rememberfor local UI state (query, active state) - Delegate business logic to ViewModels
Navigation
Navigation
Error Handling
Error Handling
- Display user-friendly error messages
- Provide retry functionality for failed operations
- Use Material3 error colors for visibility
Performance
Performance
- Use LazyColumn for lists to enable virtualization
- Load images asynchronously with Coil
- Minimize recompositions with stable state
Related Documentation
Navigation
Learn about routing and navigation
Theming
Explore color schemes and typography
Architecture
Understand Clean Architecture implementation