Skip to content

[NavSvc] make INavigationService.Navigate*() accepts dataContext as argument#944

Merged
pomianowski merged 2 commits intolepoco:developmentfrom
Palatis:feature/navsvc/datacontext
Mar 13, 2024
Merged

[NavSvc] make INavigationService.Navigate*() accepts dataContext as argument#944
pomianowski merged 2 commits intolepoco:developmentfrom
Palatis:feature/navsvc/datacontext

Conversation

@Palatis
Copy link
Copy Markdown
Contributor

@Palatis Palatis commented Feb 9, 2024

Pull request type

Please check the type of change your PR introduces:

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

What is the current behavior?

INavigationService lacks a way to specify dataContext for navigating.
Yes, we can get the underlying NavigationControl and navigate with dataContext object like this:

NavigationService.GetNavigationControl().Navigate(pageType, dataContext);
// or
NavigationService.GetNavigationControl().NavigateWithHierarchy(pageType, dataContext);

but... that's a bit tedious.

Issue Number: N/A

What is the new behavior?

add these 3 overload methods with dataContext to INavigationService

bool Navigate(Type pageType, object? dataContext);
bool Navigate(string pageIdOrTargetTag, object? dataContext);
bool NavigateWithHierarchy(Type pageType, object? dataContext);

so client code can just do NavigationService.Navigate(type, data) without the hassle.

Other information

However, if the current displaying page (ie. top-most navigation stack) is pageType, Navigate*(...) returns false and does nothing.
I managed to force-refresh the stack by doing this in client code:

while (!NavSvc.NavigateWithHierarchy(typeof(SomePage), someData))
{
    // failed, try pop the stack and try again
    if (!NavSvc.GoBack())
    {
        // cannot pop stack, really failed...
        Log.LogCritical(...);
        break;
    }
}

add these 3 overload methods with `dataContext` to `INavigationService` so that
```C#
bool Navigate(Type pageType, object dataContext);
bool Navigate(string pageIdOrTargetTag, object dataContext);
bool NavigateWithHierarchy(Type pageType, object dataContext);
```

However, if the current displaying page (ie. top-most navigation stack) is `pageType`, `Navigate*(...)` returns `false` and does nothing.
I managed to force-refresh the stack by doing this in client code:
```C#
while (!NavSvc.NavigateWithHierarchy(typeof(SomePage), someData)
{
    // failed, try pop the stack and try again
    if (!NavSvc.GoBack())
    {
        // cannot pop stack, really failed...
        Log.LogCritical(...);
        break;
    }
}
```
@Palatis Palatis requested a review from pomianowski as a code owner February 9, 2024 18:01
@Palatis Palatis changed the title [NavSvc] add dataContext to INavigationService.Navigate*() [NavSvc] make INavigationService.Navigate*() accepts dataContext as argument Feb 9, 2024
@pomianowski
Copy link
Copy Markdown
Member

Hey @Palatis, thanks for your contribution

@pomianowski pomianowski merged commit 8454e5b into lepoco:development Mar 13, 2024
@Palatis Palatis deleted the feature/navsvc/datacontext branch March 13, 2024 11:55
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants