UI Layer Architecture
Composable Screens
Screen Structure Pattern
All feature screens follow a consistent pattern:Key UI Patterns
Factory Injection
Use
@Inject on composable with ViewModel factory parameterState Collection
collectAsStateWithLifecycle() for lifecycle-aware collectionScaffold Pattern
Consistent use of Scaffold with top bar and FAB
State-Based UI
Render different UI based on ViewState properties
State Management
ViewState Pattern
Immutable data classes representing complete UI state:Creating StateFlow in ViewModel
Reusable UI Components
Kafka has a rich library of reusable components in theui:components module.
Item Components
Common UI Components
Material3 & MaterialYou
Kafka uses Material3 with dynamic colors (MaterialYou).Navigation
Type-safe navigation using Compose Navigation.Lists and LazyLayouts
Efficient list rendering with LazyColumn and LazyRow.Best Practices
Lifecycle Awareness
Use
collectAsStateWithLifecycle() instead of collectAsState()Immutable State
ViewState should be immutable data classes
Stateless Composables
Keep composables stateless, hoist state to ViewModel
Keys in Lists
Always provide keys for items() in lazy layouts
Reusable Components
Extract common UI patterns to ui:components
Loading States
Show placeholders instead of empty screens