-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor: Migrate from Fragments to pure Compose Navigation #399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit removes the Fragment-based navigation and replaces it with a pure Compose navigation solution using `navigation3`. Key changes: * Deleted `MovieDetailsFragment`, `MoviesFragment`, and their associated XML layouts. * Updated `MainActivity` to use `NavDisplay` from `navigation3` for screen management. * Introduced `MoviesNavScreen` and `MovieDetailsNavScreen` composables to handle navigation logic and state. * Replaced AndroidX Navigation dependencies with `navigation3`. * Removed `collectAsStateWithLifecycle` in favor of passing state directly to screen composables.
53eaea6 to
3bd429c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates the application from Fragment-based navigation with AndroidX Navigation to pure Compose navigation using the navigation3 library. The change simplifies the architecture by removing XML layouts and Fragment boilerplate in favor of declarative Compose code.
Key changes:
- Removed Fragment classes (
MoviesFragment,MovieDetailsFragment) and XML layouts - Introduced new navigation composables (
MoviesNavScreen,MovieDetailsNavScreen) that manage lifecycle and state - Updated screen composables to accept state directly instead of collecting from flows
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| PopularMoviesScreenTest.kt | Updated test calls to pass state directly instead of flow and initial value |
| MovieDetailsScreenTest.kt | Updated test calls to pass state directly and fixed URL protocol |
| nav_graph.xml | Deleted XML navigation graph |
| fragment_compose.xml | Deleted Fragment layout file |
| activity_main.xml | Deleted Activity layout with FragmentContainerView |
| MoviesScreen.kt | Refactored to accept state parameter instead of collecting from flow |
| MoviesNavScreen.kt | New composable managing navigation, lifecycle, andViewModel integration for movies list |
| MoviesFragment.kt | Deleted Fragment implementation |
| MovieDetailsScreen.kt | Refactored to accept state parameter instead of collecting from flow |
| MovieDetailsNavScreen.kt | New composable managing navigation, lifecycle, and ViewModel integration for movie details |
| MovieDetailsFragment.kt | Deleted Fragment implementation |
| Screen.kt | New sealed class defining navigation destinations |
| MainActivity.kt | Refactored to use Compose setContent with NavDisplay instead of Fragment container |
| build.gradle | Updated dependencies to replace AndroidX Navigation with navigation3 library |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The `ModuleOwner` interface, which was used to decouple fragments from the `Application` class, has been removed. The `App` class now directly exposes the `appModule`. The `appModule()` extension function has been updated to cast the `applicationContext` to `App` instead of `ModuleOwner`.
This commit extracts the main navigation logic from `MainActivity` into a new `MoviesApplication` composable. Key changes: - A new `MoviesApplication.kt` file is created to house the `NavDisplay` and its configuration. - `MainActivity` is simplified to just call `MoviesApplication`. - The `observeIn` extension function is removed in favor of `flowWithLifecycle`. - Modules (`TheMovieDbModule`, `MovieDetailsModule`) now own the `actions` `Channel`, removing redundant `remember` calls in the UI. - Dependencies like `AppModule` and `BackStack` are now passed explicitly to screen composables (`MoviesNavScreen`, `MovieDetailsNavScreen`). - Introduced a `BackStack` typealias for `SnapshotStateList<Screen>`.
The `Screen` sealed class now implements the `NavKey` interface from the navigation library and is marked as `@Serializable`. This change removes the manual `remember { mutableStateListOf<Screen>(PopularMovies) }` in favor of a new `rememberNavBackStack` composable function, which utilizes `rememberSerializable` with a `NavBackStackSerializer` for better state restoration.
d5c23cd to
700e666
Compare
72112b6 to
c76ceb8
Compare
This reverts commit c76ceb8.
This commit removes the Fragment-based navigation and replaces it with a pure Compose navigation solution using
navigation3.Key changes:
MovieDetailsFragment,MoviesFragment, and their associated XML layouts.MainActivityto useNavDisplayfromnavigation3for screen management.MoviesNavScreenandMovieDetailsNavScreencomposables to handle navigation logic and state.navigation3.collectAsStateWithLifecyclein favor of passing state directly to screen composables.