Overview
Divvy uses Jetpack Compose Navigation with Kotlin serialization for type-safe navigation. This approach eliminates string-based routes and provides compile-time safety for navigation arguments.Navigation Destinations
All app destinations are defined as a sealed interface with serializable data classes:app/src/main/java/com/example/divvy/ui/navigation/AppDestination.kt
Type Safety: Using
@Serializable data classes ensures navigation arguments are type-safe and validated at compile time.Navigation Routes
Main Tabs
- Home - Activity feed and quick actions
- Groups - Manage expense groups
- Friends - Friend connections
- Profile - User account settings
Feature Flows
- GroupDetail - View group expenses and members
- ScanReceipt - Camera-based receipt scanning
- SplitExpense - Choose split method
- AssignItems - Item-level expense assignment
- SplitByPercentage - Percentage-based splits
Secondary Screens
- Ledger - All balances and settlements
- Analytics - Spending insights
Navigation Graph
TheAppNavHost defines the navigation graph with all composable destinations:
app/src/main/java/com/example/divvy/ui/navigation/AppNavHost.kt
Navigation with Arguments
Passing Arguments
Navigation arguments are passed as constructor parameters:- Multiple Arguments
- Optional Arguments
Retrieving Arguments
Arguments are retrieved usingtoRoute() extension function:
ViewModel Factory with Arguments
For ViewModels that need navigation arguments, use Hilt’s assisted injection:app/src/main/java/com/example/divvy/ui/navigation/AppNavHost.kt
The ViewModel factory pattern allows Hilt to inject dependencies while accepting navigation arguments.
Bottom Navigation
The bottom navigation bar provides quick access to main tabs:app/src/main/java/com/example/divvy/ui/navigation/BottomNavigationBar.kt
Navigation Options for Tabs
- Save State
- Launch Single Top
- Restore State
Deep Linking
Divvy supports deep linking for group invitations through Supabase Auth:Auth Redirect Configuration
app/src/main/java/com/example/divvy/di/NetworkModule.kt
Redirect URL Pattern
- Google OAuth sign-in redirects
- Group invitation deep links
- Password reset flows
AndroidManifest Configuration
Navigation Flow Examples
Creating an Expense
Group Management
Back Stack Management
Pop to Destination
Pop Current Screen
Clear Back Stack
Testing Navigation
Navigation Testing Example
Best Practices
1
Use Type-Safe Routes
Always use
AppDestination sealed interface instead of string routes2
Validate Arguments
Use non-nullable types for required arguments, nullable types for optional ones
3
Handle Back Navigation
Always provide
onBack callbacks in screen composables4
Save Tab State
Use
saveState and restoreState for bottom navigation tabs5
Avoid Deep Stacks
Pop back to main screens after completing flows (like expense creation)
Common Patterns
Conditional Navigation
Multi-Step Flows
Next Steps
MVVM Pattern
Learn how navigation integrates with ViewModels
Architecture Overview
Return to architecture overview