Scalable Jetpack Compose Navigation
Article Summary
Lachlan McKee from Bumble Tech tackles a critical scalability problem in Jetpack Compose Navigation that Google's docs don't address. His solution? Delegate route creation to feature modules using Dagger Hilt factories.
When building a single-activity Compose app, the standard NavHost approach forces one location to know how to instantiate every screen—creating a potential god-class nightmare. McKee developed a factory pattern that keeps navigation logic decentralized and feature modules truly independent.
Key Takeaways
- Standard NavHost requires defining all routes in one place, creating maintenance bottlenecks
- Factory pattern with Dagger Hilt lets each feature module own its navigation logic
- Published open-source library reduces boilerplate with HiltComposeNavigationFactory annotation
- Enables feature modules to use Kotlin internal keyword for better encapsulation
Critical Insight
A factory-based navigation pattern solves Compose's centralization problem by distributing route definitions across feature modules using Dagger Hilt's automatic discovery.