Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Shell navigating deferral token #12039

Merged
merged 9 commits into from
Sep 18, 2020
Merged

Conversation

PureWeen
Copy link
Contributor

@PureWeen PureWeen commented Sep 6, 2020

Description of Change

Provide a deferral token during navigating that users can use to invoke async operations

  • Implementation uses the existing "cancel" behavior to "cancel" user initiated navigation. Once they complete the deferral then it uses GotoAsync to replay the navigation
  • GotoAsync and all of the INavigation methods will not resolve until the user has completed all deferrals
  • If user tries to navigate while there is a pending deferral then GoToAsync will throw an exception
  • reworked all the INavigation methods to route through GoToAsync so that all behavior is symmetrical

Issues Resolved

API Changes

class ShellNavigatingDeferral
{
    public void Complete();
}
class ShellNavigatingEventArgs
{
     public ShellNavigatingDeferral GetDeferral()
}

Platforms Affected

  • Core/XAML (all platforms)
  • iOS
  • Android
  • UWP

Testing Procedure

  • Unit tests included

Example usage

Given the following override of OnNavigating if the user tries to do any navigation they will be given a display sheet confirming if the want to navigate. If they click "no" then navigation will be cancelled

If the user calls GoToAsync the GoToAsync call will only resolve after the deferral token has been completed

public class MyShell : Shell
{
		protected override async void OnNavigating(ShellNavigatingEventArgs args)
		{
			base.OnNavigating(args);

			var token = args.GetDeferral();

			var result  = await DisplayActionSheet(
					"Are you sure?",
					"cancel",
					"destruction",
					"Yes", "No");

			if (result != "Yes")
				args.Cancel();

			token.Complete();
		}

DEMO

F6633D2C-EBDD-4E75-950B-5B7E1998AA33

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

@PureWeen PureWeen added the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Sep 6, 2020
@PureWeen PureWeen removed the request for review from StephaneDelcroix September 6, 2020 23:00
@PureWeen PureWeen removed the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Sep 6, 2020
Copy link
Contributor

@felipebaltazar felipebaltazar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤎🤯🤎

Xamarin.Forms.Core.UnitTests/ShellTestBase.cs Show resolved Hide resolved
Xamarin.Forms.Core.UnitTests/ShellTests.cs Outdated Show resolved Hide resolved
Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>
PureWeen and others added 2 commits September 11, 2020 21:18
Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>
@samhouts samhouts merged commit be20299 into 5.0.0 Sep 18, 2020
vNext+1 (5.0.0) automation moved this from In Review to Done Sep 18, 2020
@samhouts samhouts deleted the shell_navigating_deferral_token branch September 18, 2020 21:34
@samhouts samhouts added this to the 5.0.0 milestone Sep 19, 2020
@samhouts samhouts added this to Done in Sprint 176 Sep 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[Bug] Shell.Current.GoToAsync("..", true) has no animation like Shell.Current.Navigation.PopAsync()
5 participants