Skip to content

Obsolete Dictionary and shift to single state object#15281

Closed
PureWeen wants to merge 1 commit into
mainfrom
dont_retain_extra_params_via_args
Closed

Obsolete Dictionary and shift to single state object#15281
PureWeen wants to merge 1 commit into
mainfrom
dont_retain_extra_params_via_args

Conversation

@PureWeen
Copy link
Copy Markdown
Member

@PureWeen PureWeen commented May 25, 2023

Description of Change

  • Obsolete the shell.gotoasync API that takes Dictionary<string, object>
  • Add a new overload that's specific to just passing navigationState. This structure matches WPF a bit with how the NavigationService works
  • No breaking changes
  • Splits out the concept of "queryParameters" vs "navigationState" a bit more explicitly.

Justification

Alternate PR Idea for: #14965

Currently when you pass extra parameters to shell via the parameters dictionary those are retained forever and reapplied with each navigation. The workarounds to remove those parameters is fairly cumbersome. Through discussions with users, it's become apparent that we need a mechanism to have parameters that only get applied during the initial navigation request. This PR clears any parameters that aren't part of the QueryString.

It's particularly problematic to retain those parameters because if the user passes a complex object that object is retained in memory forever unknown to the user.

Thoughts

  • It is a little odd to apply the navigationState through the existing IQueryAttributable but the idea would be to eventually promote this to NavigatingEventArgs like UWP/WPF has and you can grab it from the ExtraData. Then we can eventually elevate that to work with NavigationPage as well
  • We could add an interface with this PR IReceivesNavigationState that you could mark on your classes and then that's where it'd pass the navigationState to

FAQ

  • Why is the Query Property an internal BP?
    • This was done for Hot Reload purposes. In theory there would be scenarios where hot reload could trigger a page to be recreated and thus all BP's would need to get copied from one Page to another.
  • What about a perfect solution?
  • Ideally we restructure shell when there's more time to flesh out more interfaces/apis for parameters passing. For now, we need a way for users to opt out of parameters being reapplied
  • What changed between MAUI and XF?
    • The only thing that changed was the addition of the dictionary overload on GotoAsync. Parameters have always reapplied. So, for users coming from XF there is no change in behavior. This would mainly be a change for users that started using the new API.
  • What if users are using the setting of the parameter for OnAppearing?
    • IApplyQueryAttributes will still get called so users can use that interface.

Examples for the docs to improve clarity

We should enhance the navigation part of the Shell docs to include various example permutations of how parameters are handled.

Still works the same

await GotoAsync("firstPage?param=1");
await GotoAsync("nextPage");
await GotoAsync(".."); // param = 1 will get applied to `firstPage`

New

ComplexObject obj;
await GotoAsync("firstPage?param=1", obj);
await GotoAsync("nextPage");
await GotoAsync(".."); // param = 1 will get applied to `firstPage` but `ComplexObject` won't
ComplexObject obj;
await GotoAsync("firstPage?param=1", new KeyValuePair<string, object>("MyParameter", obj));
await GotoAsync("nextPage");
await GotoAsync(".."); // param = 1 will get applied to `firstPage` but `ComplexObject` won't

Issues Fixed

Fixes #10294

@PureWeen PureWeen requested review from hartez and mattleibow May 25, 2023 20:09
@PureWeen PureWeen closed this Jun 12, 2023
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 10, 2023
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.

Navigation data is retained and also presented to IQueryAttributable on Back navigation.

1 participant