The implementation is very straightforward since each method is only calling Xamarin.Forms static methods provided by the Shell API.
Create the Navigator class, as shown in the following steps:
- In the News project, add a new class called Navigator.
- Add the following code to the class:
using System.Threading.Tasks;
using News.ViewModels;
using Xamarin.Forms;
namespace News
{
public class Navigator : INavigate
{
public async Task NavigateTo(string route)
{
await Shell.Current.GoToAsync(route);
}
public async Task PushModal(Page page)
{
await Shell.Current.Navigation.PushModalAsync(page);
}
public async Task PopModal()
{
await Shell.Current.Navigation.PopModalAsync();
}
}
}
This is simply pass-through code that calls already existing methods.