Refactor navigation state so core is impl agnostic#3208
Refactor navigation state so core is impl agnostic#3208bidetofevil wants to merge 2 commits intohho/nav-state-navcontrollerfrom
Conversation
| /** | ||
| * Instrumentation provider that creates and registers [NavControllerTracker] with the [NavigationTrackingService]. | ||
| */ | ||
| class ComposeNavigationInstrumentationProvider : InstrumentationProvider { |
There was a problem hiding this comment.
Not sure if this is a good way to to use the data source interface because it doesn't actually provide a datasource, but it allows for the dynamic loading of the compose navigation tracking via a new module. Is there a better way to do this?
| /** | ||
| * Updates the navigation state by listening to events | ||
| */ | ||
| class NavigationStateDataSource( |
There was a problem hiding this comment.
I think there is potentially additional refactoring that can be done to clean this datasource up so it doesn't also fire the controller attachment events. But it's convenient right and I can do this later.
f2b6b56 to
0de806f
Compare
0de806f to
47ec7cd
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## hho/nav-state-navcontroller #3208 +/- ##
==============================================================
Coverage ? 78.15%
==============================================================
Files ? 583
Lines ? 12186
Branches ? 1831
==============================================================
Hits ? 9524
Misses ? 1936
Partials ? 726
🚀 New features to boost your workflow:
|
fractalwrench
left a comment
There was a problem hiding this comment.
LGTM although it'd be good to make the controller parameter a more specific type if possible
...in/kotlin/io/embrace/android/embracesdk/internal/navigation/NavigationTrackingServiceImpl.kt
Outdated
Show resolved
Hide resolved
| * The implementation is responsible for casting the controller to whatever interface it needs in order to do its tracking, | ||
| * as the interface is generic and agnostic to any navigation controller implementation details. | ||
| */ | ||
| fun trackNavigation(activity: Activity, controller: Any? = null) |
There was a problem hiding this comment.
What type do we expect the controller to be? Is there any way to make it more specific than Any??
There was a problem hiding this comment.
For now, it's NavController. And I'd be happy to have that explicitly until there's another type, but then that means we'll have to expose this Compose Navigation dependency at the public API level.
I started out with way, but then went to this generic method. It'll be more obvious in my next PR.

Goal
Made the interfaces for navigation tracking implementation agnostic. That way, the
NavigationStateDataSourcecode can live in its own module and code that updates states that have specific dependencies like Compose Navigation can live it its own module. All the wiring will be done via a new interfaceNavigationTrackingServicewhich will have an implemenation exposed inInstrumentationArgsso the listeners and event producers can be wired up when they load (via datasources).This offers better encapsulation and allows us to create modules with different dependencies and not have to push those onto SDK users.
Testing
Refactored existing test to ensure the rewiring still works.